Skip to content

Instantly share code, notes, and snippets.

View avand's full-sized avatar

Avand Amiri avand

View GitHub Profile
HTMLFormElement.prototype.submitViaXHR = function(success, error) {
if (this.classList.contains("submitting")) return;
var xhr = new XMLHttpRequest(),
form = this,
readyStates = ["unsent", "opened", "headers-received", "loading", "done"];
form.classList.add("submitting");
form.classList.remove("errored");
form.removeAttribute("data-ready-state");
require "test/unit"
class TruncateFromCenter
def self.truncate(string, length = 30, separator = "...")
return string if length > string.length
if string.length <= separator.length || length <= separator.length
return string[0...length]
end
# 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
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 {