0) Open notepad
1) Write <html>My name is Ely <img src=''></html>
2) CTRL + S as index.htm
3) FTP to server
4) Then went to site.com/
That's when I knew I was going to be an amateur programmer for life. Yeah, yeah I know, it's HTML. But that gave me the courage to later jump into server-side languages.
That's indeed an interesting example because, by any standard, this is terrible code.
Yet for a sysadmin position it still provides valuable insight into your a) pain threshold, b) familiarity with the tools, c) willingness and ability to bend reality for the boss.
I'd just add a big disclaimer that this kind of code only happens in emergencies.
(disclaimer: I'm guilty of these gnuplot hacks myself and they always stick around way longer than they should...)
> They always stick around way longer than they should...
But isn't that true for all 'terrible' code? Most of the elegant and well-formed code I write ends up getting butchered for the sake of 'features,' while the quick hacks that 'just work' stick around forever.
But seriously, nice work. Being able to put something useful together that easily (in terms of lines of code) is what most attracted me to UNIX/Linux coming from Windows. The amount of CLI tools one can take advantage of is simply astonishing.
This person claims that simple variable usage and stdout should be all that is needed to impress. While I studied enough low-level software development to still be impressed by an adder circuit, I just don't think this will impress enoug of the people we NEED to convert. Just about everyone takes it for granted that when they log onto FB, they will see their name...and that doesnt seem like "programming" to them
I used to do that kind of hacking in the 80's. I recognized the CALL-151. I have an old Apple II+ in the other room I'm tempted to try firing up just to solve this mystery.
NEW
1HOME:A=9200:B=13168:C=100:FORI=768TO796:READN:POKEI,N:NEXT:HGR:POKE-16302,0:HCOLOR=4:HPLOT0,0:CALL62454:HCOLOR=2:HPLOT0,63TO279,63:HPLOT0,62TO279,62:HCOLOR=6:HPLOT0,61TO279,61:HPLOT0,60TO279,60:HCOLOR=1:HPLOT0,59TO279,59:HPLOT0,58TO279,58
2HCOLOR=5:HPLOT0,55TO279,55:HPLOT0,54TO279,54:HCOLOR=0:HPLOT0,123TOC,123:HPLOT0,122TOC,122:HPLOT0,119TOC,119:HPLOT0,118TOC,118:COLOR=0:FORI=0TO39:VLIN0,39ATI:NEXT:COLOR=13:HLIN0,39AT14:FORI=0TO7:POKEA+I,0:POKEB+I,0:NEXT:COLOR=1
3HLIN0,39AT13:VTAB21:PRINTTAB(16)"RAINBOW":PRINT:PRINT"MIXED GRAPHICS (HI-RES/COLOR)":CALL768:DATA173,87,192,173,83,192,173,84,192,173,80,192,208,251,173,86,192,160,22,136,208,253,234,173,87,192,76,9,3
RUN
It was a grid of cells. Each cell could contain a constant or a formula, strings or numbers. You selected the cell to change with a mouse, and it recomputed once per click on a button. In essence it was fully functional, just lacking file load and save.
It didn't have charts or graphics, but the cell functionality was pretty complete. Using "EVAL" meant you had access to any function in the underlying language.
;; run this on SBCL
(sb-ext:unlock-package :common-lisp)
(let (syms) (do-symbols (s :common-lisp) (if (fboundp s) (push s syms)))
(labels ((worm (sym)
(let ((next (elt syms (random (length syms))))
(old (symbol-function sym)))
(format t "~%Worm attacks ~a, next target is ~a!~%" sym next)
(setf (symbol-function sym)
(lambda (&rest args)
(when next (worm next) (setf next nil)) (apply old args))))))
(worm '+)))
;; now try adding some numbers (and so on)
Long ago I also wrote a quine-based payload version of the above, moving towards doing the same for NewtonScript. But I've long since lost it.
Maybe not cool, but practical, I'd like to nominate some OCaml bitstring matching code:
let bits = Bitstring.bitstring_of_file "data" in
bitmatch bits with
| { width : 5;
data : width } ->
printf "width %d data %Ld\n" width data
It reads the first five bits of the file, interprets these bits as a number, then reads the next 0-31 bits from the file (note: not aligned, the first 3 bits come from the first byte in the file).
The nice thing is that if everything can be shown at compile time to be aligned to byte/word boundaries, then it all turns into relatively efficient calls to C.
There are some more realistic examples on the web page:
Coming late to the party, but Simon Tatham's .sig is pretty cool:
for k in [pow(x,37,0x13AC59F3ECAC3127065A9) for x in [0x195A0BCE1C2F0310B43C,
0x73A0CE584254AB23D5A0, 0x12878657EA814421CC92, 0x7373445BB3DA69996F4A,
0x77A7ED5BC3AA700E80B2, 0xE9C71C94ED87ADCF7367, 0xFE920395F414C1A5DB50]]:
print "".join([chr(32+3*((k>>x)&1))for x in range(79)]) # <anakin at pobox.com>
It won't be completely obvious to most people why this is cool, but it's effectively RSA-signed.
Mandelbrot fractal set viewer in brainfuck would fit the bill nicely. It's not 10 lines exactly, but reflowing the BF code with no loss of clarity is not a big deal :)
function Y(f)
local function g(...) return f(g,...) end
return g
end
print(Y(function(rec,x)
if x < 2 then
return 1
else
return x * rec(x-1)
end
end)(5))
I'd have said that for impressing people with small pieces of code something like SecondLife scripting would be ideal. You can manipulate objects in a 3d environment using simple code. Who doesn't enjoy programming a gun?
Also COM scripting on Windows (and presumably Applescript on the Mac).
Sure there's a lot of special keyword magic involved, but nothing will get people more excited about programming than seeing how they can easily automate their routine tasks to make their life easier - that's what programming is supposed to be about anyway.
You could probably stuff Node into this category too, if your target is the type to be impressed with writing their own basic web server in 10 lines of code.
0) Open notepad 1) Write <html>My name is Ely <img src=''></html> 2) CTRL + S as index.htm 3) FTP to server 4) Then went to site.com/
That's when I knew I was going to be an amateur programmer for life. Yeah, yeah I know, it's HTML. But that gave me the courage to later jump into server-side languages.