Skip to content

Instantly share code, notes, and snippets.

@jackfarrington
jackfarrington / pascals_triangle.clj
Created August 4, 2016 23:59
Pascal's triangle (Clojure)
#(reduce (fn [a _] (concat [1] (map + a (rest a)) [1])) [1] (range 1 %))
@jackfarrington
jackfarrington / chain.js
Last active December 28, 2017 03:52
NodeJS pipelining module
class Chain {
constructor() {
this.chain = []
}
use(handler) {
this.chain.push(handler)
return this
}
@jackfarrington
jackfarrington / capacity.js
Last active March 29, 2016 22:54
Utilities to convert between various byte capacities
/**
* Represents a capacity in bytes.
* @class
* @param {Number} sizeInBytes - The size in bytes.
* @prop {Number} oneKB - One kilobyte.
* @prop {Number} oneMB - One megabyte.
* @prop {Number} oneGB - One gigabyte.
* @prop {Number} oneTB - One terabyte.
*/
function Capacity(sizeInBytes) {
@jackfarrington
jackfarrington / ReverseComparer.cs
Created September 11, 2015 18:37
C# Generic Reverse Comparer (IComparer<T>)
using System.Collections.Generic;
namespace Gist
{
public sealed class ReverseComparer<T> : IComparer<T>
{
public static readonly ReverseComparer<T> Default = new ReverseComparer<T>(Comparer<T>.Default);
public static ReverseComparer<T> Reverse(IComparer<T> comparer)
{
@jackfarrington
jackfarrington / scala-by-example-exercise-6.0.3.scala
Created August 15, 2015 04:58
Scala By Example exercise 6.0.3
/*
* The trait Nat is provided by the text.
*/
trait Nat {
def isZero: Boolean
def predecessor: Nat
def successor: Nat
def +(that: Nat): Nat
def -(that: Nat): Nat
package main
import (
"fmt"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
Fetch(url string) (body string, urls []string, err error)
package main
import "fmt"
import "golang.org/x/tour/tree"
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
var walk func(t *tree.Tree)
walk = func(t * tree.Tree) {