Skip to content

Instantly share code, notes, and snippets.

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
#!/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;
@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}
@rebx
rebx / whichpy
Created April 10, 2014 05:52
whichpy -- a nifty script for finding where your python module is imported from
#!/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('__init__.py')
def try_import(module_name):
@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 / 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}