Skip to content

Instantly share code, notes, and snippets.

View avand's full-sized avatar

Avand Amiri avand

View GitHub Profile
# Given a set of class names, will require objects of those types to have been populated
# Usage: depends_on(User, Post, Comment)
def depends_on(*args)
raise "Depends on #{args.map{ |a| a.name.pluralize }.to_sentence.downcase} to populate data." if args.any? { |a| a.count.zero? }
args.each { |a| eval "@#{a.name.underscore.pluralize} = #{a}.all" }
end
require 'oauth/consumer'
require 'json'
class TwitterController < ApplicationController
before_filter :require_no_authentication
TWITTER_AUTH_KEY = '...'
TWITTER_AUTH_SECRET = '...'
TWITTER_AUTH_URL = 'http://twitter.com'
dom_id = 'new_debt_lightview'
page << "e = $('#{dom_id}'); if (e != null) { e.remove() }"
page.insert_html :bottom, 'body', content_tag(:div, :id => dom_id, :style => 'display: none') { render :partial => 'new' }
page << "Lightview.show({ href: '##{dom_id}', rel: 'inline', title: 'New Debt', options: { width: 420, height: 280 } });"
class AppTweeter < Struct.new(:status)
class << self
def new_user(user)
update("#{user.name} just signed up!")
end
def update(status)
status = "[#{Rails.env}] #{status}" unless Rails.env.production?
Delayed::Job.enqueue AppTweeter.new(status)
end
mysqldump --user username -ppassword -h host --complete-insert --skip-extended-insert --compact --no-create-info database_name table_name > output_file.sql
stylesheets = Dir.glob('public/**/*.css')
html = []
stylesheets.each do |stylesheet|
stylesheet = stylesheet.gsub('public/stylesheets/', '')
if stylesheet =~ /html/
html << stylesheet
else
@avand
avand / Gemfile
Created September 15, 2010 23:59
gem 'haml', '3.0.18'
$column_width: 60px;
$gutter_width: 10px;
@mixin container($number_of_columns: 12) {
margin-left: auto;
margin-right: auto;
width: $number_of_columns * $column_width;
}
@mixin grid($number_of_columns) {
def accept_offer
self.update_attributes! {
:offer_accepted_at => Time.now,
:offer_declined_at => nil
}
self
end
def decline_offer
self.update_attributes {
def memcached_up?
client = Dalli::Client.new('...', :username => '...', :password => '...')
client.get('test').nil?
rescue
false
end