Skip to content

Instantly share code, notes, and snippets.

Nicolas Hery nicolashery

Block or report user

Report or block nicolashery

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
nicolashery / poisson.js
Created Jun 28, 2013
Quick JavaScript implementation of Exponential and Geometric random number generators
View poisson.js
/* Quick implementation of Exponential and Geometric random number generators
For example you can use it to simulate when an event is going to happen next, given its average rate:
Buses arrive every 30 minutes on average, so that's an average rate of 2 per hour.
I arrive at the bus station, I can use this to generate the next bus ETA:
randomExponential(2); // => 0.3213031016466269 hours, i.e. 19 minutes
View HaskellJsonTypescript.hs
#!/usr/bin/env stack
{- stack
--resolver lts-13.4
--ghc-options "-Wall"
--package aeson
--package aeson-pretty
--package aeson-typescript
--package base
nicolashery / mongoose-paginate.js
Last active Jan 24, 2018 — forked from craftgear/
Mongoose Paginate plugin
View mongoose-paginate.js
/* Mongoose Paginate plugin
Forked from:
This snippet is inspired by edwardhotchkiss's mongoose-paginate
and works with any methods like where, desc, populate, etc.
The `paginate` method must be called at the end of method chains.
nicolashery / Makefile
Last active Jan 7, 2018
Svelte.js & Google Closure Compiler
View Makefile
mkdir -p vendor
curl -o vendor/closure-compiler.tar.gz $(CLOSURE_COMPILER_URL)
tar -C vendor/ -zxf vendor/closure-compiler.tar.gz
mv vendor/closure-compiler-v$(CLOSURE_COMPILER_VERSION).jar vendor/closure-compiler.jar
rm vendor/COPYING vendor/ vendor/closure-compiler.tar.gz
nicolashery / Main.hs
Last active Aug 19, 2017
Exploring internationalization (i18n) in Haskell (message translations, datetime format, number/currency format)
View Main.hs
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveGeneric #-}
module Main where
import Data.Monoid ((<>))
import qualified Data.Text as T
import Text.Shakespeare.I18N (mkMessage, renderMessage, RenderMessage())
nicolashery / q-angular.js
Last active Feb 9, 2017
deferred.resolve() (using AngularJS' $q) and $rootScope.$apply() in async function outside of Angular
View q-angular.js
// Resolving a deferred created by AngularJS' $q, in an async function outside of Angular (ex: setTimeout)
// See:
// Using AngularJS' $q (1.0.7)
function testDeferredAngularSync() {
var deferred = $q.defer();
nicolashery /
Last active Nov 30, 2016
Proof of concept transforming React JSX code to a string-concatenating function with a Babel plugin


Go to, select babylon6 as the parser, and babelv6 as the transform option.

Paste in the babel-plugin-react-string.js code in the transform area.

Paste the following example source code:

function profile(props) {
nicolashery / gulpfile-react-jshint.js
Created Oct 20, 2014
Gulpfile for JSHint on a React app with watch, JSX error logging, and cache
View gulpfile-react-jshint.js
var gulp = require('gulp');
var react = require('gulp-react');
var jshint = require('gulp-jshint');
var cache = require('gulp-cached');
var jsFiles = [
View projections.js
// We can mentally separate "core state" from "derived state".
// Core state is where you can put normalized data (for relational data):
// it is the "single source of truth".
// Derived state is where you shape the core state into a representation that's
// closer to what you need in your views and components.
var coreState = {
venuesById: {
'v1': {id: 'v1', name: 'Hipster Coffee House'},
'v2': {id: 'v2', name: 'Veggies For Everyone'}
# avoid "works on my machine" by always locking dependency versions
npm config set save-exact=true
# install/uninstall project packages with flags that will update package.json
npm install --save lodash
npm install --save-dev jshint
npm uninstall --save lodash
# tool that makes upgrading dependencies easier, install it globally
npm install -g david
You can’t perform that action at this time.