Skip to content

Instantly share code, notes, and snippets.

@rebx
rebx / gist:1244197
Created September 27, 2011 02:52
rvm fail?
> rvm use 1.9.2-p290@mall --create
Database file /home/rebx/.rvm/user/db does not exist.
> __rvm_db
bash: /db: No such file or directory
> echo $rvm_path
@rebx
rebx / gist:1250106
Created September 29, 2011 06:25
tshark'ing mysql
live:
tshark -i eth0 -aduration:60 -d tcp.port==3306,mysql -T fields -e mysql.query 'port 3306'
capture:
tcpdump -i eth0 port 3306 -s 1500 -w tcpdump.out
tshark -r tcpdump.out -d tcp.port==3306,mysql -T fields -e mysql.query > query_log.out
@rebx
rebx / gist:1276809
Created October 10, 2011 22:52
c has a size for void?
$ cat voidsize.c
#include <stdio.h>
int main(void) {
printf("void size: %d\n", sizeof(void));
return 0;
}
$ make voidsize
cc voidsize.c -o voidsize
voidsize.c: In function ‘main’:
@rebx
rebx / gist:1362873
Created November 13, 2011 22:59
rvm remove [ruby pkg] kills the $rvm_usr_path set?
$ echo $rvm_usr_path
/some/path/to/rvm/usr
$ rvm remove 1.9.3
Removing /some/path/to/rvm/src/ruby-1.9.3-p0...
Removing /some/path/to/rvm/rubies/ruby-1.9.3-p0...
Removing ruby-1.9.3-p0 aliases...
Removing ruby-1.9.3-p0 wrappers...
Removing ruby-1.9.3-p0 environments...
@rebx
rebx / whichpm
Created March 14, 2012 21:43
Scripts for finding module locations
#!/usr/bin/env perl -w
# rebx
use strict;
my $mod = shift(@ARGV);
my @customperl = qw(/path/to/perl);
push (@INC, @customperl);
(!defined($mod)) && exit 1;
unless ( eval "require $mod;1") {
@rebx
rebx / merge_sort.py
Created June 25, 2012 00:52
python merge sort
def merge_sort(list_struct=[]):
"""
merge_sort
as if there's not enough merge sorts in python out there
"""
list_len = len(list_struct)
if list_len <= 1:
return list_struct
mid = list_len / 2
@rebx
rebx / find_unused_subs.sh
Last active December 15, 2015 06:38
Quick unused subroutine finder using ack(http://betterthangrep.com) + git
#!/bin/bash
dir=$1
if [ -z "$dir" -a "${dir+oinothir}" = "oinothir" ]; then
dir=$PWD
fi
ack -h --output='$1' '^\s*sub\s+(\w+)\b' $dir \
| sort -u \
@rebx
rebx / perl_idioms.pl
Last active December 16, 2015 09:18
perl idioms I commonly use
# size of array
sub foo { return qw(foo bar baz);}
$size = () = foo();
# or just use int. scalar works as well, but int is more "intuitive" than scalar to me
$size = int (@array);
# interleave array
sub interleave {
my %interleaved;
@interleaved{ @{$_[0]} } = @{$_[1]};
@rebx
rebx / ruby_idioms.rb
Created April 18, 2013 22:59
Some Ruby Idioms I have come across which are useful to me
# make a list into hash keys
list = %w{foo bar baz}
s ||= {}
list.each {|key| s[key.to_sym] = 1}
#
# -*- encoding: utf-8 -*-
#
# taken from perl
# my bad perl habits aren't so easy to stomp out...tsk, tsk...
#
module File::Which
#
# Returns the full path to the executable