Skip to content

Instantly share code, notes, and snippets.

View kbrock's full-sized avatar

Keenan Brock kbrock

View GitHub Profile
@kbrock
kbrock / complie.sh
Last active September 8, 2015 15:16 — forked from havenwood/hello.cr
"Hello, world!" from MRuby embedded in Crystal
export MRUBY_HOME=/opt/rubies/mruby-20150906
crystal run --link-flags -L${MRUBY_HOME}/lib/ hello.cr
@kbrock
kbrock / 01_before.txt
Created October 1, 2010 12:23
Hirb example
>> Disease.find(2)
=> #<Disease id: 2, name: "MS", symptom_survey_lifespan: 30, disease_status_id: 3, key: "ms", community_manager_id: 3187, created_at: nil, updated_at: nil>
>> User.first
# => #<User id: 22, verified: true, deleted: false, created_at: "2008-07-03 13:36:57", updated_at: "2010-09-23 03:18:13", first_name: "Justin", last_name: "Smith", title: "wife", disease_id: 2, address: nil, city: "Boston", state: "MA", country: "United States", sex: nil, birth_date: nil, deceased_date: nil, permit_registry: nil, height: nil, display_height_unit: nil, display_weight_unit: nil, allows_public_view: false, lat: #<BigDecimal:1098c57d0,'0.28228671E2',18(18)>, lng: #<BigDecimal:1098c56e0,'-0.81653075E2',18(18)>, postcode: "02142", last_activity_time: "2008-07-03 13:38:10", last_update_time: nil, allows_badge: false, timezone: nil, phone: nil, messaging_privileges: nil, role_id: 5, unsubscribe_token: "21a497dae68b11780871083eddd6a3f201389bd6", welcome_message_sent_on: "2009-03-24", system_welcome_message_sent_o
@kbrock
kbrock / Gemfile
Created April 8, 2011 03:36
initializer to load debugger
gem 'rdebug', '0.1', :group => :development, :require => false
From bef595dbdbde5725b8d49242b10a400db38134d1 Mon Sep 17 00:00:00 2001
From: Ben Zack <bzack@patientslikeme.com>
Date: Mon, 11 Jul 2011 15:42:24 -0400
Subject: [PATCH] Added levenshtein distance for determining database name
from branch name
---
Gemfile | 1 +
Gemfile.lock | 2 ++
lib/devdb.rb | 18 ++++++++++++++++++
@kbrock
kbrock / bashrc.bash
Created March 7, 2012 13:21
Colored Git prompts
# thanks from: http://aaroncrane.co.uk/2009/03/git_branch_prompt/
function find_git_branch {
local dir=. head
git_dir=${PWD}
until [ "$dir" -ef / ]; do
if [ -f "$dir/.git/HEAD" ]; then
head=$(< "$dir/.git/HEAD")
if [[ $head == ref:\ refs/heads/* ]]; then
git_branch="${head#*/*/}"
elif [[ $head != '' ]]; then
require "objspace"
ObjectSpace.trace_object_allocations_start
def log_object_space
ObjectSpace.trace_object_allocations_stop
object_hash = {}
ObjectSpace.each_object do |o|
key = "#{ObjectSpace.allocation_sourcefile(o)}" #:#{ObjectSpace.allocation_sourceline(o)}"
object_hash[key] ||= Hash.new { |h, _| h[:count] = 0; h[:memsize] = 0 }
@kbrock
kbrock / install.sh
Created September 25, 2012 21:34
nginx info
brew install nginx
@kbrock
kbrock / gist:4177712
Created November 30, 2012 18:52
ugly package list
#aptitude (/ search, + install, gg - go)
contents
apt-file list $*
install
apt-get install
upgrade
apt-get upgrade
remove
apt-get --purge remove $*
list installed
# Create a file: config/torquebox_remote.rb
TorqueBox::RemoteDeploy.configure do
torquebox_home "/usr/local/torquebox"
jruby_home "/usr/local/jruby"
hostname "10.0.3.50"
#port "22"
user "deployer"
key "#{ENV['HOME']}/.ssh/deployer_rsa"
#sudo true
end
@kbrock
kbrock / timing.rb
Created December 21, 2012 15:00
timing custom string interpolation
require "benchmark"
require 'erb'
d=Time.now
Benchmark.bm(20) do |x|
# the ultimate, but still can't figure out how to generate something that can be interpolated
x.report("n - str") { 100_000.times {
"abc #{d.hour < 10 ? '0' : ''}#{d.hour} #{d.min < 10 ? '0' : ''}#{d.min} cdef"
} }