Skip to content

Instantly share code, notes, and snippets.

@kshsieh
kshsieh / meh.rb
Last active January 3, 2017 22:01
blah
CSV.open('referral_update.csv', 'wb') do |csv|
MembershipAgreement.
joins(:membership_agreement_statuses).
where(membership_agreement_statuses: { status: 'sent', success: true }).
where("membership_agreements.created_at < ?", Date.new(2016, 12, 28)).
uniq.
find_each do |membership_agreement|
membership_agreement.all_primary_change_requests.group_by(&:location).each do |location, change_requests_by_location|
TenantService.switch_tenant_with_location_uuid(location.uuid)
13:34:41.486 2014-10-20 17:34:41.174673+00:00 app web.2 - - [5172d7fd-f601-4e34-8c94-2677d5e3a27e] Started POST "/admin/accounting/payments/manual/cc.json" for 108.162.218.142 at 2014-10-20 17:34:41 +0000
» 13:34:41.500 2014-10-20 17:34:41.197636+00:00 app web.2 - - [5172d7fd-f601-4e34-8c94-2677d5e3a27e] Processing by Admin::Accounting::ManualController#cc as JSON
» 13:34:41.576 2014-10-20 17:34:41.197645+00:00 app web.2 - - [5172d7fd-f601-4e34-8c94-2677d5e3a27e] Parameters: {"location_id"=>"23", "account_id"=>"8474", "payment_amount"=>"975.00"}
» 13:34:42.156 2014-10-20 17:34:40+00:00 app heroku-postgres - - source=HEROKU_POSTGRESQL_AMBER sample#current_transaction=20294749 sample#db_size=2191209592bytes sample#tables=46 sample#active-connections=21 sample#waiting-connections=0 sample#index-cache-hit-rate=0.99985 sample#table-cache-hit-rate=0.99483 sample#load-avg-1m=0.16 sample#load-avg-5m=0.2 sample#load-avg-15m=0.22 sample#read-iops=17.146 sample#write-iops=0.54468 sample#memory-total=1692568kB sample#mem
require 'rails_helper'
RSpec.describe RestaurantsController, type: :controller do
let!(:restaurant){Restaurant.create(name:"TestRestaurant")}
context "GET index" do
it "should return all restaurants" do
get :index
expect(assigns(:restaurants)).to include restaurant
end
class FakeController < ActionController
before_action :find_fake, only: [:show, :edit, :update]
def index
@fakes = Fake.all
end
def new
@fake = Fake.new
end
@kshsieh
kshsieh / Gemfile
Last active August 29, 2015 13:57
boiler plate GemFile for quick iteration on Heroku apps
source 'https://rubygems.org'
ruby '2.1.1'
gem 'rails', "4.0.2"
gem 'turbolinks', "~> 2.2.1"
gem 'pg', "~> 0.17.1"
gem 'haml-rails', "~> 0.5.3"
gem "bootstrap-sass", "~> 3.1.1"
@kshsieh
kshsieh / haml_barf.html
Created February 11, 2014 22:11
haml barf
<!-- / we render evnet/listing post differently than a regular post -->
<!-- / for event/listing posts that have comments, use commentator\'s profile -->
<div id=\'post_header\'>
Latest from NYC - Soho West
<\/div>
<!-- / we render evnet/listing post differently than a regular post -->
<!-- / for event/listing posts that have comments, use commentator\'s profile -->
<div class=\'post\' data-owning-profile-id=\'115\'>
<div class=\'media thumb_2x\' data-post-id=\'44208\' data-post-updated-at=\'2014-02-10 17:43:10 UTC\'>
@kshsieh
kshsieh / gist:7590889
Created November 21, 2013 22:26
dual polymorphic joins table
class Groupable
has_many :group_rules, as: :grouped
has_many :rule_objects, through: :group_rules
end
class GroupRules
belongs_to :grouped, polymorphic: true
belongs_to :rulable, polymoprhic: true
end
@kshsieh
kshsieh / gist:7378060
Created November 8, 2013 21:35
city state country setting + validation proiblem
# in a standard situation, params will be passed into a Coordinate object like below:
{
city_input: "New York",
state_or_country_input: "NY",
latitude: "40.7143528",
longitude: "-74.0059731",
neighborhood: "Tyler Run-Queens Gate",
city: "New York",
state: "New York",
[9] pry(main)> info.update_attributes(params)
(0.1ms) BEGIN
Image Load (0.5ms) SELECT `assets`.* FROM `assets` WHERE `assets`.`type` IN ('Image') AND `assets`.`viewable_id` = 1 AND `assets`.`viewable_type` = 'User::Info' AND `assets`.`id` IN (4039) ORDER BY `assets`.`position`
(2.7ms) UPDATE `user_infos` SET `completion` = '---\n:card: false\n:statement: false\n:bio: false\n:contact_info: false\n:artworks: false\n:publish: false\n:share:\n :twitter: false\n :facebook: false\n :email: false\n :link: false\n', `updated_at` = '2013-07-19 15:24:04' WHERE `user_infos`.`id` = 1
(0.6ms) UPDATE `assets` SET `remote_url` = 'https://s3.amazonaws.com/artsicle.filepicker.testing/tmp/AYRlLfbrS22r4dG7mtbH_Selection_004.png', `filepicker_url` = 'https://www.filepicker.io/api/file/Kb41uMctTeuAxdG57rE7', `attachment_file_size` = 29761, `attachment_file_name` = 'Selection_004.png', `attachment_content_type` = 'image/png' WHERE `assets`.`type` IN ('Image') AND `assets`.`id` = 4039
(0.8ms) SELECT COUNT(*) FROM
@kshsieh
kshsieh / gist:5878822
Created June 27, 2013 18:06
false positive
# test in users controller spec
# testing update with a guest account
context "updating guest account" do
before :each do
email = "guest@example.com"
User.check_and_create_guest(email)
user = User.find_by_email(email)
controller.stub :current_user => user
end