Decorators In C

Turns out you can also do decorators in C, this came in handy for something else I had to work on recently. It’s not quite as nice, because functions aren’t first-class, but handy nonetheless.

Here’s what that looks like:

The output of which is:

vilimpoc@funky:~$ ./c-decorators
hello, C decorators!
functionOne: 1, 2
decorator precondition!
functionOne: 1, 2
decorator precondition!
functionTwo: 1, 2
decorator precondition!
functionThree: 1, 2
vilimpoc@funky:~$

This might be a bit simplistic, in reality, you’d probably want to decorate a function with a signature like the following, so that you can just change the structure and not bother w/a bajillion function declarations:

Again, not super elegant, but handy.

Javascript Decorators

One reason why Javascript rocks:

As a use case, imagine you want to restrict a certain set of functions to only run if you are logged in. Doing stuff like this is ridiculously easy with first-class functions.

Here’s a generic decoration example:

Update: Here’s the specific way you’d do this with node.js/Express:

Since all of the URL handlers you register have the same signature, it’s easy to add precondition checks to the handlers via decorators.

You get preconditions essentially for free, which is a damn sight better than adding the if() block to each and every handler function. Also, if you need more preconditions in the future, you can just stack them.

Installing Mercurial Without Admin Rights And No C Compiler

Cheap webhosters can be pretty limiting sometimes in the platforms they run and the software packages on offer, even when you do have shell access. Here’s a quick guide to setting Mercurial up on a shared webhost for use when:

  • there is no Python.h available, so you cannot build the C extensions
  • you can build only the pure Python modules, which is slower but more compatible
  • you have to do all of this in your home directory somewhere

Continue reading Installing Mercurial Without Admin Rights And No C Compiler

Website Backup With rsync

One thing that kept me from getting my blog back up for a while was the lack of a consistent backup strategy for the WordPress content and the website as a whole. Website backup should be easy, with these commands and the following script, it’s very easy.

This is just a starting point though, I have some ideas about backup that I plan to explore in future experiments.

Manual Runs

Quick backup command lines:

Continue reading Website Backup With rsync