Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
#A way of including local functions in sub folders
path = File.expand_path $0
path = File.dirname(path)
require "#{path}/SubDir/function_1.rb"
require "#{path}/SubDir/function_2.rb"
require "#{path}/SubDir/function_3.rb"
#Or change working dir of script
#Small function to run a command and output return values
def do_and_report(command)
f = open("| #{command}")
g = Array.new
while (foo = f.gets)
g << foo
end
g.each do |element|
puts element
end
#!/usr/bin/env ruby
# Measure performance in seconds of tasks
# Record Startime For performance measurements
start_time = Time.now
#Main part of script goes here
#Calculate and Display Execution Time in seconds
exec_time = Time.now - start_time
## Command line to apply Migration
#sequel -m ./db/migrate/ -M 4 sqlite://db/blog.db
## Command to roll back
#sequel -m ./db/migrate/ -M 3 sqlite://db/blog.db
Class.new(Sequel::Migration) do
def up
DB.alter_table :aTable do
rename_column :old, :new
#Small function to generate a comma delimited dictionary on a unix system
def gen_dictionary
f = open("| cat /usr/share/dict/words")
g = Array.new
while (foo = f.gets)
g << foo
end
g.each do |element|
element = element.strip
print element + ","
# Sinatra method for handling file uploads
# based on http://pastie.caboo.se/134681
require 'rubygems'
require 'sinatra'
get '/upload' do
erb '<form action="upload" method="post" enctype="multipart/form-data" accept-charset="utf-8">
<input type="file" name="uploaded_data" id="uploaded_data">
<p><input type="submit" value="Continue"></p>
</form>'
#!/usr/bin/env ruby
## Command Line tools can now be portable while working on static folders.
if ENV['MEDIA_FOLDER'].nil?
puts "Add this to ~/.bashrc"
puts "Or Windows variables"
puts "export MEDIA_FOLDER='[\"/user/name/Movies\", \"/user/name/TV Shows\"]'"
else
puts ENV['MEDIA_FOLDER']
#!/usr/bin/env ruby
class HelloWorld
def initialize
@msg = "HelloWorld!"
end
def to_s
return @msg
end
@morganp
morganp / .bashrc
Created June 29, 2010 13:17 — forked from justintv/.bashrc
# If you work with git, you've probably had that nagging sensation of not knowing what branch you are on. Worry no longer!
PS1='\[\033[01;32m\]\h \[\033[01;34m\]\W' #\$ \[\033[00m\]'
PS1=$PS1"\$(git branch 2>/dev/null | grep '^*' | colrm 1 2 | xargs -I {} echo ' (\[\033[01;31m\]'{}'\[\033[01;34m\])')"
export PS1=$PS1" \$ \[\033[00m\]"
# This will change your prompt to display not only your working directory but also your current git branch, if you have one. Pretty nifty!
# host ~/code/web (beta_directory) $ git checkout master
#!/usr/bin/env ruby
color = ['Cyan',
'Blue',
'DarkOrange',
'DarkSeaGreen',
'DarkSalmon',
'DeepPink',
'DimGray',
'Green',