Skip to content

Instantly share code, notes, and snippets.

View trobrock's full-sized avatar

Trae Robrock trobrock

View GitHub Profile
class Calculator
def exec(expression)
while op = expression.match(/\([^()]+\)/)
offsets = op.offset(0)
out = exec op[0].gsub(/[()]/,'')
expression[offsets.first...offsets.last] = out.to_s
end
while op = expression.match(/\d+ ?[\*\/] ?\d+/)
run_expression op, expression
@trobrock
trobrock / git_clean_remote.sh
Created July 31, 2012 18:40
Clean unneeded branches from a git remote
#!/usr/bin/env bash
git_clean_remote()
{
remote=$1
[[ -z "$remote" ]] && echo "Must provide a remote" && return 1
for branch in $(git branch -r | grep $remote | grep -v master)
do
diff=$(git cherry -v master $branch | wc -l)
@trobrock
trobrock / trobrock.zsh
Created August 3, 2012 20:51
Custom additions to oh my zsh
alias gd='git diff'
alias gdc='git diff --cached'
alias gpq='git pull-request'
alias gld="gl | grep Updating | cut -d ' ' -f2 | xargs git diff"
alias grm="git status | awk '/deleted/{print \$3}' | xargs git rm"
alias gm='git merge --no-ff'
alias gmff='git merge'
alias gf='git fetch -p'
alias clean='find ./**/*.orig | xargs rm'
alias migrate='rake db:migrate db:test:prepare parallel:prepare'
require 'rest-client'
req = RestClient::Request.new(
:method => :post,
:url => "https://snapi.sincerely.com/shiplib/create",
:payload => {
:appkey => ENV["SINCERELY_APP_KEY"],
:debugMode => true,
:frontPhotoId => image["id"],
:recipients => [
[2012-08-30T15:02:18-07:00] INFO: Processing directory[/var/apps/outight_app/current/log] action delete (outright-application::default line 60)
[2012-08-30T15:02:18-07:00] INFO: Processing directory[/var/apps/outight_app/current/public/system] action delete (outright-application::default line 60)
[2012-08-30T15:02:18-07:00] INFO: Processing directory[/var/apps/outight_app/current/tmp/pids] action delete (outright-application::default line 60)
[2012-08-30T15:02:18-07:00] INFO: Processing execute[test ! -d /var/apps/outright_app/current/log] action run (outright-application::default line 66)
[2012-08-30T15:02:18-07:00] ERROR: execute[test ! -d /var/apps/outright_app/current/log] (outright-application::default line 66) has had an error
[2012-08-30T15:02:18-07:00] ERROR: execute[test ! -d /var/apps/outright_app/current/log] (/var/chef/cache/cookbooks/outright-application/recipes/default.rb:66:in `from_file') had an
error:
execute[test ! -d /var/apps/outright_app/current/log] (outright-application::default line 6
name "application"
run_list "application"
@trobrock
trobrock / gist:3702453
Created September 11, 2012 22:04
jruby-openssl Bundler issues
[release@thrift1 20120911215203]$ jruby -v
jruby 1.5.6 (ruby 1.8.7 patchlevel 249) (2010-12-03 9cf97c3) (OpenJDK 64-Bit Server VM 1.6.0_24) [amd64-java]
[release@thrift1 20120911215203]$ jruby -Sgem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.6
- RUBY VERSION: 1.8.7 (2010-12-03 patchlevel 249) [java]
- INSTALLATION DIRECTORY: /opt/jruby-1.5.6/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/jruby-1.5.6/bin/jruby
- EXECUTABLE DIRECTORY: /opt/jruby-1.5.6/bin
- RUBYGEMS PLATFORMS:
#!/bin/sh
git checkout master
remote=$1
branches=$(git branch --remote --merged master | grep $remote/ | grep -v /master)
for branch in $branches
do
branch=$(echo $branch | cut -d'/' -f2)
git push $remote :$branch
#!/usr/bin/env ruby
wanting = ARGV[0]
role = wanting.scan(/[a-z]+/).first.to_sym
number = wanting.scan(/\d+/).first.to_i
ROLES = {}
def role(role, *hosts)
hosts.pop if hosts.last.is_a?(Hash)
ROLES[role] = hosts
@trobrock
trobrock / create_post.rb
Created November 8, 2012 19:27
Helper for creating posts with jekyll `./create_post.rb "some title"`
#!/usr/bin/env ruby
require 'stringex'
title = ARGV.first
date = "#{Time.now.year}-#{Time.now.month}-#{Time.now.day}"
file_name = "#{date}-#{title.to_url}.md"
File.open(File.join("_posts", file_name), 'w') do |f|
f.puts "---"
f.puts "layout: post"