Skip to content

Instantly share code, notes, and snippets.

View baptistemanson's full-sized avatar
🌼
Blooming

Baptiste Manson baptistemanson

🌼
Blooming
View GitHub Profile
const ADD = 'my-app/users/ADD';
export default function reducer(state = {}, action = {}) {
switch (action.type) {
ADD: return {...state, [action.payload.id]: action.payload}
default: return state;
}
}
// Action Creators
const store = createStore(
reducer,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);

Here is my experience of 5h with reasonml. It is only my developer experience, and I focused on the things that can be improved.

The good parts

  • didn't hit any bugs
  • type inference is really pleasurable
  • merlin worked great in vscode
  • awesome discord community

The stuff that would have greatly improved my experience

@baptistemanson
baptistemanson / fast-json-packing.js
Created February 10, 2017 21:22
JS fast packing with JSON
/**
* FAST PACKING / UNPACKING JSON
*
* If all objects in a collection follows a similar schema,
* then there is gain in changing the representation from a dictionary to a simple array.
*
* It is known results used in database, protocols, in v8 itself with shadow maps and IRL.
*
* In this example, we expect our final exchange to be equivalent to this literal representation:
* [
@baptistemanson
baptistemanson / parallel-wget-node.js
Created November 6, 2015 18:44
Parallel wget with node in a few lines
var fs = require('fs');
var queue = require('queue');
var wget = require('wget-improved');
var downloadUrl = function(url) {
return function(cb) {
try {
// you can also change the mapping url to file here by changing the function
var download = wget.download(url, () => ('./downloads/' + url.substring(url.lastIndexOf('/') + 1) ) , {});
download.on('end', function() {
SELECT
tc.constraint_name, tc.table_name, tc.constraint_name, kcu.column_name,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name