Skip to content

Instantly share code, notes, and snippets.

@derwiki
derwiki / seo.py
Last active August 29, 2015 14:16
Simple class to scrape Google search results. Useful for scripting reports of SEO rankings.
import pprint
import re
import sys
import urllib
import urllib2
# pip install pyquery
try:
from pyquery import PyQuery as pq
except:
$ sslmate buy *.cameralends.com
If you don't have an account yet, visit https://sslmate.com/signup
Enter your SSLMate username: cameralends
Enter your SSLMate password: **************
Authenticating... Done.
Tip: if you don't want to have to type your password every time, you can run 'sslmate link' to link this system with your account.
Generating private key... Done.
Generating CSR... Done.
Submitting order...
@derwiki
derwiki / bulk_insert.rb
Created November 3, 2014 19:23
Comparing runtime characteristics of individual transactions, one transaction, and one statement.
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 }
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"
)
@derwiki
derwiki / ffmpeg-output.log
Created September 19, 2014 03:15
Sample output of ffmpeg encoding a time lapse.
$ ffmpeg -f image2 -r 24 -pattern_type glob -i '*.JPG' -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" -c:v libx264 time-lapse.mp4
ffmpeg version 2.2.4 Copyright (c) 2000-2014 the FFmpeg developers
built on Jun 23 2014 16:31:17 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libavresample 1. 2. 0 / 1. 2. 0
@derwiki
derwiki / gmail-invoice-parse.rb
Created September 18, 2014 03:53
Ruby script utilizing the ruby-gmail gem that allows for searching and downloading Gmail messages by label. This implementation is looking for invoice emails and parsing the amount of money that was transferred.
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: /
@derwiki
derwiki / api_response.json
Created August 16, 2014 03:31
Sample API response JSON.
{
data: {
results: [
{
camname: "EOS 5D Mark III",
cammake: "Canon",
camexifid: "CANON EOS 5D MARK III",
lensname: "Canon EF 24-105mm f/4 L IS USM",
author_name: null,
author_url: null,
@derwiki
derwiki / pixel_peeper_integration.rb
Created August 16, 2014 03:24
Example of using the lightweight PixelPeeper API.
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
@derwiki
derwiki / pixelpeeper_with_timeouts_and_caching.rb
Created August 14, 2014 21:27
Example thin JSON API client in Ruby, with one second global timeouts and local API response Redis caching
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
@derwiki
derwiki / pixelpeeper_basic.rb
Created August 14, 2014 20:37
Example thin JSON API client in Ruby
require 'httparty'
class PixelPeeper
include HTTParty
base_uri 'www.pixel-peeper.com'
def api_key
ENV['PIXELPEEPER_API_KEY']
end