Skip to content

Instantly share code, notes, and snippets.

@rebx
rebx / build_clang.sh
Last active October 30, 2018 19:42
Building clang from source using ninja and ccmake
#!/bin/bash
# use the current date
curr_date=`date +%Y-%m-%d`
clang_home=~/github/llvm_${curr_date}
# exit on any error
set -e
mkdir ${clang_home}
@rebx
rebx / mock_stack.py
Created August 30, 2018 23:06
creating a mock stack in python
def mock_stack(func):
@mock.patch.object(FooObject, 'method')
@mock.patch('some.module')
@functools.wraps(func)
def wrapped_func(*args, **kwargs):
return func(*args, **kwargs)
return wrapped_func
@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 / syslog_with_year
Created September 26, 2013 00:28
grok syslogtimestamp + year pattern
# added year to SYSLOGTIMESTAMP
SYSLOGTIMESTAMPYEAR %{MONTH} %{MONTHDAY} %{YEAR} %{TIME}
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;
def self.initialize(opts)
opts.each do |k,v|
instance_variable_set("@#{k}",v)
eigenclass = class<<self; self; end
eigenclass.class_eval do
attr_accessor k
end
end
end
# -*- 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
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}
#
@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 / 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 \