Skip to content

Instantly share code, notes, and snippets.

@remydagostino
remydagostino / lambda.js
Last active August 29, 2015 14:05
Curried Functions With Guards
/*
Do you think this might be a useful way to do functional programming
in Javascript?
Gaurded, curried functions are created like:
Lambda(2).case(predicate, expression).case(predicate2, expression2);
The `2` specifies that the function accepts two arguments, it will
be partially applied if it is called with fewer (just like autocurry)
@remydagostino
remydagostino / jquery-fail-50.js
Created November 4, 2014 17:19
Fails 50% percent of requests
if (Math.random() > 0.5) {
return $.Deferred().reject({ id: sound.id }, '', {status: 400 });
}
@remydagostino
remydagostino / custom.html
Created February 2, 2015 22:24
Custom Elm Reactor Template
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Main</title>
<style>
html, head, body { padding:0; margin:0; }
</style>
</head>
<body>
@remydagostino
remydagostino / flip-files.el
Last active August 29, 2015 14:23
Flip between js, tmpl and css files in emacs
(defun open-if-exists (filename)
(when (file-exists-p filename) (set-buffer (find-file filename)) filename))
(defun get-flipped-ext (extension)
(cond ((string= extension "js") "tmpl")
((string= extension "tmpl") "css")
((string= extension "css") "js")
(t nil)))
(defun try-file-flip (base extension tries)
@remydagostino
remydagostino / food.md
Last active December 8, 2015 18:18
Vegan Berlin

These are my favorite vegan places in Berlin.

I've mostly avoided raw food because I don't usually like it, but if you're interested you'll probably find plenty in Berlin.

There's a big bias toward places that are near where I live, but there are many, many more places. You should use this map to find them.

Vegan berlin map

The list

@remydagostino
remydagostino / typeclasses.hs
Last active February 21, 2016 17:56
Getting the hang of haskell typeclasses
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module Main where
import Data.Monoid (Monoid, mempty, mappend, mconcat)
------------------------------
-- Part 1: Make a silly monoid instance for Int
@remydagostino
remydagostino / personal-pronouns.md
Last active February 15, 2016 22:32
German Pronoun practice
| Ich  | Du    | Er   | Sie  | Es   | Wir   | Ihr  | Sie

----|------|-------|------|------|------|-------|------|------ | gebe | gibst | gibt | gibt | gibt | geben | gibt | geben | mir | dir | ihm | ihr | ihm | uns | euch | ihnen | es | es | ihn | sie | es | es | es | es für | mich | dich | ihn | sie | es | uns | euch | ihnen

  • Ich gebe mir es für mich
  • Du gibst dir es für dich
  • Er gibt ihm ihn für ihn
@remydagostino
remydagostino / future.js
Created June 27, 2016 14:54
Minimal continuation passing construct
function thenable(action) {
var self = {
fork: function(succ, err) {
action(succ || function() {}, err || function() {});
},
then: function(fn) {
return thenable(function(resolve, reject) {
self.fork(
function(data) {
var step = fn(data);
@remydagostino
remydagostino / roman-simple.hs
Last active August 12, 2016 22:50
Calculate the roman numeral string for a number
module RomanNumerals.Simple (integerToRomanString) where
import Data.List (find)
import Data.Maybe (maybe)
integerToRomanString :: Integer -> Maybe String
integerToRomanString v =
let
sortedVals :: [(String, Integer)]
sortedVals =
@remydagostino
remydagostino / promise-example.js
Created November 17, 2017 16:58
Learning exercise for promises (advanced)
// Here we try to use first principles to hack together a very scrappy version
// of a javascript Promise which doesn't implement the A+ spec.
// This is a learning exercise and there are many edge-cases for which this code
// does not handle (such as attaching several callbacks to one promise).
// A good challenge for your understanding might be to modify the code so that
// it could allow several callbacks to be attached to a single promise.
// An broken example is shown at the bottom of the file.