Skip to content

Instantly share code, notes, and snippets.

@nas
nas / Useful git commands
Last active September 3, 2015 15:24
Useful git commands
# new branch from stash
git stash create new-branch stash@{0}
# push a local branch to repo if does not exist remotely
git push origin branch_name:refs/heads/branch_name
# to start tracking a branch
git branch --track branch_name origin/branch_name
# create remote git branch from head of master
@nas
nas / urlmonitor.rb
Created November 24, 2009 15:59 — forked from isaacs/urlmonitor.rb
urlmonitor.rb
#!/usr/bin/env ruby
# urlmonitor - print out the URLs requested system wide on the main network interface
# Accept a network interface name as an optional argument
iface = ARGV.first
# No interface specified? Try to guess which one is king..
unless iface
`ifconfig -l`.split.each do |iface|
next if iface =~ /^lo/
@nas
nas / Text Mate short cuts
Created December 5, 2009 07:17
Text Mate short cuts
1:
CTRL CMD N: OPEN NEW PROJECT
2:
ESC: PRINT WORDS USED IN CURRENT FILE
3:
CMD F2: SET BOOKMARK
4:
F2: GO TO A BOOKMARK
5:
F1: FOLD/EXPAND A TEXTBLOCK
@nas
nas / non table ActiveRecord
Created December 10, 2009 15:37
non table ActiveRecord
class StateMachine::TestBaseMixin < ActiveRecord::Base
# Make this class active recordish without the table
# and add the attributes as columns
def self.columns
@columns ||= []
end
def self.column(name, sql_type = nil, default = nil, null = true)
@nas
nas / Colour strings
Created December 17, 2009 08:06
Colour strings
# taken and modified from http://www.andrewmcdonough.com/2009/10/20/colorized-logs-in-ruby
def colorify(string, color, options = {})
offsets = ["gray","red", "green", "yellow", "blue", "magenta", "cyan","white"]
# I don't think below LOC is quite right due to the fact that xx and underline strings
# are appearing multiple times; will fix it when I am about to use this script.
styles = ["normal","bold","dark","italic","underline","xx","xx","underline","xx","strikethrough"]
start = options[:bg] ? 40 : 30
color_code = start + offsets.index(color)
style_code = styles.index(options[:style]) || 0
@nas
nas / Automate git pulling
Created July 3, 2010 05:16
Automate git pulling
#!/usr/local/bin/ruby -swI .
#
# AUTOMATE UPDATING ALL PROJECTS
#
# Problem: going to each project and then pulling changes.
# Solution: Automate git pulling for all my projects
#
# 1. Create a pull_projects file and add the code from this gist
# 2. Move the file into a directory that is in your path, i.e. $PATH
# 3. Make the file executable, eg. chmod +x /usr/local/bin/pull_projects
@nas
nas / update_status.rb
Created April 18, 2011 15:04
A basic, console twitter status update script
#!/usr/local/bin/ruby
require 'rubygems'
require 'highline/import'
require 'twitter'
user = ask("Enter your twitter username:") {|q| q.echo = 'x'}
passwd = ask("Enter your twitter password:") {|q| q.echo = 'x'}
http_auth = Twitter::HTTPAuth.new user, passwd
client = Twitter::Base.new(http_auth)
@nas
nas / gbgrep
Created May 20, 2011 18:19
git blame with grep
#!/usr/local/bin/ruby
grep = `git grep -n #{ARGV[0]} #{ARGV[1]}`
puts "\n-----------------------------------------------------------"
puts "GREP RESULT"
puts '-----------------------------------------------------------'
puts grep
files = grep.scan /.*\:\d+/
@nas
nas / roman_numeral_calculator.rb
Created July 20, 2011 17:40 — forked from jimweirich/analysis.rb
Results from Roman Numeral Calculator Kata at @cincinnatirb
class RomanNumeralCalculator
def calculate(numeral)
if numeral =~ /^\d+$/
arabic_to_roman(numeral)
else
roman_to_arabic(numeral)
end
end
private
@nas
nas / before_filter.rb
Created December 14, 2011 07:20
Before Filter
class A
def self.before_filters
@before_filters ||= []
end
def self.before_filter(callback, params={})
before_filters << params.merge(:callback => callback)
end
def self.inherited(child_class)