Skip to content

Instantly share code, notes, and snippets.

array = [1,2,4,3]
// => [1, 2, 4, 3]
array[6]
// => undefined
array[6] !== undefined
// => false
array[1] !== undefined
// => true
array[1] = false
// => false
irb(main):007:0> RestaurantModel.create name: 'Foo Bar'
=> #<Restaurant @values={:id=>7, :merchant_id=>nil, :name=>"Foo Bar", :created_at=>2012-03-22 10:57:53 -0400, :updated_at=>2012-03-22 10:57:53 -0400, :neighborhood_id=>nil, :metro_id=>nil, :price_rating=>nil, :reservation_max_party_size=>8, :reservation_days_in_advance=>nil, :time_zone=>nil, :accepts_reservations=>true, :uses_table_management=>nil, :reservation_no_show_after_minutes=>15, :server_balance_mode=>2, :server_balance_importance=>5, :customer_vip_after_visits=>5, :sms_default_pager_message=>nil, :email_from_address=>nil, :email_from_name=>nil, :phone_number=>nil, :reservation_pre_close_minutes=>60, :agreed_to_mail=>nil, :restaurant_guid=>nil, :non_customized_trial=>nil, :useful_notes_rtf=>nil, :subdomain=>nil, :uses_manual_slotting=>true, :replyto_email=>nil, :replyto_sender_name=>nil, :activation_date=>nil, :table_manager=>nil, :monthly_fee=>nil, :transaction_fee=>nil, :monthly_fee_cap=>nil, :reservation_email_template=>nil, :reservation_from_
namespace :resque do
task :setup => :environment do
require 'resque'
ENV['QUEUE'] = '*'
Resque.after_fork do |job|
ActiveRecord::Base.establish_connection
end
end
end
scope :terms, lambda { |terms|
return if terms.blank?
composed_scope = joins(:user)
terms.split.each do |term|
term = '%' << term << '%' # Wrap the search term in % to achieve 'fuzzy' searching
composed_scope = composed_scope.where 'messages.body ILIKE :term', term: term
composed_scope = composed_scope.where 'users.first_name ILIKE :term or users.last_name ILIKE :term', term: term
end
User.invite!(:email => email) { |new_user| new_user.school_id = current_user.school_id }
@jperrine
jperrine / gist:1565902
Created January 5, 2012 16:08
stripe callbacks
class StripeCallbacksController < ApplicationController
def create
@user = User.find_by_stripe_customer_token(params[:customer])
if ["recurring_payment_failed", "recurring_payment_succeeded", "subscription_final_payment_attempt_failed"].include? params[:event]
send(params[:event])
end
respond_to do |format|
format.json { render :json => {}, :status => :ok }
end
end
Pending:
Asset
# No reason given
# ./spec/models/asset_spec.rb:22
Failures:
1) TemplatesController show should find the template and display it
Failure/Error: get :show, @params
NoMethodError:
var ApplicationNamespace = function() {};
ApplicationNamespace.FurtherNamespace = (function() {
// private stuff
return {
publicFunction: somePrivateFunction,
init: function(args) {
},
@jperrine
jperrine / gist:1329577
Created November 1, 2011 01:15
modules
module AdminUserMethods
def self.included(base)
base.extend(ClassMethods)
end
# instance methods go here
module ClassMethods
# class methods go here
end
@jperrine
jperrine / gist:1323948
Created October 29, 2011 01:04
separation
# in lib/admin_user_methods.rb
module AdminUserMethods
# your methods go here
end
# in app/models/user.rb
class User < AR
include AdminUserMethods
end