rand(Ø)

> beautiful code & photos

about <

Posts tagged: script

JS: Singleton as a module

When you develop a NodeJS application, you probably get to work with services and as much as possible with service dependency injection.
As I worked quite a lot with Symfony lately, I wanted to be able to manage my NodeJS services as it should be, and in some case, like a database connection: a single instance for the whole script.

I quicky looked onto Internet to see how to build a singleton in JavaScript (pardon my weak skills in this language) and I quickly found what I was (almost) looking for.

Code examples provided in the different posts I've read

> Continue Reading

NodeJS: Quick dev server

I'm on a nice project where I need to develop a kind of proxy in NodeJS. When you work to forward data after possible filtering or transformation, it's never too easy to quickly set up an environment in order to test your on-going development.

Using NodeJS, I extended my colleague very small HTTP server that just returns a 201 HTTP code and prints the request body in the console:

// debug-server.js
var http = require('http');  
var port = process.env.PORT || 8080;  
var host = '127.0.0.1';

http.createServer(function (request, response) {  
    // console.log(request.headers);
    request.pipe(process.stdout)
> Continue Reading

Wordpress to Ghost

Today For the past 2 weeks, I've been trying to move out from my beloved Wordpress blog to this new, shiny and hipsterish blog plateform called Ghost.

So, two big moves:

The longest part wasn't to have Ghost up and running but to import all my Wordpress shit into this baby's DB. Ha, a long story that involved automated and manual work.

Import WP data into Ghost

At first, I tried the Ghost Wordpress Plugin which exported well my WP data but I

> Continue Reading

SH: md5sum -c like for Mac OSX

Okay, since I plan to upload old backup archives to the cloud with fear to lose data integrity, I wanted to calculate the MD5 hash of these archives before any manipulation. OSX has natively the MD5 command provided by OpenSSL but no argument to check automatically a file checksum against another file which would contain its checksum.
And the -r generates broken MD5SUMS pattern output (the default OpenSSL star is stripped)!

In order to be able to use the md5sum command on OSX like on other Unix platforms, I developped a small script that will behave alike. I hosted it

> Continue Reading

ZSH: Open a new window using the last pwd

A friend of mine used ZSH on his Mac and since I know him and his .zshrc, I keep ZSH as main CLI on my laptop, it works so well, I advice you to switch if still not :P .

But, I was very tired of typing a long cd command every time I wanted to open a new Terminal tab to execute a command in the same directory or close to where I was working ; so I looked for a hack to get rid of this pain over the Internet and now, I'd like to share it with you.

The

> Continue Reading

PHP: héritage multiple

PHP est un langage qui ne supporte pas l'héritage multiple depuis le début de sa pseudo-implémentation objet. L'héritage multiple apporte bien des soucis aux architectes logiciels car le point fort et le point faible de l'héritage multiple est le fait qu'il soit multiple.

Dans cet article, je vais vous montrer qu'il est possible de gérer plus ou moins dynamiquement l'héritage multiple grâce au concept d'agrégation, aux interfaces ainsi que les méthodes magiques de PHP.

Pour illustrer le plus simplement possible, je vous ai concocté un petit exemple concret qui permet de mettre en œuvre cet héritage multiple. Pour cela, il

> Continue Reading