Skip to content

Instantly share code, notes, and snippets.


Nicolas Hery nicolashery

View GitHub Profile
nicolashery / AsyncMonadBaseControlExample.hs
Created Sep 9, 2022
Haskell ReaderT LoggingT - MonadBaseControl vs. MonadUnliftIO
View AsyncMonadBaseControlExample.hs
module AsyncMonadBaseControlExample where
import Blammo.Logging (LoggingT)
import Control.Concurrent.Async.Lifted.Safe (concurrently)
import Control.Monad.Base (MonadBase)
import Control.Monad.Reader (MonadIO, MonadReader, MonadTrans (lift), ReaderT)
import Control.Monad.Trans.Control (MonadBaseControl (liftBaseWith, restoreM), StM)
import Data.Text.Lazy qualified as TL
import Web.Scotty.Trans (ActionT, text)
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 /
Last active Aug 26, 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 / 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 / .gitignore
Last active Sep 24, 2021
TypeScript React JSDoc
View .gitignore
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 / 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())
View mix.dep.txt
$ mix deps
* fs 0.9.1 (Hex package) (rebar)
locked at 0.9.2 (fs)
* gettext 0.9.0 (Hex package) (mix)
locked at 0.9.0 (gettext)
* ranch 1.2.1 (Hex package) (rebar)
locked at 1.2.1 (ranch)
View .bash_prompt
# Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"
# Shamelessly copied from
# Screenshot:
# A big thanks to \amethyst on Freenode
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
if tput setaf 1 &> /dev/null; then
nicolashery / 0-flowtype-playground.js
Last active Oct 28, 2015
Flow playground (
View 0-flowtype-playground.js
/* @flow */
import _ from "lodash";
type UserId = string;
type UserRole =
'admin' |
'guest' |