Skip to content

Instantly share code, notes, and snippets.

View mokolabs's full-sized avatar

Patrick Crowley mokolabs

View GitHub Profile
@mokolabs
mokolabs / invoices.rb
Created March 16, 2012 21:18
archive your slicehost invoices
require 'rubygems'
require 'mechanize'
a = Mechanize.new { |agent|
agent.follow_meta_refresh = true
agent.pluggable_parser.pdf = Mechanize::FileSaver
}
a.get('https://manage.slicehost.com/') do |home_page|
Process: Safari [5047]
Path: /Applications/Safari.app/Contents/MacOS/Safari
Identifier: com.apple.Safari
Version: 5.0.5 (6533.21.1)
Build Info: WebBrowser-75332101~6
Code Type: X86-64 (Native)
Parent Process: launchd [641]
Date/Time: 2011-06-29 21:14:22.609 -0700
OS Version: Mac OS X 10.6.8 (10K540)
@mokolabs
mokolabs / user.rb
Created May 26, 2011 02:49 — forked from ropiku/user.rb
If you need to support logging in via username and your usernames are case sensitive, use this.
def self.authenticate(email, password)
user = find(:first, :conditions => ['LOWER(username) = ? OR email = ?', email.to_s.downcase, email.to_s.downcase])
user && user.authenticated?(password) ? user : nil
end
# MODEL
class Theater
named_scope :with_recent_comments,
:select => "*, recent_comments.created_at AS last_comment_at",
:joins => "INNER JOIN (SELECT * FROM comments WHERE entity_type = 'Theater' ORDER by id DESC LIMIT 100)
AS recent_comments ON recent_comments.entity_id = theaters.id",
:order => "recent_comments.created_at DESC"
end
# CONTROLLER
# Recent comments on theaters
comments = Comment.find(:all, :conditions => "entity_type = 'Theater'", :order => "id DESC", :select => "entity_id", :limit => 100)
comments = comments.map{ |i| i.entity_id }.uniq
theaters = Theater.find(:all, :conditions => "id IN (#{comments.join(',')})")
@theaters_with_comments = theaters.sort_by{|e| comments.index(e.id)}
# VIEW
@mokolabs
mokolabs / gist:876452
Created March 18, 2011 17:13
Summary of recent work
NEW
- Added rating stars to product grid
- Supports multiple sizes
- Displays half-step stars by default
- Improved styles on product, production association, and collections pages
- Improved styles on friends sidebar on Dashboard page
- Added basic tooltip support
# Simple batch convertor for ERB => HAML
# To run, move to app root and do 'ruby haml.rb'
class ToHaml
def initialize(path)
@path = path
end
def convert!
Dir["#{@path}/**/*.erb"].each do |file|
.message_block {
clear: both;
margin: 12px 0;
}
.message_block ul {
border-bottom: 1px solid #ecd757;
border-top: 1px solid #ecd757;
list-style: none;
padding: 10px;
@mokolabs
mokolabs / clear_log.rb
Created November 16, 2010 04:27
Add this initializer to auto-delete your development log
# Clear logs when booting server locally
# so they don't grow to be 1GB in size
if RAILS_ENV == 'development'
f = File.open("#{RAILS_ROOT}/log/development.log", "w")
f.close
end
var functions = []
$.getJSON("/functions.json", function(data) {
$.each(data, function(i, item) {
functions.push(item.function.name);
});
$("#functions_list").autocomplete(functions);
});