Articles

Affichage des articles du 2016

Better than tar

This time I'd like to show you, why I love JavaScript:

Improving tar with a simple idea and few lines of JavaScript

The code is on github:
jntar (with more info about the original idea of meta-compression)

How to learn JavaScript with confidence

If you're lost among all the JavaScript frameworks, if you're still hesitating between all the different tools to use, if you're scared by the JavaScript ecosystem complexity, have a look to my post on hello.js :

How to learn JavaScript with confidence

Things might not be as bad as it seems...

Change your Gogs admin password

I might have missed something, but I haven't found any simple way to change my admin password (with emailing not active) in gogs.

It was quite easy to find the hash location, but as I didn't know how it was generated...

Luckily I eventually found the parameters used, so here it is for you if you need them embedded in a script :

var pbkdf2 = require('pbkdf2-sha256');
var key = 'YourChosenPasword';
var salt = 'AnyRandomValue';

var hash = pbkdf2(key, salt, 10000, 50); console.log(hash.toString('hex'));

All I had to do was then to update the table user, setting passwd to the generated value (and updating salt with the value used in the script).

The devil codes in Pramda - Wandering in the JavaScript Functional programming world

Article originally published on Hello.js
As a Perl coder, I'm a big fan of functional programming.
If that sounds odd to you, think about all that features that are considered as idiomatic Perl : List processing (map, grep)High order functions (Mark Jason Dominus ;-) )Lazy evaluation (iterators)Lamda calculus (closure)
Functional programming is a fascinating thing but it’s not so easy to use consistently. We all love the concept, feel the inner power. We all use lists, closure, functions as parameter, but how many of us manage to fully apply functional programming everywhere and commit to pure functions and immutability ?
I recently discovered a wonderful library for functional programming in JavaScript that could help you embrace functional programming even more and I'd like to share it with you: it's calledRamda. There are several other functional programming libraries (more on that below) but what makes Ramda so practical and somewhat unique is its combination of auto-curryin…

JavaScript for Perl lovers.

Article originally published on Hello.js

This time I feel really qualified to write this article, because believe me, I love Perl ! I think in Perl, I dream in Perl, and I really appreciate the whole Perl community. I’ve been in love with this language for more than a decade but I decided that I needed a change.

I’ve already said in a previous article why I chose to learn JavaScript this year (instead of getting involved in Perl 6 for example) but let me tell you why you might also enjoy learning JavaScript if you love Perl. Perl developers form a very unified community that all too often, resist outside influences, but learning a secondary language as JavaScript can really be a very enlightening experience.

It’s expressive  JavaScript, like Perl, is an expressive language. You get your work done with just a few lines of code. When talking about programming languages, I really like the tent analogy:

In a tent you have functional things (tent fabrics) whose purpose is to provide a funct…

Why Javascript in 2016 ?

Many of my friends express their surprise when I say I chose to learn JavaScript in 2016.

With so many cool languages to learn, why using a "toy language" of the past instead of, let's say Haskell, Go, Nimrod, Rust (just to name some)?

First and foremost, for me it's not as much as learning JavaScript in 2016 as learning a new language in 2016. But whatever your reasons : not become fossilized, improve your efficiency with new tricks/paradigms/tools or just plain fun you'll probably feel the urge to learn a new language sooner or later.
This bring us back to the question why JavaScript in 2016?
Reason to choose JavaScript Ubiquity It could be handy to be able to do everything in one unique language (from command line tools, front-end Web dev,  server coding, phone applications to robots programming) and JavaScript now allows that. That wasn't the case before but with node/express/commander/ionic/cylon.js (to name few) you'll have all your needs covered.

Migration dans la simplicité.

Après une mise à jour de mon système je me suis retrouvé avec un postgresql 9.5 flambant neuf (et vide) ! et une version 9.3 encore en place avec toutes mes bases dedans.

Mais moi je veux toutes mes bases dans la 9.5 et pas de 9.3.

Modification du Port à 5433 dans /etc/postgresql/9.3/main/postgresql.conf et 5432 dans /etc/postgresql/9.5/main/postgresql.conf

Un petit redémarrage en tant que root

root@vault:~# pg_ctlcluster 9.3 main restart
Redirecting restart request to systemctl
root@vault:~# pg_ctlcluster 9.5 main restart
Redirecting restart request to systemctl

Une copie simplissime en tant qu'utilisateur 'postgres' :

postgres@vault:~$ pg_dumpall -p 5433 | psql -d postgres -p 5432

Un peu de nettoyage

root@vault:~# pg_ctlcluster 9.3 main stop
Redirecting stop request to systemctl
root@vault:~# pg_dropcluster 9.3 main

Et voila toutes mes bases migrées...

J'adore PostgreSQL !

Yeoman : Passing data from generator to sub generator

I won't present Yeoman here. If you like to use scaffolding tool and use JavaScript, you already have heard about this great tool.

Maybe you've even tried to write your own generator. If you did, sooner or later you'll want to structure your code using sub generators and pass data from your (main) generator to your sub generators.

This simple task took me more time than needed, mainly because I was unable to find the right documentation.
The official documentation on the topic suggest using composeWith() with the options parameter to pass data to the called generator, but doesn't show how to get the data in the called generator.

So in hope the following could help others, you'll find below an example of how to do it.

In the generator you call the sub-generators this way :
//in generator-arhuman/generators/app/index.js this.composeWith('arhuman:express', { options: { my_opt: 'anystring' } }, { local: require.resolve('../express') });
Note th…

Installation locale de nodejs et npm

Pour mes environnements de développement je suis un fan des environnements locaux
(perlbrew/plenv, virtualenv...) :
_  Pour séparer mon environement de développement du sytème
_  Pour se dispenser du sudo
_  Parce que ça donne une meilleur visibilité sur l'environnement de dev qui est ainsi mieux contenu/localisé.

C'est pourquoi comme je vais désormais utiliser assez souvent node et npm, je préfère le mode d'installation suivant à celle classique des paquets sur ma Debian.

# Installation des prérequis (optionnel)
sudo apt-get install build-essential curl

# Ajout d'un répertoire au PATH
mkdir ~/local
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
 # Installation de node via les sources mkdir ~/node-install
cd ~/node-install

# Pour choisir la version (idéalement LTS)
# https://github.com/nodejs/LTS

curl http://nodejs.org/dist/latest-v4.x/node-v4.5.0.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install cd .. rm -rf  ~/node-ins…

Année de Javascript

Parmi mes résolutions de début d'année l'étude approfondie de Javascript et de son écosystème tient une place de choix.

Pourquoi Javascript ? Alors que Perl 6 est là ? Que des langages plus récents comme nimrod, go, rust ont vent en poupe ? Que des langages offrant d'autres paradigmes comme haskell, clojure seraient plus dépaysant ? Pourquoi Javascript en 2016 ?!?

Pour moi les principales raisons sont :
_ La souplesse du langage (je retrouve pas mal de choses que j'aime avec Perl)
_ L'asynchronisme dans son "adn"
_ La maturité de l'écosystème nodejs (npm !)
_ La possibilité d'utiliser le langage partout (serveur, navigateur, ligne de commande, embarqué...)
   (et pour *tous* les projets qui me trottent dans la tête)
_ Le moment me semble idéal  (ES6, Angular 2 béta, Année du singe ;-) )


J'ai déjà conscience que tout n'est pas rose (callbacks hell, le rythme de sortie et d'obsolescence des frameworks/libraries qui est dément...) et j&#…