Skip to content

Instantly share code, notes, and snippets.

View coreymartella's full-sized avatar

Corey Martella coreymartella

  • Waterloo, Ontario, Canada
View GitHub Profile
@coreymartella
coreymartella / objective_resource_skeleton.rake
Created August 15, 2009 17:15
rake task to generate objc models from rails ones
desc "Generate iPhone Models"
task :objective_resource_skeleton => :environment do
output_path = "#{Rails.root}/doc/iphone_models"
#get all our models
model_files = Dir.glob("#{Rails.root}/app/models/*.rb").each { |file| require file }
models = Object.subclasses_of(ActiveRecord::Base).select { |model|
File.exist?("#{Rails.root}/app/models/#{model.name.underscore}.rb")
}
#make sure our output path exists
FileUtils.mkdir_p(output_path)
@coreymartella
coreymartella / dmd_helper.rb
Created August 18, 2009 02:04
helpers for DMD apps
# Methods added to this helper will be available to all templates in the application.
module DmdHelper
def admin_logged_in?
#TODO figure out if admin_logged_in
true
end
def title(page_title, show_in_body=true, &block)
content_for(:title) { page_title }
if show_in_body
heading = block_given? ? capture(&block) : content_tag(:h1,page_title.split(' // ').last)
!!! Strict
%html
%head
%title=yield(:title) || "FIXME: Default Title"
= stylesheet_link_tag 'general', 'dashboard', 'tables', 'pagination', 'forms', 'tooltips', 'widgets', :cache => "cache/all"
= javascript_include_tag :defaults, :cache => "cache/all"
= "<!--[if IE]>#{stylesheet_link_tag 'ie', :media => 'screen'}<![endif]-->"
= javascript_include_tag *@behaviours if @behaviours
%script{:type => "text/javascript"}= "rails_authenticity_token = '#{form_authenticity_token}';"
@coreymartella
coreymartella / dmd_template.rb
Created August 18, 2009 06:42
defunct template
raise "Don't use this, use the dropbox template!"
@coreymartella
coreymartella / ruby_home_automation_for_canine_happiness.rb
Created February 13, 2010 00:41
DoorMonitor - Doggy Motion Capture
require 'rubygems'
require 'directory_watcher'
require 'fileutils'
require 'growl'
# require 'ruby_gntp'
SOURCE = "http://172.16.187.5/img/mjpeg.cgi" #URL source of your video stream
#SOURCE = "http://172.16.187.5/img/video.asf" #URL source of your video stream
INTERVAL = 2 #seconds between frame grabs
FUZZ = 10 #fuzz for dealing with lossy jpgs
MIN_DELTA = 5 #delta required to cause a notification to occur
@coreymartella
coreymartella / chart_data.rb
Created December 17, 2010 19:30
Builds totals and counts for a scope or conditions
scope :summarized_by_app_and_date, select("app_id, occurred_on, count(*) as count,sum(total) as total").group("app_id, occurred_on").order("app_id, occurred_on")
def self.chart_data(conditions_or_scope)
if conditions_or_scope.is_a?(ActiveRecord::Relation)
totals = conditions_or_scope.summarized_by_app_and_date.all
else
totals = where(conditions_or_scope).summarized_by_app_and_date.all
end
totals.inject({:count => {}, :total => {}}) do |h,t|
h[:count][t.app_id] ||= []
h[:total][t.app_id] ||= []
@coreymartella
coreymartella / internet_monitor.rb
Created January 21, 2011 15:15
El Cheapo Internet Monitor
was_down = false
while true
t = Time.now.strftime("%l:%M:%S%p")
result = `ping -c 1 www.google.com 2>&1`
if result !~ /1 packets received/
puts "Check at #{t} -- DOWN!"
if was_down
#don't repeat the notification if we're still down
`say "Internet down!"`
@coreymartella
coreymartella / version_compare.rb
Created January 10, 2012 03:00
version compare
print "version1:";STDOUT.flush
v1 = gets.strip.split(".").map(&:to_i)
print "\nversion2:";STDOUT.flush
v2 = gets.strip.split(".").map(&:to_i)
diff = v1 <=> v2
puts "v1 < v2" if diff < 0
puts "v1 = v2" if diff == 0
puts "v1 > v2" if diff > 0
@coreymartella
coreymartella / post_receive.rb
Created April 19, 2012 13:21
post_receive.rb
{"commits"=>
[{"distinct"=>true,
"timestamp"=>"2011-06-22T11:53:30-07:00",
"message"=>"fix logger",
"committer"=>
{"username"=>"coreymartella",
"email"=>"[email protected]",
"name"=>"Corey Martella"},
"url"=>
"https://github.com/coreymartella/rails-footnotes/commit/326e01151a314c7808e4744ae1f2cce909d0c044",
@coreymartella
coreymartella / git-commiturl
Created May 2, 2012 18:57
Get a commit url for sharing
#!/usr/bin/env ruby
######
# To Install
# sudo wget https://raw.github.com/gist/2579234/git-commiturl -O /usr/local/bin/git-commiturl
# sudo chmod +x /usr/local/bin/git-commiturl
#
# To use
# git commiturl # gets the HEAD commit hash and copies a github url for it
# git commiturl -c 3dfcb4e7143d0c200e980ee2f65759157e066651 -o #copies a url for a specific commit hash AND opens it in your local browser