Skip to content

Instantly share code, notes, and snippets.

View vasi's full-sized avatar

Dave Vasilevsky vasi

  • Stripe
  • Montreal
View GitHub Profile
#!/usr/bin/env rvm 1.9.3 do ruby
require 'pp'
def hamming(i)
dist = 0
v = i
while v != 0
dist += 1 if (v & 1 != 0)
v >>= 1
end
@vasi
vasi / gist:5365782
Created April 11, 2013 18:13
Sample contents of GDELT
$ ./httpfs2-mt http://eventdata.psu.edu/data.dir/GDELT.1979-2012.reduced.zip mnt
file name: GDELT.1979-2012.reduced.zip
host name: eventdata.psu.edu
port number: 80
protocol: http
request path: /data.dir/GDELT.1979-2012.reduced.zip
auth data: (null)
./httpfs2-mt: HEAD: invalid time
Wed, 03 Apr 2013 05:14:40 GMT
file size: 667748833
@vasi
vasi / gist:5543124
Created May 8, 2013 19:51
libguestfs appliance weirdness
vasi@inchon:~/Downloads$ LIBGUESTFS_PATH=$PWD/rwmj-appliance guestfish -a ubuntu-10.04.4-alternate-amd64.iso
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
Type: 'help' for help on commands
'man' to read the manual
'quit' to quit the shell
><fs> run
@vasi
vasi / gist:5691785
Created June 1, 2013 21:27
UTF16-LE to UTF-8 conversion
#include <stdio.h>
#define BOM 0xFEFF
#define SUR1 0xD800
#define SUR2 0xDC00
int read16(void) {
int a = getc(stdin), b = getc(stdin);
if (a == EOF || b == EOF)
return EOF;
@vasi
vasi / gist:5691787
Created June 1, 2013 21:27
UTF-16LE to UTF-8 conversion
#include <stdio.h>
#define BOM 0xFEFF
#define SUR1 0xD800
#define SUR2 0xDC00
int read16(void) {
int a = getc(stdin), b = getc(stdin);
if (a == EOF || b == EOF)
return EOF;
@vasi
vasi / output of patch
Created June 4, 2013 00:29
Patch from "svn diff"
Index: usr.sbin/ndiscvt/inf-token.l
===================================================================
--- usr.sbin/ndiscvt/inf-token.l (revision 251347)
+++ usr.sbin/ndiscvt/inf-token.l (working copy)
@@ -55,6 +55,9 @@
lineno++;
}
+static void in_buf(char *buf, yy_size_t *result, int max_size);
+#define YY_INPUT(buf, result, max_size) (in_buf(buf, &result, max_size))
@vasi
vasi / gist:6695284
Created September 25, 2013 04:53
Git subset
[Olio:~/Desktop/mefi] vasi$ cd ..; rm -r mefi; clear
override r--r--r-- vasi/staff for mefi/.git/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99? ^C
@vasi
vasi / gist:6695286
Created September 25, 2013 04:53
Git subset
[Olio:~/Desktop] vasi$ git init mefi
Initialized empty Git repository in /Users/vasi/Desktop/mefi/.git/
[Olio:~/Desktop] vasi$ cd mefi
[Olio:~/Desktop/mefi] vasi$ # Create some files and commit them
[Olio:~/Desktop/mefi] vasi$ for i in foo bar iggy blah; do echo $i > $i; done
[Olio:~/Desktop/mefi] vasi$ ls
bar blah foo iggy
[Olio:~/Desktop/mefi] vasi$ cat iggy
iggy
[Olio:~/Desktop/mefi] vasi$ git add *
@vasi
vasi / LfsOsx
Created February 14, 2014 01:37
LFS on OS X from 2005 or so
= LinuxFromScratch using Mac OS X =
Linux From Scratch is a fun way to learn about Linux, but it expects you to already have Linux running. [http://trac.cross-lfs.org Cross-compiling] is already supported but OS X is a little weird--so here are some hints for bootstrapping LFS from OS X. I've only tried this on 32-bit PPC, I have no idea how well or badly it would work on G5 or Intel chips.
Generally, you can follow the [http://cross-lfs.org/view/1.0.0rc4/ppc/ Cross-LFS book], I only refer to areas where changes are needed.
== Chapter 2 ==
=== Partitioning ===
To perform the partitioning, you'll probably want to use a Linux rescue CD. Gentoo's PPC CD has a version of parted that can even resize existing HFS+ partitions non-destructively, I think Debian's does too. Using Disk Utility or a commercial tool like iPartition is an option, but I'm not certain they can create the special partition types Apple_Bootstrap and Apple_UNIX_SVR2.
@vasi
vasi / tarpv
Created June 2, 2014 01:23
Create a tarball, using a progress bar
#!/usr/bin/env bash
# First arg is always option
arg1="$1"
shift
# Find first non-option
for i in "$@"; do
if [[ -z "$dir" && "$i" != -* ]]; then
dir="$i"