This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Point2D { | |
x: number; | |
y: number; | |
} | |
interface Point3D extends Point2D { | |
z: number; | |
} | |
function f(pt: Point2D) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
import Data.List | |
import Data.Ord (comparing) | |
import Control.Applicative ((<|>)) | |
import Criterion.Main | |
import GHC.Generics (Generic) | |
import Control.DeepSeq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sillyhash(x): | |
return x % 16 | |
class BloomFilter: | |
SIZE = 32 | |
HASH_FNS = [hash, sillyhash] | |
def __init__(self): | |
self.n = BloomFilter.SIZE | |
self.bitset = [0]*self.n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data BKTree a = Node a [(Int, BKTree a)] deriving (Eq, Show) | |
lev :: Eq a => [a] -> [a] -> Int | |
lev [] b = length b | |
lev a [] = length a | |
lev a b = minimum [ lev (init a) b + 1 | |
, lev a (init b) + 1 | |
, lev (init a) (init b) + (if last a == last b then 0 else 1) | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstring> | |
#include <iostream> | |
#include <thread> | |
#include <future> | |
#include <queue> | |
std::mutex mqMutex; | |
std::queue<std::tuple<size_t, std::promise<void*>&>> mq; | |
void * alloc(size_t len) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// So I don't lose it | |
function boxCollide(a, b) { | |
if ((a.y+a.h <= b.y) || (a.y >= b.y+b.h)) return false; | |
if ((a.x+a.w <= b.x) || (a.x >= b.x+b.w)) return false; | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class dotdict(dict): | |
def __getattribute__(self, key): | |
if key in self: | |
return self[key] | |
return dict.__getattribute__(self, key) | |
d = dotdict(a=1, b=2) | |
print d.a, d.b | |
print d.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE LambdaCase #-} | |
import Control.Concurrent | |
import Control.Concurrent.Chan | |
import Control.Monad | |
import Network.Socket | |
import System.IO | |
data MainMessage = Accept Socket SockAddr | |
| MsgReceived String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Test.Hspec | |
import VM | |
($=) = shouldBe | |
main :: IO () | |
main = hspec $ do | |
describe "runVM" $ do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define (obj state msg) | |
(match msg | |
['init (cons state (curry obj state))] | |
['get-x (cons state (curry obj state))] | |
[(list 'set-x x) (cons x (curry obj x))] | |
['ping (cons "pong" (curry obj state))])) | |
(define-syntax-rule (send! obj msg) |