Skip to content

Instantly share code, notes, and snippets.

View loreb's full-sized avatar

Lorenzo Beretta loreb

View GitHub Profile
@loreb
loreb / bug.1st
Created September 15, 2013 21:09
Captain's log, Star Date 91312.3 -- this github thing apparently has bug fixing facilities...
https://github.com/cjdelisle/cjdns/issues/341
1st time I've reported a bug here on github rather than using email or reportbug
-- that shows I should use github a little bit^W^Wlot more...
@loreb
loreb / suoneria
Created August 29, 2013 22:31
A little script for my mom's new cell -- explaining just didn't work :) "suoneria" is the italian word for "ringtone"
#! /bin/sh
# Original msgs edited or stripped (they were in italian);
# iirc knoppix localizes sell scripts, I don't care.
zdie() {
zenity --error --text="$*" --no-markup
exit 123
}
@loreb
loreb / ISAAC_readable.vim
Created March 13, 2013 16:34
Bob Jenkins' ISAAC implementation converted to Vimscript (http://www.burtleburtle.net/bob/rand/isaacafa.html). At least three orders of magnitude slower than the C version.
" http://www.burtleburtle.net/bob/c/readable.c
" ----------------------------------------------------------------------------
" readable.c: My random number generator, ISAAC.
" (c) Bob Jenkins, March 1996, Public Domain
" You may use this code in any way you wish, and it is free. No warrantee.
" * May 2008 -- made it not depend on standard.h
" ----------------------------------------------------------------------------
" /* a ub4 is an unsigned 4-byte quantity */
" typedef uint32_t ub4
@loreb
loreb / marsaglia.sh
Last active December 14, 2015 10:29
George Marsaglia's favorite PRNG in vimscript and POSIX shell - fast, good, easy to use, remarkably short for what it does. The shell version breaks under mksh, but I'm too lazy to fix it now^H^H^H^H fixed.
#! /bin/sh
# Marsaglia's favorite PRNG, see his 20/01/99 post on sci.stat.math at
# https://groups.google.com/forum/?fromgroups=#!topic/sci.crypt/yoaCpGWKEk0
# https://en.wikipedia.org/wiki/Random_number_generation#Computational_methods
# = API =
# marsaglia_seed [w] [z] / both non-zero
# marsaglia() returns a random uint32 in $RAND
# -- can't use $RANDOM, setting it means seeding the PRNG in bash/ksh/zsh
@loreb
loreb / djbRANDOM.vim
Created February 14, 2013 17:30
The vimscript translation of a small rng published by Daniel J. Bernstein.
" https://groups.google.com/forum/?hl=en&fromgroups=#!topic/sci.physics/SWhCr8SEVWw
" TLDR: a PRNG by Dan Bernstein ported to vimscript
" The generator shown below is faster than Marsaglia's on my Pentium-100.
" It passes the Diehard tests without trouble.
"
" Use RANDOM for one 32-bit random number. Do not use RANDOM twice in one
" line. You can put a 64-bit seed into random_in[2 and 3]. The effect of
" seed m is to jump ahead by 2^68 m in a single sequence of period 2^132.
" It's easy to determine the seed from the sequence, but not with the sort
@loreb
loreb / devurandom.vim
Created November 22, 2012 23:22
vim RNG (/dev/urandom)
" I like picking a random colorscheme, but I hate the way it's done in most vim scripts
" -- localtime(), system("echo $RANDOM"), etc etc.
" And I wanted to try this gist thing...
function! DevUrandom()
let rv = 0
" readline reads 4096 bytes at a time(think fread())
" and returns a *list* of lines.
" Don't only read one line because:
" - we read more anyway, and
" - a short line means 0 has 1/256 probability rather than 1/4G!