Thursday, September 15, 2011

Introducing Whitespace2.0.vim!

This is a raving that I wrote some months ago now while I was working a different job in a different country. I should point out that I liked the guys I was working with and they, generally speaking, were not retards...




The guys I'm working with are fucking geniuses and I fucking love them! I've been doing some maintenance on their PHP apps at work, and their coding standards are so advanced that Vim can't even support them out of the box! Luckily, I'm pro at vimscript and was able to write a plugin to help me!

<blink>Whitespace2.0! Now available on github! Get it here!</blink>

The making of Whitespace2.0 - A documentary

Right. First things first: we will need a random number generator. For this, we will nick some code from here.


Secondly, we will need to modify the behaviour of the tab key with this code:


Additionally, we need trailing whitespace to occasionally appear.

Sweet, that should do it.

PHP devs are blithering retards because Jesus made them that way

The other day a programmer at my work hacked on some PHP that I had written and, when I pulled the changes, I saw my code was now riddled with mixed indenting. I felt like he had just been in my bedroom and knocked all my transformers off the shelf and then just left them there. On the floor! That FUCK! I was going through Rapid Cyclic Weapon Escalation Syndrome1 and was in danger of rage-crapping my pants when I was reminded of that old bible story from primary school.

You know the one I'm talking about.

What are you? Stupid!? OK, here's an except:

... Jesus is on the assembly line putting together the final prototypes of all the programmers. He's bored as fuck and this shit has been dragging out all day - who knew there were so many fucking languages! All he wants is to be at home sucking on a beer and watching the tube, but instead he is stuck on the line putting the nerds together for daddy.

Poor Jesus...

So when the next head comes down the line, he pops the lid off and, instead of ramming in the corresponding brain, he hoists up his skirts and takes a giant shit right in there and snaps the lid back on ...

And thus explains why most PHP programmers are either:

A. too stupid to indent properly
B. completely ignorant about tabs, spaces and good indenting
C. don't know how to use their editors


(1). A mental disorder in which the subject fantasizes about killing someone with progressively larger and larger weapons until they have exhausted all possibilities, whereupon they begin combining weapons together into super-weapons. The ultimate culmination of which is a giant mega weapon made up of all known weapons in the universe.

Tuesday, October 12, 2010

Colorizing and autopaging svn diffs and other commands

I can't remember the last time I jacked off to black and white pornography.

Can you?

OF COURSE YOU CANT! Color is fucking awesome! No one yanks their crank to black and white shit anymore.

Once you've tasted color, you can never go back.

This brings us to the subject of version control. Over the last few years I've been spoiled by git, but have recently switched jobs and been using svn again. Using git has taught me to actually care what I'm committing — as opposed to just creating one giant commit at the end of the day — which has meant I've been looking at lots of diffs.

Git gives you lovely colorized, paged diffs that frequently stiffen the schlong. While svn, on the other hand, still gives you the same uncolored, unpaged horse shit as it did several years ago! I can't fucking believe the meat puppets at svn haven't gotten their asses into gear and stolen some basic UI ideas from the competition. WTF guys?!

Here's how you enable color for everything in git:

git config --global color.ui always

There are more granular options if you want them, but fuck that, color is awesome!

Svn has no such option. So I, like many others, have been forced to hack the mainframe to get color. Check my hacks:


This script defines a function called "svn" that hijacks calls to the svn program and essentially rewrites some of the commands. For example, this command:

svn diff -r1:7 foo

would get rewritten to:

svn diff -r1:7 foo | colordiff | sed -e 's/\r//g' | less -RF

Another example:

svn log foo

would get rewritten to:

svn log foo | less -F

Notice that I'm still interacting with svn via the same command set, and am not training myself away from the existing commands. Hopefully this will prevent me from losing the plot and ripping off cocks when forced to use svn on a machine that doesn't have my hacks.

Tuesday, July 13, 2010

Vim pr0n: Sample NERD tree plugins

I'm a lazy wank, and additionally: a bastard.

Which brings us nicely to our next point: The NERD tree API. In version 4.0 I added an API to allow people to add functionality to the NERD tree in the form of plugins.

I did this because I was getting tired of politely telling people where to ram requests for features that I either A. Would never personally use and therefore would probably do a poor job of maintaining, or B. Thought were good ideas, but was not interested in taking the plugin in that direction.

As a result, I've ended up writing a lot of small NERD tree plugins for people who have requested such features. In this raving I'll post and explain a couple of the simpler examples.

API Technical Details

You can get technical information about the API from :help NERDTreeAPI. Here you will find the documentation on the interface functions and some short usage examples. I spent ages writing that shit, so go check it out!


I see you've ignored my advice. You suck! However, in a rare show of generosity, I'll summarize it for you.

At the time of this writing the following public functions are defined in the NERD tree core:

NERDTreeAddKeyMap({options})
NERDTreeAddMenuItem({options})
NERDTreeAddSubmenu({options})
NERDTreeAddMenuSeparator([{options}])
NERDTreeRender()

The first 4 deal with extending the NERD tree key set and menu system, while the last redraws the tree buffer (useful if you have changed the tree somehow and want to reflect that in the UI).

Additionally, the following public classes are available:

NERDTreePath
NERDTreeDirNode
NERDTreeFileNode
NERDTreeBookmark

These are what the NERD tree core uses to get most of its biznass done. I wont say any more about them other than check out the source code, and check out this blog post to see the coding conventions used and for a rundown of prototype OO in Vim.

Example 1: A key mapping to open a :shell

In this example we add a key mapping on 'S' to the NERD tree that launches the :shell command in the directory of the currently selected node.


Even though I commented the living shit out of the code, it's probably worth mentioning the three points in this code where we call the NERD tree API:
  • Lines 8–11. Here we set up the NERD tree key binding so that when the user hits 'S', the NERDTreeStartShell() function is invoked. The quickhelptext value is what appears in the quick help (i.e. when you hit '?') under the "Custom mappings" section.
  • Line 18. Here we call GetSelected() (a class method of NERDTreeDirNode). This gives us a NERDTreeDirNode instance representing the directory node the cursor is sitting on.
  • Line 26. Here we call n.path.str(...) which gives us a string representation of the NERDTreePath object for the node in question, suitable for use with a :cd command. There are a number of formats and options the str() method can take. Check out the method comments in NERD_tree.vim for details.

Example 2: A menu item to open images

In this example we add a menu item to view images with eog. We could easily extend this to support some default image viewers for MF Windows™ and Mac OSX, but for simplicity, that has been left out.



Here is an image of the above code in action (after hitting 'm' on an image node):

The code is responsible for the last 2 lines of the menu. Some highlights:
  • Lines 13 and 14 add the menu separator (the line of dashes).
  • Lines 17–21 add the (v)iew image menu item.
  • Lines 14 and 20 ensure that the menu items only appear when the cursor is over an image node.
  • Line 21 connects the menu item to the NERDTreeViewImageMenuItem() function which shells out to eog to open the image.

Final ravings

We've seen a couple of basic examples of NERD tree plugins that show how to add additional key mappings and menu items. I've written many more such plugins, which have mostly been for the purposes of integrating the tree with external programs (e.g. git and grep), or with other vim plugins (eg UTL). I've also written plugins that add slightly modified versions of existing key mappings, or even override the existing mappings.

One day I may stop watching pr0n long enough to clean up and post some more complex examples. Until then, try to behave yourselves, and flick me an email if you write any dynamite NERD tree plugins!

Monday, June 28, 2010

Hacking line numbers into embedded gists

Github has the only corporate mascot in existence that I fantasize about touching inappropriately.




When github unveiled their gist service in 2008, I went into my room, jumped up on my bed, ripped all the playboy posters off the ceiling and taped up a giant portrait of the octocat.

But HOT DAYYUMN is github's lack of line numbers on their embedded gists pissing me off! I've been trying to write another raving containing a reasonable amount of code that is explained over the course of the post — pretty fucking hard without line numbers!

So I went and wrote some javascript hacks to add line numbers in for me.

The hacks

I originally tried to do it with prototype, but was having so much trouble getting it to work on IE6 that I decided to try out jquery instead. Cunting fuck I hate fucking Internet Explorer 6! Ive lost count of the number of rape fantasies I've had about Bill Gates! Anyway, check out these hacks below — maximum credit goes to gaving for refactoring them into not sucking.



Notice those line numbers? ZOMG!


How to use said hacks

Its easy, check out this example:

Its worth noting that the url for the "line number hackz0r script" is from the "view raw" link of the previous gist. If you remove the SHA1 from the url, it seems it always grabs the latest revision of the gist.

Monday, June 21, 2010

The best of Lardcore Volume Three

The other day I was rummaging around looking through the old junk on my hard drive. You know what I'm talking about. Those nostalgic moments when you rediscover some old game you spent ages getting to compile but never really played, or several incrementing versions of the JVM you saved over a period of time, or some long lost porn, or some filthy hacks to download porn, or some hentai that was so fucking funny you just had to save it for later but then forgot where the fuck you stashed it... Anyway, I discovered this edition of Lardcore. It's a few years old, but so priceless(ly retarded) that it has to be aired. Enjoy.

Image(1077)

This picture was taken in the midst of a terrible struggle for survival. Let me tell you a tale...

Once upon a time I took a Computer Science paper at The Ronald McDonald University for the Rectally Handicapped*. Midway through the course I was unfairly failed for one of the tests, and trudged up to the lecturers office to clear things up...

Looking me square in the eye he said, "Son, the reason I failed you is because your brain is composed largely of faeces. You suck more balls than a one legged man in an ass kicking contest". Clearly there was no changing his mind. Oh well. Plan B. "Sir", I began, "allow me to take a moment to fill you in on my recent sexual encounters with your family, friends and pets". "Ok" he replied and sat back, listening patiently. After a full 30 minutes, I gave up and moved on to death threats. Finally, as I was detailing the various rectal mutilation techniques that I would apply to his dead parrots, he snapped.

Like a ferocious lion, he leaped up on his desk, pulled the above hat and glasses out of his back pocket, and roared! His nostrils flared and steamed and his voice seemed to issue forth straight out of their snorting depths: "SONNY, DON'T YOU KNOW WHO YOU'RE DEEEALING WITH!" He then double somersaulted off his desk, punctuating the landing with a screeching "BOOOOM!", before erecting himself in the above pose mere centimeters from my terrified face. It was then that I noticed the distinctive bulge of an M20B1 Super Bazooka tucked into his belt and under his shirt.

I can confidently say that, had I left home without my grappling gun and smoke grenades, I would now be dead.

I had to conceal myself while I made my escape. So, as he struggled to free the bazooka from his pants, I snap rolled toward the door while unclipping a smoke grenade from my utility belt. Hefting the device, I cocked my arm and hurled it at his face. It clocked him hard and true in the chops, granting me a few precious seconds while his vision blurred with tears and the air became translucent with spittle as he dropped f-bombs for Africa.

I let loose my own roar. Only my roar was actually more like a terrified scream. Well... if we're gonna get technical about it: I screamed in the manner of one who is having his testicles busted open with a nutcracker while simultaneously having his remaining genital equipment welded to his anus.

I ran out of his office and down the corridor screaming like my life depended on it — which I assure you, it did. If I had thought about it, I suppose I would have turned my head and screamed backwards to boost my speed. But I wasn't thinking straight.

Ronald McDonald** sprang from his office like a deadly switchblade poised for the kill. He dropped to one knee, switched the bazooka to full-auto and went for the head shot.

Lucky for me, he'd left the safety on, and I reached the end of the building just as he fumbled off the first rocket. I smashed out of the 3rd story window and grappled onto the next building, swinging out of harms way as he completely obliterated the top 4 stories of the computer science building...

Unfortunately, there were no witnesses as everyone in the building had their music up too loud to notice the commotion. Thus, me and Ron were forced to spend the rest of the semester carefully avoiding each other.


NOTE: It is vital for our children that the world hears this story, which is why I have petitioned Michael Bay to make this raving into a movie. Sign it here!

* Yes, this is the real name of the university I attended.
** Yep! I was lectured by the one and only.

Saturday, May 8, 2010

How csplit turned my software into hardware

I'm typing this text with my penis.

This is made possible largely due to the erection inducing side-effects of csplit — a program I'd never used until today.

Story time!

Once upon a time in a far distant land, there was a handsome, charming, young prince who had never known true love... Meanwhile, somewhere else, I was sitting at my desk, scratching my head, wondering how the cunting fuck I was going to extract the tiny part of this 1.8GB database dump that I needed. The dump was generated with something like
mysqldump --all-databases > all_databases.sql
giving me a file with a metric fuck-load of sql to create databases, and insert data into them — from which I needed one particular database.

Of course I tried to edit it with Vim first (before realizing how large it was) and had to kill it before it started eating into my swap. Gedit gave me similar results, and Emacs just told me to fuck off. However, a quick trip to google gave me the answer: csplit! Following which my four foot blackzilla punched a hole through the front of my jeans and stabbed me in the eye.

Anyway, I went over to my dump file and grepped the bastard to find out the order that the "CREATE DATABASE" statements appeared in and then snipped out the one I wanted with these hacks (where foo_database is the database I wanted to extract, and bar_database is the next one in the file):
csplit all_databases.sql '/CREATE DATABASE.*foo_database/' '/CREATE DATABASE.*bar_database/'
This outputted three files (xx00, xx01, xx02):
  • xx00 containing everything up to the first match of /CREATE DATABASE.*foo_database/ (a regex)
  • xx01 containing everything between the two regexes (including the line matching the first regex)
  • xx02 containing everything after the second regex (/CREATE DATABASE.*bar_database/)
This put the code that I wanted into xx01. Very handy!

A related tool that could also have been useful is plain split. For example

split --bytes=10000000 a_large_file
would split a file up into 10MB chunks.

Saturday, December 19, 2009

Hacking IE6 With Sass Mixins

Just recently I was raging against Internet Explorer 6 and the hacks that are required to overcome its shitty css support when it occurred to me that Sass mixins could be used to abstract away some of these hacks.

Read this raving if you use sass and rage against having to support IE6.

Bill Gates is way more awesome than Hampton Catlin (at sucking)


Good morning class, let us begin today's lesson with some quotes.

Now, I ain't gay, but let it be known that Sass is so fucking awesome that I'd definitely suck Hampton Catlin's cock. For free!
Scrooloose - 12th Dec, 2009

Many of you may be offended by the above homo-erotic sentiments and view them as inappropriate, but let me ask you: if you call those sentiments "inappropriate" then what, pray tell, the fuck would you call these:

I love Bill Gates like I love decapitated parrot heads sprinkled on cornflakes with milk and sugar. If I met him on the street I'd kidnap him and drag him back to my secret torture lab, where I would inject a delightful cocktail of fire ants, piranhas, and ninja stars into his anus. Then, I'd don my strap-on cactus and proceed to stir said cocktail with extreme force. Following this, I would feed him — cock first — to the cult of homosexual-rapist-cannibals that I harbor in my basement.

Whoa! Hold on there, thats pretty brutal! Maybe I took that last part a bit too far?? OH WAIT NO I DIDN'T, FUCK YOU BILL!
Queen Elizabeth II (after failing to get her site running in IE)

I hold Bill personally responsible for the travesty of Internet Explorer 6. Not the browser itself mind you, but the fact that it is still widely used today, even though I was still in fucking high school when it was released!*

Having to support such a buggy and incomplete css implementation is enough to make any web developer shit his pants in protest.

Sass mixins to the rescue

I only looked into these the other day, and I wish I'd done it ages ago. Mixins are basically a way to reuse chunks of css.

Check out this example:


Here we create a mixin called "ultimate-hippy-border" which takes a "thickness" parameter. When the css file is compiled, the declarations inside the mixin are evaluated and inlined into the css rules that the mixin is used in.

Check out these links for more info about mixins.

You can see how we could use this to hide css hacks. Check out these examples:



There are several benefits to doing this.

The most obvious is that we no longer have these ugly-as-fuck hacks repeated all over our code. Instead, we are left with much more symbolic mixin code. The intent of +min_height_hack(10px) is much clearer than the 3 line hack we would otherwise inline. This makes things more concise, readable and DRY, which results in some erection-inducing maintainability.

I can haz a repo on github?

I've created a repo on github with the hacks that ive been using so far which, at the time of this writing, is nothing more that what's in the gist above. Not impressed? Here, check out this ballsack:

How you like me now?

If you're still not satisfied, then you'll have to fork me and add your own hacks.


* if you are one of the people that still uses IE6 and you are not clinically dead then please correct this situation immediately. Thank you.