Skip to content

Instantly share code, notes, and snippets.

View stereosupersonic's full-sized avatar

MICE Portal stereosupersonic

View GitHub Profile
@stereosupersonic
stereosupersonic / install textmate bundle
Created January 16, 2010 17:17
install textmate bundle
mkdir -p ~/Library/Application\ Support/TextMate/Bundles
cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/grimen/formtastic_tmbundle.git 'Formtastic.tmbundle'
osascript -e 'tell app "TextMate" to reload bundles'
@stereosupersonic
stereosupersonic / table.css
Created February 1, 2010 12:15
table.css
table tr th {background:#222; color:#fff; padding:0; border:#111 solid 1px; text-align: center; font-weight: bold;}
table tr td {border:1px #ccc solid; padding:5px;}
table tr td.rightright {background: #eee;}
table tr td h4 {margin:0; padding:0; font-weight:normal;}
#from here => http://net.tutsplus.com/tutorials/other/building-a-forum-from-scratch-with-ruby-on-rails/
table {
def every seconds, &block
while true
yield
sleep seconds
end
end
class Fixnum
def minutes
self * 60
@stereosupersonic
stereosupersonic / validate_email.rb
Created February 4, 2010 13:20
validate email adress
validates_format_of :email,
:with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i
@stereosupersonic
stereosupersonic / string_to_file.rb
Created August 4, 2010 12:38
Write Text to a File
open('output.txt', 'w') { |f| f << "This file contains great truths.\n"}
@stereosupersonic
stereosupersonic / youtube2mp3
Created November 16, 2010 15:17
convert youtube videos to mp3 on OSX
#!/usr/bin/ruby
#example:
# youtube2mp3 EzgGTTtR0kc
VLC = "/Applications/VLC.app/Contents/MacOS/VLC"
youtube_id = ARGV.first || STDIN.read
raise "no youtube id is given" unless youtube_id
system "#{VLC} -I dummy http://www.youtube.com/watch?v=#{youtube_id}
@stereosupersonic
stereosupersonic / update_all_bundles.rb
Created March 10, 2011 09:14
update all my textmate bundles from github
#!/usr/bin/env ruby
Dir.chdir(File.expand_path("~/Library/Application\ Support/TextMate/Bundles/")) do
Dir.foreach(".") do |dir|
if File.directory?(dir)
Dir.chdir(dir) do
puts "Update Bundle #{File.basename Dir.getwd}"
puts %x{git pull}
end
end
@stereosupersonic
stereosupersonic / analytics.rb
Created October 31, 2011 13:56
analytics_stub
# analytics/app/support/report_invoker.rb
class ReportInvoker
def self.build_reports(dir)
new(dir).build_reports
end
attr_reader :dir
def initialize(dir)
def colorize(text, color_code)
"\e[#{color_code}m#{text}\e[0m"
end
def red(text); colorize(text, 31); end
def green(text); colorize(text, 32); end
def yellow(text); colorize(text, 33); end
@stereosupersonic
stereosupersonic / import_export_json.rb
Created March 21, 2012 08:26
Import export data with json
require 'json'
#export
users = User.all.map {|user| {:id => user.id, :name => user.name }}
File.open("/tmp/users.json","w") do |f|
f.write(JSON.pretty_generate(users))
end
#import