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
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
--install-ghc
script
--ghc-options "-Wall"
--package aeson
--package aeson-pretty
--package aeson-typescript
--package base
@nicolashery
nicolashery / mongoose-paginate.js
Last active Jan 24, 2018 — forked from craftgear/mongoose_paginate.coffee
Mongoose Paginate plugin
View mongoose-paginate.js
/* Mongoose Paginate plugin
Forked from:
https://gist.github.com/craftgear/1525918
This snippet is inspired by edwardhotchkiss's mongoose-paginate
(https://github.com/edwardhotchkiss/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
nicolashery / Makefile
Last active Jan 7, 2018
Svelte.js & Google Closure Compiler
View Makefile
CLOSURE_COMPILER_VERSION := 20180101
CLOSURE_COMPILER_URL := http://dl.google.com/closure-compiler/compiler-$(CLOSURE_COMPILER_VERSION).tar.gz
closure-compiler:
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/README.md vendor/closure-compiler.tar.gz
@nicolashery
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
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:
// https://github.com/angular/angular.js/wiki/When-to-use-$scope.$apply()
// http://stackoverflow.com/questions/16066170/angularjs-directives-change-scope-not-reflected-in-ui/16066306#16066306
// https://github.com/angular/angular.js/blob/master/src/ng/timeout.js
// Using AngularJS' $q (1.0.7)
function testDeferredAngularSync() {
var deferred = $q.defer();
@nicolashery
nicolashery / 0-react-jsx-string-concatenation.md
Last active Nov 30, 2016
Proof of concept transforming React JSX code to a string-concatenating function with a Babel plugin
View 0-react-jsx-string-concatenation.md

Instructions

Go to http://astexplorer.net/, 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
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 = [
'src/**/*.js',
'test/**/*.js',
'*.js'
];
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'}
View npm-cheat-sheet.sh
# 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.