Skip to content

Instantly share code, notes, and snippets.

## Ruby Documentation
http://ruby-doc.org/downloads/
@austenito
austenito / gist:5018075
Last active December 14, 2015 02:59
sales_engine - git://github.com/Diasporism/sales_engine.git
  • Class level variables are considered bad practice. Instance variables are the preferred way of storing object state.
    def self.build_customer(contents)
      @@customer = []
      contents.each {|row| @@customer << Customer.new(row)}
      @@customer.count
    end
  • Every class has find_by_* methods. Take a look at method_missing to create dynamic finders for your class attributes. This is exactly how the Rails finders work.

  • Results from methods can be memoized. You shouldn't have to look up objects every time you call a method to get back the same results.

def transactions
@transactions ||= Transaction.find_all_by_invoice_id(id)
end
" Powerline settings
set nocompatible " Disable vi-compatibility
set laststatus=2 " Always show the statusline
set encoding=utf-8 " Necessary to show Unicode glyphs"
set guifont=Menlo\ Regular\ for\ Powerline\:h14
let g:Powerline_symbols = 'fancy'
class Api::V1::BoardsController < ApplicationController
include Api::V1::GameConcerns
def show
board = current_player.boards.find(params[:id])
render json: board, serializer: Api::V1::BoardSerializer
end
end
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
def record_not_found(exception)
Rails.logger.warn "Record Not Found #{params}"
render :nothing => true, :status => :not_found
end
@austenito
austenito / suck.js
Created November 11, 2012 02:31
What not to do
client.query('SELECT username, upvotes FROM (SELECT djid, sum(up) as upvotes '
+ 'FROM ' + config.database.dbname + '.' + config.database.tablenames.song
+ ' WHERE started > DATE_SUB(NOW(), INTERVAL '
+ '1 DAY) GROUP BY djid) a INNER JOIN (SELECT * FROM (SELECT * FROM '
+ config.database.dbname + '.' + config.database.tablenames.user
+ ' ORDER BY lastseen DESC) as test GROUP BY userid) b ON a.djid = b.userid'
+ ' ORDER BY upvotes DESC LIMIT 3',
it "calls MC.clear_validation", ->
MC.reset_redemption_form()
expect(MC.clear_validation).toHaveBeenCalled()
it "calls MC.disable_button on the 'redeem' button", ->
MC.reset_redemption_form()
expect(MC.disable_button).toHaveBeenCalledWith($("#redeem"))
describe "MC", ->
describe "#update_overage_total", ->
beforeEach ->
$('#bill_total').remove()
$('#voucher_value').remove()
$('#overage_value').remove()
$('body').append "<div id='overage_value'></div>"
it "calculates positive overage value", ->
$('body').append "<input id='bill_total' type='text' value=100 />"
class User < ActiveRecord::Base
devise :recoverable, :trackable, :omniauthable
attr_accessible :name, :provider, :uid, :email, :access_token
has_many :deal_groups, :foreign_key => "owner_id"
has_one :payment
has_many :deal_group_users
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
uid = auth["uid"]