Skip to content

Instantly share code, notes, and snippets.

View scashin133's full-sized avatar

Sean Cashin scashin133

View GitHub Profile
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names
git_check_changes ()
{
git status | sed -n '
1h
1!H
$ {
g
s/Untracked files:/\?/
s/Changed but not updated/\*/
def run_cmd(cmd)
puts "\nRunning: #{cmd}"
raise "#{cmd} failed" unless system cmd
end
def current_branch
`git status`.gsub(/On branch (.+)/) do
return $1
end
def foo
f = Proc.new { return "return from foo from inside proc" }
f.call # control leaves foo here
return "return from foo"
end
def bar
f = lambda { return "return from lambda" }
f.call # control does not leave bar here
return "return from bar"
@scashin133
scashin133 / rand_alphanum.sh
Created January 6, 2011 22:25
Used to generate a random alphanum string from command line without newlines.
# Linux
openssl rand -base64 1024 -out /dev/stdout | sed -r 's/[^a-zA-Z0-9]//g' | tr -d '\n'
# Mac OSX
openssl rand -base64 1024 -out /dev/stdout | sed 's/[^a-zA-Z0-9]//g' | tr -d '\n'
@scashin133
scashin133 / bunlder_snippet.rb
Created February 1, 2011 21:46
snippet for requiring all gems in a Gemfile without having to load the rails environment or run with bundle exec
require 'rubygems'
require 'bundler'
ENV['BUNDLE_GEMFILE']="/path/to/Gemfile"
Bundler.require
@scashin133
scashin133 / gist:832537
Created February 17, 2011 20:01
STDOUT rails console
ActiveRecord::Base.logger = Logger.new(STDOUT)
reload!
@i = 0
a = ""
def ao
puts @i
end
@scashin133
scashin133 / apiexamples.rb
Created September 14, 2011 18:29
Socialcast API examples
require 'rubygems'
require 'rest_client'
require 'json'
require 'logger'
require 'pp'
class VhackDemo
def self.request(method, path, request_params)
RestClient.log = Logger.new(STDOUT)
url = ['https://', 'demo.socialcast.com', path].join
// Java example
import java.io.BufferedReader;
import java.io.OutputStreamWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.HttpURLConnection;