Skip to content

Instantly share code, notes, and snippets.

View whitequark's full-sized avatar
🐈‍⬛

Catherine whitequark

🐈‍⬛
View GitHub Profile
@whitequark
whitequark / diff-pci-configs.sh
Created September 4, 2011 23:00
A script to find differences in PCI configuration space on Linux
#!/bin/bash
set +e
if ! [ "`id -u`" == '0' ]; then
echo 'This script must be run as root'
exit
fi
mkdir -p diff-pci-configs-data
@whitequark
whitequark / ast_quirks.rb
Created September 7, 2011 21:17
Treetop AST quirks
require 'treetop'
Treetop.load 'ast_quirks.treetop'
parser = SimpleExpressionParser.new
ast = parser.parse %q{42}
p ast.to_code
@whitequark
whitequark / strace-4.6-v4l2-ioctls.patch
Created October 5, 2011 00:02
V4L2 ioctl support for strace
diff -urN strace-4.6.old/defs.h strace-4.6.new/defs.h
--- strace-4.6.old/defs.h 2011-03-15 20:19:09.000000000 +0300
+++ strace-4.6.new/defs.h 2011-10-05 01:06:42.000000000 +0400
@@ -594,6 +594,7 @@
extern int rtc_ioctl(struct tcb *, long, long);
extern int scsi_ioctl(struct tcb *, long, long);
extern int block_ioctl(struct tcb *, long, long);
+extern int v4l2_ioctl(struct tcb *, long, long);
#endif
@whitequark
whitequark / gist:2622705
Created May 6, 2012 14:48
a piece of modern art
(3995:lookup-switch 3523 [3307, 3307, 3307, 3337, 3337, 3337, 3337, 3337, 3491, 3491, 3491, 3491, 3491, 3491, 3491, 3523]
(ternary
(3560:===
(3558:bit-or
(3555:lshift
(3551:integer 46)
(3553:integer 16))
(3556:integer 14))
(3559:get-local 3))
(3564:integer 0)
@whitequark
whitequark / update-package.sh
Created May 12, 2012 17:14
Pure shell update package installer for Android
#!/bin/bash
set -e
UPDATE_PKG=$1
if [ "$UPDATE_PKG" == "" ]; then
echo "Usage: $0 <update package>"
echo
exit 1
@whitequark
whitequark / gist:4705506
Last active December 12, 2015 03:18
NoSQL is for those who can't learn SQL.
# Convert raw stats into hourly stats.
def self.squash!(before=Time.now)
transaction do
range = where(%{
date_trunc('hour', collected_at) < date_trunc('hour', timestamp ?)
}, before)
from_id, to_id = range.minimum(:id), range.maximum('id')
return nil if [from_id, to_id].none?
@whitequark
whitequark / result.txt
Last active December 20, 2015 03:09
emacs compatible unicode (c) erikh
$ ruby x.rb <<<"проверка"
"\M-P\M-?\M-Q\M-\C-@\M-P\M->\M-P\M-2\M-P\M-5\M-Q\M-\C-@\M-P\M-:\M-P\M-0"
$ ruby -e 'puts "\M-P\M-?\M-Q\M-\C-@\M-P\M->\M-P\M-2\M-P\M-5\M-Q\M-\C-@\M-P\M-:\M-P\M-0"'
проверка
@whitequark
whitequark / swap_escape.ml
Last active December 21, 2015 01:28
Beautiful tiny FSM encoded with pattern matching
(* OCaml regular expressions are unusual in that they require
parentheses and pipe symbol to be escaped to *gain* special
meaning. swap_escape converts from (and, incidentally, to)
the usual format. *)
let swap_escape input =
let swap_chr (esc, str) chr =
match esc, chr with
(* Go to escape mode. *)
| false, '\\'
-> true, str
@whitequark
whitequark / README.md
Created December 12, 2013 06:54
A simple symbolizer for caml-inspect.

Caml-inspect symbolizer

Symbolizes closure blocks. Works only on native executables.

Build

ocamlfind ocamlopt -syntax camlp4o -package lwt -package lwt.syntax -package lwt.unix str.cmxa -linkpkg symbolizer.ml -o symbolizer
ocamlfind ocamlopt -package inspect -linkpkg foo.ml -o foo

Use

17:08 < whitequark> I once had a home server based on a pentium iii motherboard with makeshift passive cooler
17:09 < whitequark> usually it was around 50°C, but once a night a cron job kicked in and it started gzipping stuff, bringing it up to 110°C
17:09 < whitequark> first time I discovered that, I literally burned myself
17:09 < whitequark> that thing had uptime of about 1.5 years when I finally scrapped it
17:10 < whitequark> oh and that job took about two hours each night... this is quite a testament to reliability.