I wrote a Quine

So I wrote my first Quine last night. A Quine is a program that, when run, outputs an exact copy of its source. It’s not immediately obvious in regard of how to accomplish that. At first it sounds pretty easy but then you get lost in recursion and your brain explodes.

So I wrote a Quine in Python. It’s not exactly short or impressive, but it works. I am pretty happy with myself, because I found out how to do it by myself, which was a very enlightening moment, makes you realize a bunch of things about compilers.

So here it is: (pretty vim-desert syntax colored version here: http://alex.underwares.org/quine.py.html)

#!/usr/bin/env python
# Holy fucking shit I wrote a quine!
# You wouldn't believe how baked I am.
 
code ="#!/usr/bin/env python\n# Holy fucking shit I wrote a quine!\n# You wouldn't believe how baked I am.\n\ncode =\"__code__\"\n\ndef regurgitate(text):\n    \"\"\"Hi, I regurgitate stuff, but escaped.\"\"\"\n text = text.replace(\"\\\\\",\"\\\\\\\\\")\n    text = text.replace('\"', \"\\\\\\\"\")\n   text = text.replace('\\n',\"\\\\n\")\n  return text\n\ndef main():\n    \"\"\"I seem to be the entry point, sir.\"\"\"\n    print code.replace(\"__code__\", regurgitate(code), 1)\n\nif __name__ == \"__main__\":\n    main()\n\n"
 
def regurgitate(text):
    """Hi, I regurgitate stuff, but escaped."""
    text = text.replace("\\","\\\\")
    text = text.replace('"', "\\\"")
    text = text.replace('\n',"\\n")
    return text
 
def main():
    """I seem to be the entry point, sir."""
    print code.replace("__code__", regurgitate(code), 1)
 
if __name__ == "__main__":
    main()

You might also enjoy:

Posted in Computers, English, Programming | Tagged , | Leave a comment

Xapian Binaries

Just a quick post to mention that Charlie Hull from Lemur Consulting sent me an e-mail to mention that they are now providing actual binaries along with the makefiles.

http://www.flax.co.uk/xapian_windows.shtml

This renders my binaries redundant, so I will update the relevant pages with this link. I hadn’t built recent python bindings in a while because my the Windows Server 2003 VM I used for windows builds was lost in a hard drive crash, and I never got around to rebuilding it. Well, this is great news!

You might also enjoy:

Posted in English | Tagged , , , | Leave a comment

Gah! Why? Part Deux

Yesterday, I close the lid on my first generation MacBook Pro, unplug it, pack it in my bag and head home from another long day at work. I make a pit stop at the Salon des Métiers D’Arts at Place Bonaventure to pick up some christmas gifts. I feel the urge to check on my finances, so I take the laptop out of the bag, pop it open and behold, nothing. Battery’s dead. I figure, I must have unplugged it somehow while working, or it must have failed to suspend properly, and wasted the entire battery on a kernel panic. This happens sometimes when the Cisco VPN Client kext is loaded and active.

But alas, no. I plug it in this morning, and bang:

"Battery not charging"

Again, for those not speaking french, it means “battery not charging”.

This is the third battery that dies with this laptop. If the laptop broke down, I’d understand. It has a bit over three years of age, which is pretty much the average life span of a laptop-you-carry-around-every-day. But the battery is still young. Bleh.

ADDENDUM (24 mar 2009): I just noticed I sound like an elitist douche hipster in that post. I mean, Art Salon + Apple hardware + French… Should have included more codetalk or wires as not to lose my geek street cred, yo.

You might also enjoy:

Posted in English | Tagged , | Leave a comment

Nintendo DS Dev Kit

I went to Arcadia a few weeks ago and this small developement company had a DS dev kit running their game demo, so I snapped a picture of it, telling myself I would post it on my blog when I got home, and then promptly forgot about it. I found the picture on my phone just now and decided to try the wordpress iPhone client. So here goes a lot of fuss over nothing.

You might also enjoy:

Posted in English, Randomness | Tagged , | 1 Comment

We all have to start somewhere

Well, you know, in electronics like everything else, we all have to start somewhere. So my “hello world” of sorts, is making a LED blink using an Arduino Diecimila board.

You might also enjoy:

Posted in English | Tagged , , | 1 Comment

Megaman 9

I just want to point out something terribly uncomfortable about Megaman 9.

THEY ARE ALL WEARING THE SAME GOD DAMN HELMET!

Thank you.

You might also enjoy:

Posted in English | Tagged , | Leave a comment

Mark Hoekstra passed away

So, Mark Hoekstra of Geek Technique has died of a heart attack earlier this week, while riding his bike.

Shit.

Mark was a really huge inspiration to me, I absolutely loved the guy and his work. I really related to his love of SGI gear and various obsolete chunks of hardware. I read geek technique with almost religous, cheerful glee every update.

I can’t believe he’s gone, I truely am sad now. This really is sad day.

You might also enjoy:

Posted in English | Tagged | 1 Comment