Skip to content

Instantly share code, notes, and snippets.

rebx /
Last active October 30, 2018 19:42
Building clang from source using ninja and ccmake
# use the current date
curr_date=`date +%Y-%m-%d`
# exit on any error
set -e
mkdir ${clang_home}
rebx /
Created August 30, 2018 23:06
creating a mock stack in python
def mock_stack(func):
@mock.patch.object(FooObject, 'method')
def wrapped_func(*args, **kwargs):
return func(*args, **kwargs)
return wrapped_func
rebx / whichpy
Created April 10, 2014 05:52
whichpy -- a nifty script for finding where your python module is imported from
View whichpy
#!/usr/bin/env python
import sys
from os.path import basename, dirname
from re import compile as regxcomp
from re import match as regxmat
INIT_BNAME = regxcomp('')
def try_import(module_name):
rebx / syslog_with_year
Created September 26, 2013 00:28
grok syslogtimestamp + year pattern
View syslog_with_year
# added year to SYSLOGTIMESTAMP
SYSLOGBACKFILLYEAR %{SYSLOGTIMESTAMPYEAR:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{PROG:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}
#!/usr/bin/env perl -w
use strict;
use Data::Dumper qw(Dumper);
sub _right_split {
my ( $strstr, $delim, $ary ) = @_;
$ary ||= [];
return $ary unless $strstr;
my $rindex = rindex( $strstr, $delim ) or return $ary;
View class_from_hash.rb
def self.initialize(opts)
opts.each do |k,v|
eigenclass = class<<self; self; end
eigenclass.class_eval do
attr_accessor k
View which.rb
# -*- 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
rebx / ruby_idioms.rb
Created April 18, 2013 22:59
Some Ruby Idioms I have come across which are useful to me
View ruby_idioms.rb
# make a list into hash keys
list = %w{foo bar baz}
s ||= {}
list.each {|key| s[key.to_sym] = 1}
rebx /
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 /
Last active December 15, 2015 06:38
Quick unused subroutine finder using ack( + git
if [ -z "$dir" -a "${dir+oinothir}" = "oinothir" ]; then
ack -h --output='$1' '^\s*sub\s+(\w+)\b' $dir \
| sort -u \