Skip to content

Instantly share code, notes, and snippets.

View kbrock's full-sized avatar

Keenan Brock kbrock

View GitHub Profile
#!/usr/bin/env ruby
require 'nokogiri'
src =<<EOD
<wrapper xmlns="ns" xmlns:extra="extra">
<record xml:id="r1">
<field>aaa</field>
<field extra:type="second">bbb</field>
</record>
digraph G {
label = "Enterprise"
rankdir = "TB";
node [ shape="Mrecord" ]
edge [ color="#555555"; dir="back"]
subgraph cluster_1 {
label = "Region: 1"
color = "#000000"
@kbrock
kbrock / gitconfig
Last active August 29, 2015 14:02
gitconfig
[alias]
st = status
br = branch
co = checkout
cat = show
#origin = !sh -c 'git remote add -t ${2:-master} -m ${2:-master} ${1:-origin} ${0}'
prune = fetch --prune
#amend keeping the same comment
amend = !git log -n 1 --pretty=tformat:%s%n%n%b | git commit -F - --amend
# add file to .gitignore
@kbrock
kbrock / windowing.sql
Last active December 30, 2015 00:59
Using windowing function to do multiple smaller limits. Give me the first 3 records (for each grouping) If you use limit, this will require 1 query to determine the groupings, and one limit queries per each grouping. N+1
create table windowing_example (id int, counter int);
-- id is the common component of the rows
-- counter is the timestamp / other id where ordering is introduced
insert into windowing_example(id, counter) values
(1, 1),
(1, 2),
(1, 3),
(1, 4),
(1, 5),
@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"
} }
# 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 / 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
@kbrock
kbrock / install.sh
Created September 25, 2012 21:34
nginx info
brew install nginx
@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
From bef595dbdbde5725b8d49242b10a400db38134d1 Mon Sep 17 00:00:00 2001
From: Ben Zack <[email protected]>
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 ++++++++++++++++++