Skip to content

Instantly share code, notes, and snippets.

Noam Lewis sinelaw

Block or report user

Report or block sinelaw

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sinelaw
sinelaw / copy.py
Last active Jul 2, 2019
Parallel copy of a single file
View copy.py
import threading
import os
import sys
BLOCK_SIZE = 1024*1024
THREADS = 16
def write_range(source, target, start, amount, block_size):
with open(source, 'r') as source_file:
with open(target, 'r+') as target_file:
View git-branch-diff
#!/bin/bash
set -eu
BRANCH_A="$1"
shift
BRANCH_B="$1"
shift
PATHS="$@"
BRANCH_A_COMMITS=$(mktemp)
ONLY_IN_BRANCH_A=$(mktemp)
BRANCH_B_COMMITS=$(mktemp)
@sinelaw
sinelaw / atomic.c
Created Aug 17, 2017
testing <stdatomic.h> on Intel cross-cacheline
View atomic.c
#include <stdint.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdatomic.h>
#define CACHELINE__BYTECOUNT (64)
struct Data {
uint8_t bytes[CACHELINE__BYTECOUNT - 4];
@sinelaw
sinelaw / git-unmerged-commits
Last active Jun 2, 2016
Given branch/ref (e.g. my_branch) and target (e.g. origin/master), lists commits in branch that have no "equivalent" ones in target (by author, date and message)
View git-unmerged-commits
#!/bin/bash
set -eu
# Similar to git branch --merged but looks at commit author, date and
# subject, instead of hash.
#
# Given branch/ref (e.g. my_branch) and target (e.g. origin/master),
# lists commits in branch that have no "equivalent" ones in target (by
# author, date and message).
@sinelaw
sinelaw / binary.hs
Created Feb 3, 2016
Binary encode/decode of Fixed
View binary.hs
-- run it like:
-- stack ghc --package criterion -- binary.hs -Wall -O2 && ./binary
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE BangPatterns #-}
module Main where
import Data.ByteString.Lazy (ByteString)
import Data.Binary
import Data.Fixed
View shake-util-infernu.js
/*jsl:option explicit*/
"use strict";
// /////////////////////////////////////////////////////////////////////
// // JQUERY EXTENSIONS
/* Removed this part.. */
/////////////////////////////////////////////////////////////////////
// STRING FORMATTING
View Parser.hs
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}
-- |
module Main where
import Control.Applicative (Alternative(..), (<|>))
import Data.List (foldl', intercalate)
import Data.Monoid ((<>))
@sinelaw
sinelaw / optional-args.js
Last active Sep 9, 2015
optional args using polymorphic records + record field constraints
View optional-args.js
// foo :: { 0: Num, 1: Maybe Num } -> Num
function foo(a, opt_b) {
var b = opt_b == undefined ? 3 : opt_b;
return a + b;
}
// foo here inferred to have this type:
// RowFields r Maybe => { 0: Num | r } -> b
foo(3); // translated to: foo { 0 = 3 | .. }
@sinelaw
sinelaw / bla.hs
Created Sep 9, 2015
type case simulated using polymorphic sums
View bla.hs
foo :: +{ Num : Number, Str : String | r } -> Number
function foo(x) {
if (typeof x == Number) { .. x is a number here! ...; return 0 }
else if (typeof x == String) { .. a string here ..; return 1 }
else { .. }
}
\case x of
Num n -> ... ; 0
Str s -> ... ; 1
View *scratch*.el
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
You can’t perform that action at this time.