Skip to content

Instantly share code, notes, and snippets.

@hatashiro
hatashiro / LineNotify.hs
Last active October 13, 2016 07:23
Use LINE Notify with a personal access token
{-# LANGUAGE OverloadedStrings #-}
module Line
( Message (..)
, Messageable (..)
, send
) where
import Control.Lens
import Data.Text
@hatashiro
hatashiro / ps-v1-public.md
Last active June 8, 2017 12:34
perfect-scrollbar v1 design draft for public

PS v1 is still in heavy development and everything can be discussed and changed later. It's being developed in the next branch, so please take a look if interested.

API

The following code shows how PS v1 will be used. For the detailed information, some parts are tagged with a number following *. The details are described below with the indexing number.

@hatashiro
hatashiro / aa.js
Created August 1, 2016 14:51
async/await
async function a() {
console.log('a');
throw 'err';
}
async function b() {
console.log('b');
}
(async function () {
@hatashiro
hatashiro / partial-app.js
Created June 8, 2016 07:53
Partial application with fat-arrow functions
const add = a => b => a + b;
[1, 2, 3, 4].map(add(1)); // => [2, 3, 4, 5]
@hatashiro
hatashiro / compose.js
Last active June 8, 2016 08:08
One-liner function composition in JavaScript
export default function compose() {
return x => Array.from(arguments).reverse().reduce((a, f) => f(a), x);
}
@hatashiro
hatashiro / tip.md
Last active June 6, 2016 13:29
A simple tip to throw errors from promises in Node.js

When we try to throw an error from a promise, it actually isn't thrown into the running Node.js process. It seems the error is swallowed or ignored.

function throwErr() {
  return new Promise(() => {
    throw 'a critical error!';
  });
}
#!/usr/bin/env bash
if [ -z "$3" ]; then
scale=600
else
scale=$3
fi
if [ -z "$2" ]; then
out="out.gif"
@hatashiro
hatashiro / IdentityT.hs
Last active May 2, 2016 16:18
A monad transformer for Identity
import Control.Applicative
import Control.Monad
import Control.Monad.Trans.Class
import Data.Functor.Identity
newtype IdentityT m a = IdentityT { runIdentityT :: m (Identity a) }
instance Functor f => Functor (IdentityT f) where
fmap f = IdentityT . fmap (fmap f) . runIdentityT
@hatashiro
hatashiro / CataAna.hs
Created April 26, 2016 08:23
Sum of [1..n] using catamorphism and anamorphism
{-# LANGUAGE DeriveFunctor #-}
module Main where
import Data.Fix
type CataAlgebra f a = f a -> a
type AnaAlgebra f a = a -> f a
data ListF a b = Nil | Cons a b deriving (Show, Functor)
@hatashiro
hatashiro / Main.hs
Created October 31, 2015 09:44
Sierpinski Triangle
module Main where
import Data.List
import Lib
pad :: Int -> [Char] -> [Char]
pad size str
| length str < size = str ++ replicate (size - length str) ' '
| otherwise = str