This file contains 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
require 'httparty' | |
class PixelPeeper | |
include HTTParty | |
base_uri 'www.pixel-peeper.com' | |
default_timeout 1 # hard timeout after 1 second | |
def api_key | |
ENV['PIXELPEEPER_API_KEY'] | |
end |
This file contains 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 example_pictures_for(gear) | |
pp = PixelPeeper.new | |
if gear.pp_lens_id.present? | |
pp.examples(lens_id: gear.pp_lens_id) | |
elsif gear.pp_camera_id.present? | |
pp.examples(camera_id: gear.pp_camera_id) | |
else | |
[] | |
end.take(8) | |
end |
This file contains 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
require 'gmail' | |
label = 'transactional/payment' | |
Gmail.new(username, password) do |gmail| | |
puts "Emails that match label '#{ label }'" | |
lender_profit = 0 | |
gmail.mailbox(label).emails.each do |email| | |
message = email.message | |
next if message.subject =~ /^Re: / | |
next if message.subject =~ /^Fwd: / |
This file contains 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
require 'gmail' | |
label = 'transactional/payment' | |
Gmail.new(username, password) do |gmail| | |
puts "Emails that match label '#{ label }'" | |
lender_profit = 0 | |
gmail.mailbox(label).emails.each do |email| | |
message = email.message | |
next if message.subject =~ /^Re: / | |
next if message.subject =~ /^Fwd: / |
This file contains 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 pay_lender!(token = nil) | |
fail unless lender.stripe_recipient_id || token | |
recipient = lender.stripe_recipient_id || | |
create_recipient!(token, lender.name).id | |
Stripe::Transfer.create( | |
amount: (lender_profit * 100).round, | |
currency: "usd", | |
recipient: lender.stripe_recipient_id, | |
statement_description: "CameraLends Lending" | |
) |
This file contains 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 insert_many | |
1000.times { SeoRank.create! } | |
end | |
start = Time.now | |
ActiveRecord::Base.transaction { insert_many } | |
puts "N transactions: #{ Time.now - start }" | |
start = Time.now | |
ActiveRecord::Base.transaction { insert_many } |
This file contains 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.new(ActiveSupport::LogSubscriber) do | |
def sql(event) | |
return | |
query = event.payload[:sql] | |
if query =~ /SELECT/ | |
Rails.logger.info "Traced query: #{query}" | |
Rails.logger.info '!stacktrace!begin' | |
# Rails.logger.info Rails.backtrace_cleaner.clean(caller).join("\n") | |
Rails.logger.info Rails.backtrace_cleaner.clean(caller).first | |
Rails.logger.info '!stacktrace!end' |
This file contains 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
#!/bin/bash | |
# usage ./s3.sh filename.ext remote/path/filename.ext | |
S3_KEY="REDACTED" | |
S3_SECRET="REDACTED" | |
S3_BUCKET="REDACTED" | |
REMOTE_PATH=$2 | |
date=$(date +"%a, %d %b %Y %T %z") | |
acl="x-amz-acl:public-read" |
This file contains 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
#!/app/bin/ruby | |
require 'platform-api' | |
cleardb_url = ENV['CLEARDB_DATABASE_URL'] | |
if cleardb_url.nil? || cleardb_url == '' | |
puts "Error: CLEARDB_DATABASE_URL not set" | |
exit -1 | |
end |
This file contains 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
require 'parser/current' | |
class Processor < AST::Processor | |
attr_accessor :verbose | |
def initialize(*args) | |
super | |
self.verbose = false | |
end |