Skip to content

Instantly share code, notes, and snippets.

@nas
nas / stress testing
Created July 4, 2012 12:38
Apache Bench
#! /usr/bin/ruby
raise "Provide the dir path" unless ARGV[0] =~ /[a-z]*/
to_dir = ARGV[0].strip
raise "Provide the dir path" if to_dir.nil?
site = 'http://url'
print "Processing home page ... "
@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)
@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 / 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 / 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 / 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 / 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 / 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 / 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 / ssl_puma.sh
Last active August 29, 2015 14:22 — forked from tadast/ssl_puma.sh
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key