This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with hydrated_sleeps as ( | |
| select ss.user_id, ss.well_rested, ss.occurred_on, u.company_id, u.gender | |
| from simple_sleeps ss inner join users u on u.id = ss.user_id | |
| ), | |
| filtered_sleeps as ( | |
| select * from hydrated_sleeps where company_id = 12 or company_id = 4 | |
| ), | |
| sleep_counts as ( | |
| select |
We can make this file beautiful and searchable if this error is corrected: It looks like row 3 should actually have 1 column, instead of 3 in line 2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with current_goals as ( | |
| select g.user_id, g.id, 'eat_move_sleep' as goal_type | |
| from eat_move_sleep_goals g | |
| where now() between start_date and end_date | |
| union | |
| select g.user_id, g.id, 'weight_loss' as goal_type | |
| from weight_loss_goals g | |
| where now() between start_date and end_date | |
| union |
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 2 in line 1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create temp table hydrated_temp ( | |
| occurred_on date, | |
| user_id int, | |
| company_id int); | |
| with | |
| participation as ( | |
| select occurred_on, user_id from simple_activities | |
| union | |
| select occurred_on, user_id from simple_sleeps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def lines(invoice) | |
| (invoice.lines.count / 100.0).ceil.times.map do |page| | |
| offset = page * 100 | |
| invoice.lines.all(count: 100, offset: offset).map do |line| | |
| Stripe::InvoiceItem.construct_from line | |
| end | |
| end.flatten | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def remove_membership(membership) | |
| ii = Stripe::InvoiceItem.retrieve(membership.stripe_invoice_item) | |
| ii.delete | |
| rescue | |
| #nothing | |
| end | |
| def kill_stripe(n=30) | |
| query = Membership.where(Membership.arel_table[:updated_at].gt 33.days.ago).where.not(stripe_invoice_item: nil) | |
| count = query.count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # tests for 3.2 of confident ruby | |
| # inplicit vs explicit | |
| # | |
| require 'pry' | |
| describe "section 3.2" do | |
| context "string" do | |
| class C | |
| attr_accessor :name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rvm install ruby-2.2.2 | |
| bundle install | |
| #rspec spec failed on redis | |
| brew install redis | |
| # turn on redis at login | |
| mkdir -p ~/Library/LaunchAgents | |
| ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents | |
| # turn on redis now! | |
| launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes | |
| class Primes | |
| def self.time_it | |
| t = Time.now | |
| rval = yield | |
| elapsed = Time.now - t | |
| #return rval, elapsed | |
| puts elapsed | |
| return rval |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class InterfaceProxy | |
| def self.create(delegate) | |
| begin | |
| #check if proxy exists | |
| if delegate.__class == self | |
| delegate.log "proxy previously created, returning delegate" | |
| return delegate | |
| end | |
| rescue | |
| # if not return a new one |
NewerOlder