Skip to content

Instantly share code, notes, and snippets.


Nicolas Hery nicolashery

View GitHub Profile
nicolashery /
Last active Jul 13, 2021
Make environment variables available in Jekyll Liquid templates

Environment variables in Jekyll templates

This is one way to pass some data (API tokens, etc.) to your Jekyll templates without putting it in your _config.yml file (which is likely to be committed in your GitHub repository).

Copy the environment_variables.rb plugin to your _plugins folder, and add any environment variable you wish to have available on the site.config object.

In a Liquid template, that information will be available through the site object. For example, _layouts/default.html could contain:

nicolashery /
Last active Jun 22, 2021
Elasticsearch: updating the mappings and settings of an existing index

Elasticsearch: updating the mappings and settings of an existing index

Note: This was written using elasticsearch 0.9.

Elasticsearch will automatically create an index (with basic settings and mappings) for you if you post a first document:

$ curl -X POST 'http://localhost:9200/thegame/weapons/1' -d \
  "_id": 1,
nicolashery / .gitignore
Last active Jun 16, 2021
TypeScript React JSDoc
View .gitignore
nicolashery / solarized-dark.css
Last active Jun 12, 2021 — forked from scotu/solarized.css
Solarized theme stylesheets for Jekyll and Pygments
View solarized-dark.css
/* Solarized Dark
For use with Jekyll and Pygments
--------- -------- ------------------------------------------
base03 #002b36 background
base01 #586e75 comments / secondary content
nicolashery /
Created Sep 8, 2012
Deploy Python app using Pandas on Heroku

Deploy Python app using Pandas on Heroku


This document explains how to deploy a Python app that uses the Pandas library on Heroku.

Heroku builds Numpy (one of Pandas' requirements) fine. However, when trying to deploy an app with both numpy and pandas in its requirements.txt file (or even just pandas), for some reason it fails

nicolashery /
Last active Apr 1, 2021
Emulating "enums" in JSDoc version of TypeScript

Emulating "enums" in JSDoc version of TypeScript


TypeScript has support for type-checking plain JavaScript files, which is very useful if you have an existing JS codebase and you want to test the waters and gradually add types.

There are some limitations in what you can do in JSDoc, but a lot of them can be worked-around by using type-definition files .d.ts (for example in a types/ directory). These files don't generate any JavaScript code, they are just there to provide extra type definitions to the compiler.

One thing you can't do in those .d.ts files though, is use enums. You could define them of course, but you won't get the runtime representation since the files don't generate JS code.

nicolashery / example.js
Last active Mar 3, 2021
Combine a pipe of multiple Node.js streams into one stream
View example.js
var util = require('util')
, Transform = require('stream').Transform
, StreamCombiner = require('./streamcombiner');
var chunks1 = [];
var stream1 = new Transform();
var soFar = '';
stream1._transform = function(chunk, encoding, done) {
var pieces = (soFar + chunk).split('\n');
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
nicolashery / rxjs-react.js
Last active Feb 1, 2020
Fetching data asynchronously with RxJS and React
View rxjs-react.js
import React from 'react';
import _ from 'lodash';
import Rx from 'rx';
import superagent from 'superagent';
let api = {
host: 'http//localhost:3001',
getData(query, cb) {
nicolashery /
Last active Aug 23, 2019
D3.js chart with panning and paging

Click, hold, and drag chart background to pan left & right. When you see the "More" button, click to load next page of data.


I put this together while trying to find a simple solution to the following problem and contraint:

  • Visualize a potentially large set of timeseries data (stored behind an API)
  • Render fast, stay lean, and don't take up too much browser memory or computation

The paging means that we're always working with the same amount of data in memory (in this example, 1 day of data), and that we're allowed to explore as far back/forward in time as we like. I found this solution simple and easy to work with, but we could imagine something fancier like automatically fetching and rendering the next chunk of data when we reach the edge.