Skip to content

Instantly share code, notes, and snippets.

function f(x) { let y = 0; while (x > 1) { if (x % 2 == 0) x /= 2; else x = x * 3 +1; ++y; } return y; }
function g(a, b) { let t = 0; for(let i = a; i < b; ++i) { t+=f(i); } return t; }
function h() { let n = 0; for(;;) { print(g(n*10000, (n+1)*10000)); ++n; } }
h();
@jld
jld / gist:6302389
Created August 22, 2013 02:01
Note to self.
F/MOZ_Assert( 1109): Assertion failure: ((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))), at /home/jld/src/B2G/gecko/dom/ipc/TabChild.cpp:675
@jld
jld / gist:6373277
Created August 29, 2013 01:18
Go home, C++. You're drunk.
rustc: /usr/local/src/rust/src/llvm/include/llvm/Support/IntegersSubsetMapping.h:86: bool llvm::IntegersSubsetMapping<SuccessorClass, IntegersSubsetTy, IntTy>::isJoinable(llvm::IntegersSubsetMapping<SuccessorClass, IntegersSubsetTy, IntTy>::CaseItemIt&, llvm::IntegersSubsetMapping<SuccessorClass, IntegersSubsetTy, IntTy>::CaseItemIt&) [with SuccessorClass = llvm::MachineBasicBlock; IntegersSubsetTy = llvm::IntegersSubset; IntTy = llvm::IntItem; llvm::IntegersSubsetMapping<SuccessorClass, IntegersSubsetTy, IntTy>::CaseItemIt = std::_List_iterator<std::pair<llvm::IntegersSubsetMapping<llvm::MachineBasicBlock>::RangeEx, llvm::MachineBasicBlock*> >]: Assertion `!isIntersected(LItem, RItem) && "Intersected items with different successors!"' failed.
@jld
jld / gist:6395568
Created August 31, 2013 00:51
In which numbers are multiplied and divided.
> (define (usable? n) (or (zero? n) (let ((i (modulo n 223))) (and (or (< i 26) (and (>= i 32) (< i (+ 32 26)))) (usable? (quotient n 223))))))
> (time (let loop ((n 1)) (and (< n 100000000) (if (usable? (* n (expt 2 63))) n (loop (+ n 1))))))
(time (let loop ((n 1)) (and (< n 100000000) (if (usable? (* n (expt 2 63))) n (loop (+ n 1))))))
44377 ms real time
44359 ms cpu time (44339 user, 20 system)
58806 collections accounting for 2957 ms real time (2920 user, 0 system)
17930827840 bytes allocated
no minor faults
no major faults
23411452
@jld
jld / gist:6395576
Created August 31, 2013 00:53
In which OCaml's type system includes some rules not typically seen in theoretical presentations.
# fun b -> if b then `DjEKseMUFXem else `AAAAAAAAAAAA;;
Error: Variant tags `DjEKseMUFXem and `AAAAAAAAAAAA have the same hash value.
Change one of them.
@jld
jld / exidx-count.py
Last active December 22, 2015 12:18
import os, sys, struct, subprocess
READELF = os.getenv("READELF") or "readelf"
def main(argv):
filename = argv[1]
phdrs = subprocess.Popen([READELF, "-l", filename],
stdout = subprocess.PIPE, stderr = sys.stderr)
offset = None
fsize = None
for line in phdrs.stdout:
/*
* The instruction encodings.
*/
/* instruction classes */
#define BPF_CLASS(code) ((code) & 0x07)
#define BPF_LD 0x00
#define BPF_LDX 0x01
#define BPF_ST 0x02
#define BPF_STX 0x03
#define BPF_ALU 0x04
GITREPO=git://github.com/jld/b2g-manifest BRANCH=mac-keon ./config.sh keon
./build.sh out/target/product/keon/boot.img
@jld
jld / gist:7128603
Created October 23, 2013 23:24
This backport probably won't work.
# On branch seccomp-goldfish
# You are currently cherry-picking.
# (fix conflicts and run "git cherry-pick --continue")
# (use "git cherry-pick --abort" to cancel the cherry-pick operation)
#
# Changes to be committed:
#
# new file: Documentation/prctl/no_new_privs.txt
# new file: Documentation/prctl/seccomp_filter.txt
# new file: arch/arm/include/asm/syscall.h
@jld
jld / gist:7270024
Last active December 27, 2015 04:49
hamachi kernel rebuild notes
GITREPO=https://github.com/jld/b2g-manifest BRANCH=hamachi-kernel-maybe-broken ./config.sh hamachi
rm -rf out
./build.sh
adb pull /dev/mtd/mtd0 orig-boot.img
./flash.sh boot
# At this point, if the device stays in the Alcatel boot screen,
# it has an incompatible bootloader and this can't work.
# Unbrick the phone thusly:
fastboot flash boot orig-boot.img