Skip to content

Instantly share code, notes, and snippets.

class A {
def f1(xs: Seq[Int]) = xs match { case xs: Seq[_] => xs } // infers Seq[Any]
def f2(xs: Seq[Int]) = xs match { case xs: List[_] => xs } // infers List[Any]
def f3(xs: List[Int]) = xs match { case xs: Seq[_] => xs } // infers List[Int]
def f4(xs: List[Int]) = xs match { case xs: List[_] => xs } // infers List[Any]
}
@liuliu
liuliu / k-mean on histogram.c
Last active September 26, 2016 06:05
k-mean for layer
gsl_rng_env_setup();
gsl_rng* rng = gsl_rng_alloc(gsl_rng_default);
sqlite3* db = 0;
int h[0x10000];
int kc[0x100];
float kmean[0x100];
uint16_t tbl[0x10000];
int i;
for (i = 0; i < 0x10000; i++)
tbl[i] = i;
@tonymorris
tonymorris / List.hs
Created August 3, 2014 04:44
A right-fold is of the same structure as []
{-# LANGUAGE RankNTypes #-}
import Data.Monoid
data List a =
List (forall b. (a -> b -> b) -> b -> b)
instance Eq a => Eq (List a) where
x == y =
iso ~> x == iso ~> y
@john2x
john2x / 00_destructuring.md
Last active September 24, 2025 00:52
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

class @BaseCtrl
@register: (app, name) ->
name ?= @name || @toString().match(/function\s*(.*?)\(/)?[1]
app.controller name, this
@inject: (annotations...) ->
ANNOTATION_REG = /^(\S+)(\s+as\s+(\w+))?$/
@annotations = _.map annotations, (annotation) ->
@kafecho
kafecho / Reader.scala
Created May 8, 2014 08:20
Example of using the Reader Monad.
package org.kafecho.learning.monad
import java.util.UUID
/** My attempt at implementing the Reader Monad concept.
* The Reader Monad encapsulates a computation which:
* - requires a dependency of type D
* - produces values of type A.
*/
case class Reader[D, A](computation: D => A) {
@hallettj
hallettj / Cat.lidr
Last active April 2, 2018 15:05
description of category laws in Idris
# Category Theory proofs in Idris
Idris is a language with dependent types, and is similar to Agda.
What distinguishes Idris is that it is intended to be a general-purpose language first,
and a theorem prover second.
To that end it supports optional totality checking
and features to support writing DSLs:
type classes,
do notation,
monad comprehensions (i.e., a more general form of list comprehension),
@nathenharvey
nathenharvey / vhosts.rb
Last active May 31, 2016 16:41
vhosts recipe for one-day Introduction to Chef workshop
data_bag("vhosts").each do |site|
site_data = data_bag_item("vhosts", site)
site_name = site_data["id"]
document_root = "/srv/apache/#{site_name}"
template "/etc/httpd/conf.d/#{site_name}.conf" do
source "custom-vhosts.erb"
mode "0644"
variables(
:document_root => document_root,
@davidcelis
davidcelis / install_docker.sh
Created February 20, 2014 18:53
Fresh install of Docker on OSX.
#!/usr/bin/env bash
brew install docker boot2docker
boot2docker init
boot2docker up
export DOCKER_HOST="tcp://localhost:4243"
@mrb
mrb / typecher.ml
Created February 20, 2014 01:21
Simple Typed Lambda Calculus Typechecking Function in OCaml
let rec typeof ctx t =
match t with
TmVar(fi,i,_) -> getTypeFromContext fi ctx i
| TmAbs(fi,x,tyT1,t2) ->
let ctx' = addbinding ctx x (VarBind(tyT1)) in
let tyT2 = typeof ctx' t2 in
TyArr(tyT1, tyT2)
| TmApp(fi,t1,t2) ->
let tyT1 = typeof ctx t1 in
let tyT2 = typeof ctx t2 in