Skip to content

Instantly share code, notes, and snippets.

View rbriank's full-sized avatar

Brian Kierstead rbriank

  • Kierstead Consulting, Inc.
  • Hamilton, ON
View GitHub Profile
class Fixnum
def minutes
self * 60
end
def days
self * 60 * 60 * 24
end
end
@rbriank
rbriank / gist:3078571
Created July 9, 2012 20:03
monitor a website and do something if it's down
alias monitor='while true; do if [ "$(wget -T 10 -t 1 https://some.server.com -O /dev/null -o /dev/stdout | grep 200.OK)" = "" ]; then "$(..restart...)"; echo "restarted at `date`"; fi; echo "last checked at `date`"; sleep 1800; done'
@rbriank
rbriank / gist:3078091
Created July 9, 2012 18:36
view partial file with colorized word
# usage:
# sedr 100 120 some/file/with.txt hot
# will return lines 100 to 120 of some/file/with.txt with 'hot' in green
#
alias sedr='ruby -e "start=ARGV.shift;finish=ARGV.shift;filename=ARGV.shift;word=ARGV.shift;cmd=%Q(sed -n #{start},#{finish}p #{filename});cmd << %Q( | sed ''/#{word}/s//`printf "\033[32m#{word}\033[0m"`/'') unless word.nil?; puts cmd; puts %x[#{cmd}];"'
@rbriank
rbriank / svn_merge_helper.sh
Created June 7, 2012 16:59
bash alias for easier svn merging
alias s:merge='ruby -e "branch=ARGV.shift;ARGV.each{|r| cmd=%Q(svn merge https://subversion/svn/repo/#{branch} -c #{r}); puts cmd}"'
alias s:merge:live='ruby -e "branch=ARGV.shift;ARGV.each{|r| cmd=%Q(svn merge https://subversion/svn/repo/#{branch} -c #{r}); system(cmd)}"'
alias s:merge:dry='ruby -e "branch=ARGV.shift;ARGV.each{|r| cmd=%Q(svn merge https://subversion.looksmart.com/svn/plp/amp/#{branch} ->
# mergr branches/branch 123 124 125 ...
Gem::Specification.new do |s|
s.name = 'multi_methods'
s.version = '1.0.3'
s.platform = Gem::Platform::RUBY
s.author = 'Brian Kierstead'
s.email = 'briankierstead@gmail.com'
s.summary = 'General dispatch for ruby'
s.description = <<EOS
Supports general dispatch using clojure style multi-methods. This can be used
for anything from basic function overloading to a function dispatch based on arbitrary complexity. Based on the work of Andrew Garson (https://github.com/andrewGarson/ruby-multimethods) and Paul Santa Clara (https://github.com/psantacl/ruby-multimethods)
@rbriank
rbriank / bash_profile.sh
Created May 2, 2012 17:48
Script to run ssh-agent, and ssh-add on login
# Add to ~/.bash_profile
# Start/Reuse SSH Agent - restart or re-use an existing agent
SSH_AGENT_CACHE=/tmp/ssh_agent_eval_`whoami`
if [ -s "${SSH_AGENT_CACHE}" ]
then
echo "Reusing existing ssh-agent"
eval `cat "${SSH_AGENT_CACHE}"`
# Check that agent still exists
@rbriank
rbriank / memcache_model.rb
Created April 4, 2012 12:29 — forked from jpmckinney/memcache_model.rb
ActiveModel class with Memcache backend
# blog post: http://blog.slashpoundbang.com/post/1455548868/memcachemodel-make-any-ruby-object-that-persists-in
# No transactions or exceptions (yet).
module MemcacheModel
def self.included(base)
base.class_eval do
extend ActiveModel::Naming
extend ActiveModel::Translation
extend ActiveModel::Callbacks
extend MemcacheModel::ClassMethods
// from ruby-1.8.7-p357 ruby.h
#define RBIGNUM_SET_SIGN(b,s) (RBIGNUM(b)->sign = (s)) // line 455
#define RBIGNUM_LEN(b) (RBIGNUM(b)->len) // line 458
mkdir -p .ext/common
make PRELIBS='-Wl,-rpath,/home/bkierstead/rubies/ruby-enterprise-1.8.7-2009.10/lib -L/home/bkierstead/rubies/ruby-enterprise-1.8.7-2009.10/lib -ltcmalloc_minimal '
gcc -g -Os -fno-strict-aliasing -DRUBY_EXPORT -D_GNU_SOURCE=1 -L. -rdynamic -Wl,-export-dynamic main.o libruby-static.a -Wl,-rpath,/home/bkierstead/rubies/ruby-enterprise-1.8.7-2009.10/lib -L/home/bkierstead/rubies/ruby-enterprise-1.8.7-2009.10/lib -ltcmalloc_minimal -lrt -ldl -lcrypt -lm -o miniruby
libruby-static.a(random.o): In function `make_seed_value':
/home/bkierstead/src/ruby-enterprise-1.8.7-2009.10/source/random.c:304: undefined reference to `RBIGNUM_SET_SIGN'
/home/bkierstead/src/ruby-enterprise-1.8.7-2009.10/source/random.c:313: undefined reference to `RBIGNUM_LEN'
/home/bkierstead/src/ruby-enterprise-1.8.7-2009.10/source/random.c:313: undefined reference to `RBIGNUM_LEN'
collect2: ld returned 1 exit status
make: *** [miniruby] Error 1
/* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
/* static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */
#include "config.h"
#include "defines.h"
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif