Skip to content

Instantly share code, notes, and snippets.

View richardking's full-sized avatar

Richard King richardking

  • Instacart
  • San Francisco, CA
View GitHub Profile
--
Parameters: {"tags"=>"nba,los-angeles-lakers,australia-cricket,cricket,wwe,cold-hard-facts", "nba-fantasy"=>"kobe-bryant,lebron-james", "last_request"=>"1395961708", "locale"=>"en_AU", "tz"=>"34200"}
Started GET "/api/v1/team_streams/philadelphia-eagles.json?appversion=3.3.1&devicetype=iphone&locale=en_US&tz=-14400" for 165.254.159.205 at 2014-04-10 23:08:28 +0000
Completed 200 OK in 229.8ms (Views: 0.2ms | ActiveRecord: 103.8ms)
Processing by Api::V1::TeamStreamsController#show as JSON
Parameters: {"appversion"=>"3.3.1", "devicetype"=>"iphone", "locale"=>"en_US", "tz"=>"-14400", "id"=>"philadelphia-eagles"}
%%%D
1 2014-04-10 21:38:33 UTC
2 ActiveSupport::TimeWithZone
3 "2014-04-10T21:38:33Z"
➜ ~ curl http://ec2-54-237-184-72.compute-1.amazonaws.com/api/v1/push_notifications\?tags\=bangladesh-cricket,new-york-yankees,cold-hard-facts\&last_request\=1395793685\&locale\=en_US\&tz\=-25200 --verbose
* Adding handle: conn: 0x7ffba1804000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7ffba1804000) send_pipe: 1, recv_pipe: 0
* About to connect() to ec2-54-237-184-72.compute-1.amazonaws.com port 80 (#0)
* Trying 54.237.184.72...
* Connected to ec2-54-237-184-72.compute-1.amazonaws.com (54.237.184.72) port 80 (#0)
> GET /api/v1/push_notifications?tags=bangladesh-cricket,new-york-yankees,cold-hard-facts&last_request=1395793685&locale=en_US&tz=-25200 HTTP/1.1
@richardking
richardking / gist:9979324
Last active August 29, 2015 13:58
15422 next previous game date
def previous_game_date
@previous_game_date ||= if Score.cached_previous_league_game(@params[:league], @params[:sport], @tz, @date)
Time.parse(Score.cached_previous_league_game(@params[:league], @params[:sport], @tz, @date)["startTime"]).in_time_zone(@tz)
elsif GameFinder.new.previous_game_before_date(@params[:league], @params[:sport], @tz, @date)
GameFinder.new.previous_game_before_date(@params[:league], @params[:sport], @tz, @date)["starts_at"].in_time_zone(@tz)
else
@date-1.day
end
end
@richardking
richardking / gist:9671343
Created March 20, 2014 19:02
instagram team stream json
{"items":[{"type":"Tweet","id":11083421,"tag":8248,"publishedAt":"2014-03-20T17:46:13Z","programmedAt":"2014-03-20T17:46:13Z","permalink":"https://twitter.com/DarnellMayberry/status/446704276488720384","twitterHandle":"DarnellMayberry","twitterText":"RT @NewsOKSports: Reasons to believe Russell Westbrook will sit tonight against Cleveland (via @darnellmayberry): http://t.co/LCxlOj4LkI","twitterProfileImageMini":"http://pbs.twimg.com/profile_images/277780584/meandthecommish_mini.jpg","twitterProfileImageNormal":"http://pbs.twimg.com/profile_images/277780584/meandthecommish_normal.jpg","twitterProfileImageBigger":"http://pbs.twimg.com/profile_images/277780584/meandthecommish_bigger.jpg","fullName":"Darnell Mayberry","gameUpdate":false},{"type":"Article","id":1998814,"originalArticleId":1998814,"title":"Kevin Durant's Scoring Binge Hiding What Makes Him Special NBA Superstar ","tag":"oklahoma-city-thunder","publishedAt":"2014-03-19T21:11:38Z","programmedAt":"2014-03-19T22:05:56Z","headline":"Scoring Binge Hidin
@richardking
richardking / gist:9125719
Created February 20, 2014 23:39
insta2 - model spec
require 'spec_helper'
describe InstagramSyncFollowingWorker do
it 'should import or sync based on number of followers' do
InstagramAccount.stub(:import_or_sync)
VCR.use_cassette 'lib/instagram_user_follows' do
response = Instagram.user_follows
InstagramAccount.should_receive(:import_or_sync).exactly(response.count).times
InstagramSyncFollowingWorker.perform
end
@richardking
richardking / gist:9125546
Created February 20, 2014 23:29
insta3 - controller spec
require 'spec_helper'
describe Admin::TeamStreamsController do
before do
activate_authlogic
end
it_should_behave_like "an action that requires admin login"
context "instagram accounts" do
#!/bin/bash
while true
do
for i in $(grep prod_br_db_slave ~/.ssh/config | sed 's/Host //') ; do sec=$(ssh $i 'mysql -e "show slave status \G" | grep Sec ' | sed "s/Seconds_Behind_Master://"); echo $i; if test $sec -gt 30 ; then echo 'sent email!'; echo $i "delayed" $sec | mail -s 'delay!' [email protected] ; fi & done
done
@richardking
richardking / gist:9102847
Created February 19, 2014 22:17
twitter delete script
trap(:SIGHUP) { reload }
@@stagger = 30
def reload
path = "stagger.txt"
if File.exist?(path)
@@stagger = File.read(path).strip.to_i
puts "@@stagger reloaded with #{@@stagger}"
else
puts "no stagger.txt file found, keeping @@stagger at #{@@stagger}"
@richardking
richardking / gist:9081138
Created February 18, 2014 21:57
Insta2 - everytime FactoryGirl.create(:instagram_account) is called
1)
VCR::Errors::UnhandledHTTPRequestError in 'InstagramSyncFollowersCountWorker should sync followers count'
================================================================================
An HTTP request has been made that VCR does not know how to handle:
GET https://api.instagram.com/v1/users/search.json?access_token=1059553397.20f3831.c5342af9457c4db788d9895db4444ef7&q=bleacherreport
There is currently no cassette in use. There are a few ways
you can configure VCR to handle this request:
@richardking
richardking / gist:9081047
Last active August 29, 2015 13:56
Insta1 - Original InstagramAccount model
class InstagramAccount < ActiveRecord::Base
belongs_to :tag
has_many :instagram_media, :dependent => :destroy
after_create :get_instagram_id
after_save :sync_following
class << self
def import_or_sync(obj)
account = InstagramAccount.find_by_instagram_id(obj["id"]) || InstagramAccount.new