Skip to content

Instantly share code, notes, and snippets.

View spion's full-sized avatar
:shipit:

Gorgi Kosev spion

:shipit:
View GitHub Profile

Disclaimer: I work for Mozilla and am a Node.js core maintainer. The opinions expressed here do not reflect those of Mozilla or the Node.js project.

After watching the events unfold the last 2 days I decided to sit down, with my two cartons of Trader Joe's eggnog, and simply express with all humility and confidence what libuv@47d98b6 definitely was not.

Over the last year I have had the pleasure of being mentored by Ben. He is largely responsible for my initial major involvement writing performance improvements for Node, and has easily surpassed

@robotlolita
robotlolita / 0-specification.md
Last active January 1, 2016 01:29
Monadic Futures specification

A future should provide the fork, of, chain, and orElse methods, subject to the following rules:

new Future(computation)

  1. The computation should fulfil the type (α → γ), (β → γ) → γ.
  2. The value should be stored in the internal field [[Computation]], as-is.
  3. If computation is not a function, the behaviour is undefined.

Future.prototype.fork(f, g)

@briancavalier
briancavalier / example.js
Last active November 24, 2021 20:10
Infinite "lists" in es6 using generators and yield
// Requires traceur
import { iterate, take, map, foldl } from './list-out-of-yield';
// Sum of squares of integers 1..100
var values = take(100, iterate(x => x + 1, 1));
var result = foldl((x, y) => x + y, 0, map(x => x * x, values));
console.log(result);
@tonymorris
tonymorris / Terminal.hs
Created May 22, 2014 09:04
Terminal I/O with Free
{-# LANGUAGE RankNTypes #-}
data Free f a =
Done a
| More (f (Free f a))
instance Functor f => Functor (Free f) where
fmap f (Done a) =
Done (f a)
fmap f (More k) =
@paf31
paf31 / node-haskell.md
Last active April 14, 2021 18:42
Reimplementing a NodeJS Service in Haskell

Introduction

At DICOM Grid, we recently made the decision to use Haskell for some of our newer projects, mostly small, independent web services. This isn't the first time I've had the opportunity to use Haskell at work - I had previously used Haskell to write tools to automate some processes like generation of documentation for TypeScript code - but this is the first time we will be deploying Haskell code into production.

Over the past few months, I have been working on two Haskell services:

  • A reimplementation of an existing socket.io service, previously written for NodeJS using TypeScript.
  • A new service, which would interact with third-party components using standard data formats from the medical industry.

I will write here mostly about the first project, since it is a self-contained project which provides a good example of the power of Haskell. Moreover, the proces

@philopon
philopon / Main.purs
Created December 19, 2014 13:31
xhr-json
module Main where
import Data.Maybe
import Debug.Trace
import Data.JSON
import Network.XHR
main = get defaultAjaxOptions
{ onReadyStateChange = onSuccess $ \response -> do
txt <- getResponseText response
@sacundim
sacundim / Shape.hs
Last active March 31, 2022 14:01
OOP Shape example in Haskell, using existentials, GADTs, Typeable and ConstraintKinds to support downcasts.
{-# LANGUAGE GADTs, ConstraintKinds, KindSignatures, DeriveDataTypeable #-}
{-# LANGUAGE TypeOperators, ScopedTypeVariables, FlexibleInstances #-}
module Shape where
import Control.Applicative ((<$>), (<|>))
import Data.Maybe (mapMaybe)
import Data.Typeable
import GHC.Exts (Constraint)
@gbaz
gbaz / Generic.purs
Last active February 6, 2016 06:06
Generics in purescript (updated to version 7)
module Generic where
import Prelude
import Data.Maybe
import Data.Traversable
import Data.Array
data GenericSpine = SProd String (Array (Unit -> GenericSpine))
| SRecord (Array {recLabel :: String, recValue :: Unit -> GenericSpine})
| SNumber Number
@briancavalier
briancavalier / typescript-strongly-typed-variadic-1.md
Last active October 12, 2023 18:34
A technique for strongly-typed, heterogeneous variadic function types in Typescript

Simpler Variadic Function Types in TypeScript (part 1)

Variadic functions, such as the common zip function on arrays, are convenient and remove the need for lots of specific arity-function variants, e.g., zip2, zip3, zip4, etc. However, they can be difficult and tedious to type correctly in TypeScript when the return type depends on the parameter types, and the parameter types are heterogeneous.

Zip Example

Given a typical zip on arrays:

const a: number[] = [1, 2, 3]