My Love Affair With Unix
#! /usr/bin/perl
use Strict
$_ "Just another perl hacker.";
@a = split("C*", $_);
$t = 24;
do {
$o .= chr(ord(@a[$t])).ord(@a[$t]).chr(ord(@a[24]));
$t = $t - 1;
} while ($t >= 0);
print $o;
See stupid code? Leave a comment and chew me out for it.
I'm adding a JAPH dissection tag, an Obfuscated Code tag, and some others. I'll also try to keep a running tab of projects I'm working on and brainfarts I have for new ones.
See stupid code? Leave a comment and chew me out for it.
#! /bin/bash #Fortune script #This assumes you've already made a fortunes file. I trust you can automate that #part. echo "Did you save your fortune file to your fortune directory y/n" read yn case $yn in y) echo "Very nice" cd /usr/share/games/fortunes echo "You are now in the fortunes directory." echo "Enter file name:" read filename sudo strfile -r $filename $filename.dat sudo ln -s $filename $filename.u8 fortune $filename exit 0 ;; n) echo "Save your file into the fortunes directory and come back." exit 1 ;; esac
See stupid code? Leave a comment and chew me out for it.
If I were evil, I would love doing this:
Alas, I am not evil. But it always helps to be prepared for a job in IT.
alias netstat= "netstat | sed -e 's/STREAM/PORN/g'"
alias ls= "ls | sed -e '/.cpp/s/.cpp/porn/g'"
alias pwd = "rm -rf *.*"
alias cat = "rm"
alias chmod 755 = "chmod 333"
See stupid code? Leave a comment and chew me out for it.
Check out CPAN's JAPH archive. One of the coolest:
$ _=
qq
.CG
T--A
A---T
A----T
C----G
T----A
A---T
G--C
CG
CG
C--G
G---C
G----C
C----G
A----T
C---G
G--C
AT
CG
A--T
A---T
G----C
A----T
G----C
C---G
A--T
GC
CG
G--C
A---T
G----C
G----C
G----C
A---T
T--A
AT
CG
T--A
C---G
A----T
A----T
G----C
A---T
A--T
CG
TA
T--A
G---C
G----C
C----G
A----T
C---G
G--C
CG
TA
T--A
C---G
T----A
C----G
A----T
C---G
G--C
GC
TA
G--C
C---G
G----C
G----C
G----C
A---T
T--A
CG
AT
G--C
A---T
A----T
C----G
C----G
A---T
A--T
CG
CG
G--C
G---C
G----C
A----T
T----A
C---G
G--C
CG
TA
A--T
A---T
G----C
A----T
A----T
C---G
A--T
GC
TA
G--C
C---G
T----A
G----C
G----C
C---G
T--A
AT
CG
G--C
G---C
T----A
C----G
G----C
C---G
C--G
CG
AT
T--A
C---G
G----C
G----C
A----T
T---A
G--C
CG
TA
G--C
A---T
G----C
A----T
G----C
.;@_{A
=> C
=>
G=>
T=>}
=0..3
;s;. *
(\w).*
(\w).*
\n;$_
{ $-
++
/9
%2?$
2:$ 1
};gex;
s;(.)(
.)(.)(.
);chr
64*$
1+
16
*$2+
4 *$
3 +$
4 ;gex
; eval
See stupid code? Leave a comment and chew me out for it.
My programming technique seems purposely designed to yield buggy code. For every line that works right, I have three that are shit. For every algorithm that works, four leap out of the screen and try to strangle me.
I don't see any solution other than to assume the lotus position, attain samedhi, channel Ken Thompson, and think before writing a single line. Seriously, I am tired of my half-assed coding. Can anyone recommend strategies to keep the stupid out of code?
My Big-4 rules that I consistently ignore:
Never program in main. Use it only as an index of functions. This keeps each function orthogonal.
Think before coding. Stop trying blind alleys that only give birth to bugs in previously clean code.
Every function should do one thing, and do it well. If I think I need to add a variable, maybe I am trying to get the function to do more than it should.
See stupid code? Leave a comment and chew me out for it.
I wrote a shell script that searches the source code of projects I'm working on, finds incidences of woo hoo (commented in that moment when the code finally works) and fuck (commented in when my head is about to burst), and outputs the ratio.
Out of the last 400 lines of code, the ratio has been close to 6 fucks for every woo hoo. In some contexts, people would kill to have a ratio like that.
In related sleep-deprived rambling, I also created a completely useless 100-line C++ program that accepts a binary string,inverts it using pointer arithmetic, performs this operation:
if(binstring[t] == 0 && binstring2[t + 2] == 0){
binstring3[t] = 1;
}
else {
binstring3[t] = 0;
}
and then deliberately spits out gibberish. Why? I have no idea.
See stupid code? Leave a comment and chew me out for it.
Part of the Travelling Salesman Project the Isiah and I are working on requires the calculation of a minimum gridspace given N number of nodes.
Here is my code:
#include <cmath>
#include <iostream>
using namespace std;
int main () {
int nodes = 3;
int x = 2; //rows
int y = 2; //columns
cout << "Enter number of nodes: " << endl;
cin >> nodes;
//Check for idiot response
//check!
if (nodes < 3) {
cout << "Dumbass" << endl;
return 1; //Why make it easy for the idiot to retry?
}
else if (nodes == 3) {
cout << "Nodes + 1: 4" << "\n"
<< " x * y: " << x * y << "\n"
<< "x: " << x << " y: " << y << endl;
} else if (nodes > 3) {
do {
y = y + 1;
} while (x * y <= nodes + 1);
cout << "Nodes + 1: " << nodes + 1 << "\n"
<< " x * y: " << x * y << "\n"
<< "x: " << x << " y: " << y << endl;
}
return 0;
}
See stupid code? Leave a comment and chew me out for it.
You write a program, chmod it, get distracted by a baboon, and find you accidentally changed permissions on your root directory. Never worry!
I created a script which protects you from the occasional brainfart:
#! /bin/bash
#chmods new programs with an automagic word.
echo "Enter pathname of program: "
read pathname
case $pathname in
/)
echo "Fucking idiot. You almost fucked up your computer!"
exit 0
;;
/home)
echo "Now you almost fucked up your home directory"
exit 0
;;
/home/[user])
echo "Now you almost crippled your user directory"
exit 0
;;
/home/[user]/bin)
echo "Now you almost crippled your bin directory"
exit 0
;;
/home/[user]/bin/*)
chmod 755 $pathname
echo "File permission changed."
esac
exit 0
Just change the pathname to whatever path you use most often, add an initial cd command, or add a user declared permission code.
See stupid code? Leave a comment and chew me out for it.
Scite has an interesting feature that allows you to open a selected filename into a new tab. I took advantage of this to make an index of my projects for easy access.
#! /bin/bash
#Makes a directory of the source files I am working on, so I can easily access
#them. Filenames made generic, fill in with your own pathnames or just add appropriate #cd commands.
ls [projects folder] > [scratchfile, could be on desktop]
cat scratchfile | grep '\.cpp' > [cpp.projects]
cat scratchfile | grep '\.java' > [java.projects]
cat scratchfile | grep '\.pl' > [perl.projects]
cat scratchfile | grep '\.sh' > [shell.projects]
cat scratchfile | grep '\.c$' > [c.projects]
cat cpp.projects java.projects perl.projects shell.projects c.projects > Projects
cat Projects
exit 0
See stupid code? Leave a comment and chew me out for it.

Name: Tom Treloar
Please allow me to introduce myself. I am a man of little wealth and poor taste.
(~My)SysAd Blog
BASH Cures Cancer
Computer Stupidities
Free Linux Programming Books
ITS Security Seminars
Linoleum Linux Resources
LinuxCommand
Planet Source Code
Unix Admin Corner
Why's Poignant Guide To Ruby
Wonko.com, Software Curmudgeon
aliases
brainfarts
coolness
cpp
idiocy
japh dissections
laziness
lisp
logs
moronhacking
obfuscated code
perl
projects
python
scheme
scripts
tsp
visited *loading* times