Skip to content

Instantly share code, notes, and snippets.

View nicolashery's full-sized avatar

Nicolas Hery nicolashery

View GitHub Profile
@nicolashery
nicolashery / Makefile
Last active January 7, 2018 21:50
Svelte.js & Google Closure Compiler
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 August 19, 2017 07:16
Exploring internationalization (i18n) in Haskell (message translations, datetime format, number/currency format)
{-# 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 February 9, 2017 11:31
deferred.resolve() (using AngularJS' $q) and $rootScope.$apply() in async function outside of Angular
// 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 November 30, 2016 03:50
Proof of concept transforming React JSX code to a string-concatenating function with a Babel plugin

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 October 20, 2014 17:06
Gulpfile for JSHint on a React app with watch, JSX error logging, and cache
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'
];
// 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
$ mix deps
* fs 0.9.1 (Hex package) (rebar)
locked at 0.9.2 (fs)
ok
* gettext 0.9.0 (Hex package) (mix)
locked at 0.9.0 (gettext)
ok
* ranch 1.2.1 (Hex package) (rebar)
locked at 1.2.1 (ranch)
ok
// Exploring using "expose React component tree as data" @swannodette
// (https://www.youtube.com/watch?v=5hGHdETNteE#t=1559)
// for routing and fetching data ("react-router-mega-demo" @ryanflorence)
// (https://github.com/rackt/react-router-mega-demo/blob/master/app/utils/fetchData.js)
var appState = {
route: '/contacts',
contacts: [],
messages: []
};
@nicolashery
nicolashery / ink-file-picker.js
Created December 4, 2013 10:43
Ink file picker encoded security policy and its signature with Node.js
/* Ink file picker encoded security policy and its signature with Node.js
https://www.inkfilepicker.com/
https://developers.inkfilepicker.com/docs/security/
Usage:
ink.encodePolicy({
handle: 'KW9EJhYtS6y48Whm2S6D',
expiry: 1508141504