Skip to content

Instantly share code, notes, and snippets.

@ekmett
ekmett / Epsilon.hs
Created December 25, 2011 05:32
Hilbert's Epsilon
{-# LANGUAGE NPlusKPatterns, RankNTypes #-}
-- ransacking infinite structures quickly without side-effects
import Data.Maybe (fromMaybe)
import Control.Applicative
import Data.Map (Map)
import qualified Data.Map as Map
import Control.Monad
import Control.Monad.Trans.Class
@jboner
jboner / latency.txt
Last active November 17, 2024 11:32
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@KartikTalwar
KartikTalwar / Documentation.md
Last active September 24, 2024 20:03
Rsync over SSH - (40MB/s over 1GB NICs)

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
@robertklep
robertklep / gist:5124355
Created March 9, 2013 14:41
X11 keylogger
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <netdb.h>
#include <string.h>
#include <netinet/in.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
@panzi
panzi / portable_endian.h
Last active August 9, 2024 13:12
This provides the endian conversion functions form endian.h on Windows, Linux, *BSD, Mac OS X, and QNX. You still need to use -std=gnu99 instead of -std=c99 for gcc. The functions might actually be macros. Functions: htobe16, htole16, be16toh, le16toh, htobe32, htole32, be32toh, le32toh, htobe64, htole64, be64toh, le64toh. License: I hereby put …
// "License": Public Domain
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
// an example on how to get the endian conversion functions on different platforms.
#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
@pervognsen
pervognsen / glgen.py
Last active February 17, 2017 09:34
gl3w-style loader generator for SDL2
# Usage: python glgen.py SDL_opengl.h (or SDL_opengl_glext.h if you're on the 2.0.4 development branch)
import sys
import re
ext_file = file(sys.argv[1])
functions = []
for match in re.finditer(r" APIENTRY (gl.*?) \(", ext_file.read()):
functions.append((match.group(1), "PFN%sPROC" % (match.group(1).upper(),)))
@mbrcknl
mbrcknl / after.agda
Last active September 5, 2017 11:29
Code from BFPG talk about dependent types in Agda
-- Matthew Brecknell @mbrcknl
-- BFPG.org, March-April 2015
-- With thanks to Conor McBride (@pigworker) for his lecture series:
-- https://www.youtube.com/playlist?list=PL44F162A8B8CB7C87
-- from which I learned most of what I know about Agda, and
-- from which I stole several ideas for this talk.
open import Agda.Primitive using (_⊔_)
@david-christiansen
david-christiansen / NatInd.idr
Last active October 26, 2017 22:21
Simple proof automation with reflected elaboration
module NatInd
import Language.Reflection.Elab
import Language.Reflection.Utils
%default total
trivial : Elab ()
trivial = do compute
g <- snd <$> getGoal
open eq
inductive I (F : Type₁ → Prop) : Type₁ :=
mk : I F
axiom InjI : ∀ {x y}, I x = I y → x = y
definition P (x : Type₁) : Prop := ∃ a, I a = x ∧ (a x → false).
definition p := I P
@wolfiestyle
wolfiestyle / sphtrace.hs
Last active February 22, 2016 00:31
raytracer in haskell
{-# LANGUAGE BangPatterns #-}
import Control.Applicative
import System.IO
import Data.Maybe
import Data.Complex
import Data.Word
import qualified Data.ByteString as B
data Vec a = Vec { vecx, vecy, vecz :: !a }