mardi 11 octobre 2016

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...

lundi 29 août 2016

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).

mercredi 6 juillet 2016

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 called Ramda.
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-currying and the design choice to put the data last. These two things empower you and give you endless possibilities through composition.

You probably already know how map and grep can compose to solve many different tasks in a clean way. Now imagine that Ramda offers you one hundred of such functions. The number of combinations, solutions and tasks that you can solve easily just explodes! *1
This might seem theoretical, but for a simple demonstration of how Ramda can ease your life, just read  “Why Ramda ?” by Scott Sauyet.
Among the other things that make Ramda so powerful, Iis its ability to mix with promises through ‘pipeP’ and ‘composeP’. Being able to use both functional programing and promises through a clean syntax is priceless to me.

I should also underline the fact that Ramda promotes immutability: it doesn’t mutate input data by default but still allows you to produce modified one through 'assoc'.
As a final note: Don’t be scared by Ramda’s API, it offers probably far more than you want,  but everything you need. Follow the easy path:  just pick/learn functions one by one.

That being said, it would be unfair to limit functional programing in Javascript to Ramda. If you'd like go further and explore the domain, here are some other projects that I'd suggest to examine:

The well known  'generic' libraries offer functional tools, like the venerable  underscore,  lodash and it’s speedy brother lazy to name a few.

The reactive programming world also provide functional features with RxJs, Kefir or Bacon for the UI.

And if you want to experiment immutability, the choice is your : You can climb on the shoulders of a giant and use Facebook’s immutable or favour speed with mori or try the frozen object approach of icepick.
In a future article I'd like to talk about my current favourite youtube tech channel : 'funfunfunction'  so stay tuned! It's a really great channel about functional programing, JavaScript and other topics of interest.


Oh, and if you wonder about the title:
I like Ramda so much that I wanted to use it in my daily work, and started to write a port in Perl: Pramda (Perl Ramda). Any resemblance to any film title is purely coincidental...

*1 Functions like ‘transpose’, ‘unfold’, ‘times’, ‘allPass’, ‘cond’ are the first examples that come to my mind, but I bet you’ll learn to love the others while using Ramda.