Skip to content

Instantly share code, notes, and snippets.

Chris Homer chrishomer

Block or report user

Report or block chrishomer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:fdb32e0bc3498aef7aca
# To try and fix the sort order, switching to an integer instead of time.
integer :listed_at do |item|
original_listed_at_time = nil
original_item = item.original_item if item.original_item_id.present? && item.payout_policy == "upfront"
if original_item && original_item.created_at < Time.parse("April 1 2014")
original_listed_at_time = original_item.listed_at
end
View dropbox_client_tips.rb
# A. Puting a file to dropbox
@db_session.client.put_file("/Some Shared Dropbox Folder the User has access to/my_data_file.csv","#{Rails.root}/tmp/my_data_file.csv")
# B. Getting a file from dropbox (from dropbox site)
contents, metadata = @db_session.client.get_file_and_metadata('/magnum-opus.txt')
open('magnum-opus.txt', 'w') {|f| f.puts contents }
View my_drop_box_session_use.rb
# 1. Create a new record (account email is optional)
@db_session = MyDropboxSession.create({app_key: MyDropboxSession::APP_KEY,
app_secret: MyDropboxSession::APP_SECRET,
account_email: "a_dropbox_email@example.com"})
# 2. Get the authorization url and visit it in your browser and then authorize the Application
@db_session.authorization_url
# 3. After authorizing in the browser, complete the authorization
# - This gets the access token, serializes the session and saves it in the database
View create_my_dropbox_sessions.rb
class CreateMyDropboxSessions < ActiveRecord::Migration
def change
create_table :my_dropbox_sessions do |t|
t.string :app_key
t.string :app_secret
t.string :account_email
t.boolean :authorized, default: false
t.text :serialized_session
t.timestamps
View my_dropbox_session.rb
require "dropbox_sdk"
class MyDropboxSession < ActiveRecord::Base
# This can obviously live anywhere you store your credentials or settings.
APP_KEY = "*********"
APP_SECRET = "%%%%%%%%%"
scope :authorized, where(authorized: true)
View gist:4560471
ItemEvent.where("item_events.created_at > ? AND item_events.created_at < ?",Time.parse("January 15 2013"),Time.parse("January 16 2013")).select("COUNT(DISTINCT item_events.item_id) AS cnt").first.cnt
=> 1979
Item.where("items.created_at > ? AND items.created_at < ?",Time.parse("January 15 2013"),Time.parse("January 16 2013")).count
=> 2739
@chrishomer
chrishomer / gist:3758910
Created Sep 20, 2012
SHOW ENGINE INNODB STATUS
View gist:3758910
| InnoDB | |
=====================================
120920 22:53:10 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 49 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 46401 1_second, 45420 sleeps, 4635 10_second, 70 background, 70 flush
srv_master_thread log flush and writes: 48122
View gist:3758824
+------------------------------------------+-------------+
| Variable_name | Value |
+------------------------------------------+-------------+
| Aborted_clients | 7287 |
| Aborted_connects | 0 |
| Binlog_cache_disk_use | 45 |
| Binlog_cache_use | 1130102 |
| Binlog_stmt_cache_disk_use | 0 |
| Binlog_stmt_cache_use | 0 |
| Bytes_received | 4714 |
View gist:3156321
[
{ "type": "add",
"id": 153001,
"version": 1,
"lang": "en",
"fields": {
"adjustable_waist": 0,
"brand_id": 141,
"brand_name": "Gymboree",
"brand_tier_id": 1,
View gist:2986318
{
bag: {
id: "888888",
code: "01-IND-999999-888888"
}
address: {
name: "John Smith",
line1: "570 Market St",
line2: "4th Floor",
city: "San Francisco",
You can’t perform that action at this time.