Skip to content

Instantly share code, notes, and snippets.

mkset :: Ord a => [a] -> M.Map a ()
mkset = M.fromList . map (\x->(x,()))
gc :: Ord k => M.Map k v -> [k] -> (v -> [k]) -> M.Map k v
gc pvals proots ptrs = M.unions $ follow pvals proots
where
follow _ [] = []
follow vals roots =
let rootset = mkset roots
{-
foldc - "fold centre"
Perfoms a fold of a list, given an associative operation, in a binary-tree pattern.
For example, folding the numbers 1 through 10 with the operation * looks like this:
foldl1: (((((((((1 * 2) * 3) * 4) * 5) * 6) * 7) * 8) * 9) * 10)
foldr1: (1 * (2 * (3 * (4 * (5 * (6 * (7 * (8 * (9 * 10)))))))))
@stedolan
stedolan / compizswitch
Created July 10, 2011 10:24
Switch Compiz on/off
#!/bin/bash
dir="$1"
if pidof compiz > /dev/null; then
current=on
else
current=off
fi
if [ -z "$dir" ]; then
@stedolan
stedolan / coreinfo
Created July 18, 2011 16:09
Prints number of cores, CPU topology and cache topology/size on Linux machines
#!/bin/bash
unshared () {
grep '^[0-9]\+$' "$1" > /dev/null
}
for cpu in $(ls -d /sys/devices/system/cpu/cpu[0-9]* | sort -t u -k 3 -n); do
echo "${cpu##*/}: [Package #$(cat $cpu/topology/physical_package_id), Core #$(cat $cpu/topology/core_id)]"
if ! unshared $cpu/topology/core_siblings_list; then
echo " same package as $(cat $cpu/topology/core_siblings_list)"
@stedolan
stedolan / cachebench.c
Created October 2, 2011 23:37
Cache benchmarks
#include <time.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
static __inline__ unsigned long long rdtsc(void)
{
unsigned hi, lo;
@stedolan
stedolan / corebench.c
Created October 2, 2011 23:39
Inter-core communication latencies
#define _GNU_SOURCE
#include <pthread.h>
#include <sys/types.h>
#include <stdio.h>
#include <sched.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
struct {
@stedolan
stedolan / .emacs
Created October 3, 2012 12:04
Emacs
(require 'uniquify)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(dabbrev-case-fold-search nil)
'(doc-view-resolution 100)
'(ecb-options-version "2.32")
'(indent-tabs-mode nil)
@stedolan
stedolan / .emacs
Created October 3, 2012 12:13
Emacs
(require 'uniquify)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(dabbrev-case-fold-search nil)
'(doc-view-resolution 100)
'(ecb-options-version "2.32")
'(indent-tabs-mode nil)
@stedolan
stedolan / gist:3940705
Created October 23, 2012 18:44
parser.y forward declaration hack
diff --git a/parser.y b/parser.y
index 0effe07..ed05534 100644
--- a/parser.y
+++ b/parser.y
@@ -2,6 +2,8 @@
#include <stdio.h>
#include <string.h>
#include "compile.h"
+
+struct lexer_param;
#!/bin/bash
die () {
echo "$0: $@" > /dev/stderr
exit 1
}
usage () {
echo "Usage: $0 <branchname> <directory>" > /dev/stderr
exit 1