rand(Ø)

> beautiful code & photos

about <

Posts tagged: script

To rewind, or ! (to rewind)

Lately, I was missioned to integrate a vendor PHP SDK that is transport-agnostic as it implements HTTPlug. Pretty cool.

Everything went well until I found out that the SDK used a response reader method helper which is:

/**
 * @param ResponseInterface $response
 *
 * @return stdClass
 */
private function handleResponse(ResponseInterface $response)
{
    $this->setRateLimitDetails($response);

    $stream = $response->getBody()->getContents();

    return json_decode($stream);
}

First issue: I can't pick the response format, I'm forced to deal with the object deserialization version of the JSON payload. This is okay but not completely since the structure of the JSON may vary if my peers

> Continue Reading

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 for 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 developed 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 the main CLI on my laptop, it works so well, I advise you to switch if still not 😛 .

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