Skip to content

Instantly share code, notes, and snippets.

@derwiki
derwiki / pixelpeeper_with_timeouts.rb
Created August 14, 2014 20:36
Example thin JSON API client in Ruby, with one second global timeouts
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 / new-token.rb
Created July 29, 2014 18:51
User#new_token! to create a new random automatic-login token
def new_token!
SecureRandom.hex(16).tap do |random_token|
update_attributes token: random_token
Rails.logger.info("Set new token for user #{ id }")
end
end
@derwiki
derwiki / automatic-login-impl.rb.diff
Last active August 29, 2015 14:04
Generate a token and add the parameter to the link.
diff --git a/app/mailers/reservation_mailer.rb b/app/mailers/reservation_mailer.rb
index 4ee2db4..0f8faf2 100644
--- a/app/mailers/reservation_mailer.rb
+++ b/app/mailers/reservation_mailer.rb
@@ -16,6 +16,8 @@ class ReservationMailer < CameraLendsMailer
def reservation_request_lender(reservation)
@reservation = reservation
+ @owner = reservation.item.owner
+ @owner.new_token!
@derwiki
derwiki / maybe_login_from_token.rb
Last active May 31, 2018 08:59
before_filter that checks for a login token and logs the user in if it's valid
def maybe_login_from_token
Rails.logger.info "maybe_login_from_token: '#{ params[:token] }'"
return if (token = params[:token]).blank?
if (user = User.find_by_token(token))
Rails.logger.info "One time login token used for user #{ user.id }"
sign_in(user)
else
Rails.logger.info "No user found from token: '#{ token }'"
end
@derwiki
derwiki / saucelabs.rb
Last active August 29, 2015 13:56
SauceLabs setup
module Saucelabs
SAUCE_USERNAME = ''
SAUCE_TOKEN = ''
def self.setup_saucelabs_connection!(driver=nil)
WebMock.allow_net_connect!
driver ||= {
capability: :chrome,
platform: 'Windows 8',
version: '',
@derwiki
derwiki / selenium.rake
Created June 27, 2013 18:58
Simple Rake task that will take screenshots of a pre-defined set of URLs in different OS/browser combinations. Relies on SauceLabs for all the hard work of setting up the different testing environments. No automated testing, but helpful to quickly identify visual regressions.
require 'rubygems'
require 'bundler'
require 'RMagick'
include Magick
require 'selenium-webdriver'
URLS = [
'www.apartmentlist.com',
'www.apartmentlist.com/oh/medina',
'www.apartmentlist.com/oh/medina?zip=44256#map/p13063',
var ITERATIONS = 100000,
av = navigator.appVersion;
console.time('indexOf')
for (var i = 0; i < ITERATIONS; i++) {
navigator.appVersion.indexOf("Mobile") > -1
}
console.timeEnd('indexOf')
console.time('regex')
@derwiki
derwiki / javascript-for-vim-refactoring.js
Created May 29, 2013 15:08
Moving faster with Vim (5-minute lightning talk presentation). I wasn't inspired to learn effective command of Vim until I saw some people flying around faster than I thought was possible. The goal of this presentation is to call out how slow "normal" text editing is, and how many keystrokes can be reduced by using increasingly more terse Vim co…
$(function() {
// good opportunity to combine into a single statement
// qq w cw <esc> A, <esc> 0 j q
var a = 10;
var b = 20;
var c = 30;
var d = 40;
var e = 50;
// opportunity to simplify syntax
This administrative assistant will have a variety of responsibilities and duties. I'm the only full time employee at CameraLends, and I also have a day job. I plan to take care of all the programming, but occasionally there are non-technical tasks to outsource:
More specific examples of the type of work include:
- blog posts (1/week, 1-2 hours)
- posting flyers (if in San Francisco / Bay Area)
- cross-referencing pages on CameraLends against other sites (for prices, specifications)
- cleaning up user generated data, making sure Camera listings look appealing.
- responding to customer support emails (1-2 hours/week)
- coordinating with contractors (finding, hiring, getting work handed over)
- general QA of the site -- what works, what doesn't work (1-3 hours/week)
Bower 8mm f/3.5 Fisheye
Canon 1.4x Extender ii accessory
Canon EF 100-300mm f/4.5-5.6 USM Telephoto
Canon EF 100-400mm f/4.5-5.6L IS USM
Canon EF 100mm f/2.8 USM Macro
Canon EF 100mm f/2.8L IS USM Macro Lens
Canon EF 135mm f/2L USM
Canon EF 15mm f/2.8 Fisheye
Canon EF 16-35mm f/2.8L II USM
Canon EF 24-105mm f/4L IS USM