This file contains hidden or 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
#!/usr/bin/env python3 | |
# Michael J. Sullivan (http://www.msully.net/) | |
# Stupid little script to make gnome/unity media keys work when running | |
# weirdo window managers like xmonad and notion. | |
# Directions: | |
# With unity-settings-daemon running, run this script in the background. | |
# Tested on Ubuntu 15.04 using notion. |
This file contains hidden or 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
// This code is all kinds of illegal and tests whether other threads | |
// keep running while there is an outstanding vfork | |
#include <atomic> | |
#include <thread> | |
#include <iostream> | |
#include <unistd.h> | |
std::atomic<bool> child_running; | |
std::atomic<bool> child_signaled; |
This file contains hidden or 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
let time_execution func = | |
let start_time = Sys.time () in | |
let ret = func () in | |
let end_time = Sys.time () in | |
end_time -. start_time, ret | |
(* val time_execution : (unit -> 'a) -> float * 'a *) | |
let print_stuff () = Printf.printf "hello, world\n" | |
let compute_stuff () = 10 + 10 |
This file contains hidden or 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
// Copying variables into a tmp using __typeof__ is a common | |
// pattern in hacky gcc C macros, but it can backfire and | |
// allow the value to be evaluated twice! | |
// This is because __typeof__ will evaluate its argument if | |
// the value has a variably sized type! | |
// gcc added __auto_type to get around this problem in its stdatomic.h, but I'm | |
// not losing any sleep over this. | |
// See http://patchwork.ozlabs.org/patch/290802/ |
This file contains hidden or 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
// Make a copy of a value that the compiler doesn't know anything about. | |
#define launder_value(v) \ | |
({ \ | |
__typeof__(v) __v = v; \ | |
__asm__ __volatile__("" : "+r" (__v)::); \ | |
__v; \ | |
}) |
This file contains hidden or 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
import Control.Monad | |
type Var = Integer | |
type Subst = [(Var, Term)] | |
type State = (Subst, Integer) | |
type Program = State -> KList State | |
data Term = Atom String | Pair Term Term | Var Var deriving Show | |
-- Apply a substitution to the top level of a term |
This file contains hidden or 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
#!/bin/sh | |
# Run a command with a lock if it looks like it is a linker command: that is, | |
# if none of its arguments are -c. | |
# Then you can do a build where compilation is parallel but linking is serial | |
# by doing something like (for llvm/clang): | |
# make -j4 'CXX=lock-linking /tmp/llvm-build-lock clang++' | |
LOCKFILE="$1" |
This file contains hidden or 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
#!/bin/bash | |
# Terrible hack to run a build in parallel until it starts linking | |
# things and then switch to running it in serial to cut down on memory usage. | |
# This could be better and more robust in a *lot* of ways. | |
# I use this for building llvm/clang. | |
# The first argument gets passed to the initial make that runs until | |
# linking starts and should be -j4 or whatever. The rest of the | |
# arguments get passed to both makes. |
This file contains hidden or 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
// Out of thin air writes are really scary. | |
// Example adapted from http://dl.acm.org/citation.cfm?id=2618134 to | |
// work under http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/index.html | |
// Can wind up with an = &b, bn = &a! | |
int main() { | |
int *p1, *p2; | |
atomic_int a, an, b, bn; | |
a = &an; |
This file contains hidden or 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
(* Indexed list indexing in Agda *) | |
data IList {a} (A : Set a) : Nat → Set a where | |
Nil : IList A 0 | |
Cons : {n : Nat} -> A -> IList A n -> IList A (S n) | |
data Fin : Nat -> Set where | |
Z : {n : Nat} -> Fin (S n) | |
S : {n : Nat} -> Fin n -> Fin (S n) |