Skip to content

Instantly share code, notes, and snippets.

int32_t f(int32_t x) {
return x + 0x7fffffff;
}
@ivant
ivant / WordStats.hs
Last active December 31, 2015 14:48
Build a sorted word frequency list from a file, trimmed to a given quantile.
-- Build a sorted word frequency list from a file, trimmed to a given quantile.
--
-- Usage: WordStats <book.txt> <quantile>
--
-- `quantile` is a number between 0 and 1.
--
-- Example:
-- ./WordStats "Don Quijote.txt" 0.85 > "Don Quijote.words.85"
import Control.Applicative
@ivant
ivant / Yandex Helper.backtrace
Created October 2, 2012 00:20
Yandex 19.0.1084.5402 locked up on Firefox data import
(gdb) info threads
6 0x987ff0ee in __workq_kernreturn ()
5 "import_thread" 0x987ff9ae in kevent ()
4 "SamplerThread" 0x987fc80e in semaphore_wait_trap ()
3 "Chrome_ChildIOThread" 0x987ff9ae in kevent ()
2 "com.apple.libdispatch-manager" 0x987ff9ae in kevent ()
* 1 "CrUtilityMain" 0x987fe8e2 in __psynch_cvwait ()
(gdb) thread apply all bt
Thread 6 (process 89623):
@ivant
ivant / cxx-infinite-loop.cc
Created March 12, 2012 22:13
C++ compiler infinite loop
template <class T>
struct Loop {
Loop<T *> operator->();
};
int main() {
Loop<int> i, j = i->hooray;
}
@ivant
ivant / gist:1454460
Created December 10, 2011 03:18
C puzzle (sizeof)
/* What does this program print and why? */
#include <stdio.h>
int main(void) {
int n = sizeof(0)["abcdefghij"];
printf("%d\n", n);
return 0;
}
@ivant
ivant / Makefile
Created July 10, 2011 05:12
wc using Data.Enumerator
.PHONY: all clean test
DATA_REPEATS?=1000
DATA_FILE?=/usr/share/dict/words
GHC_OPTS?=-fspec-constr-count=64 -funfolding-use-threshold=64
all: wce wci
clean:
rm -f wce wci *.hi *.o