Skip to content

Instantly share code, notes, and snippets.

View matthutchinson's full-sized avatar
🧐
`¯\_(ツ)_/¯`

Matthew Hutchinson matthutchinson

🧐
`¯\_(ツ)_/¯`
View GitHub Profile
@matthutchinson
matthutchinson / launch_instance.rb
Created January 23, 2012 15:10
Launching EC2 instance with aws-sdk gem
#!/usr/bin/ruby
# README
# gem install aws-sdk
# add this to bashrc
# export HT_DEV_AWS_ACCESS_KEY_ID=????
# export HT_DEV_AWS_SECRET_ACCESS_KEY=????
# put your pem file in ~/.ssh and chmod 0400
# for more info see; https://rubygems.org/gems/aws-sdk
@matthutchinson
matthutchinson / profiler.rb
Created March 15, 2012 09:42
Profiling with ruby-prof
require 'rubygems'
require 'ruby-prof'
def slideview_image_url(photo)
if CDN_OPTIONS && CDN_OPTIONS[:s3_host_alias]
hosts = Array.wrap(CDN_OPTIONS[:s3_host_alias])
host = hosts[photo.id % hosts.size]
"http://#{host}/photos/images/#{photo.id}/search2.jpg"
else
"/system/images/#{photo.id}/search2/#{photo.image_file_name}"
@matthutchinson
matthutchinson / fakeout.rb
Created May 10, 2012 16:59
fake.rake - a takeout approach and rake task that generates some random fake data for a rails app (using ffaker)
# place this in lib/fakeout.rb
require 'ffaker'
module Fakeout
class Builder
FAKEABLE = %w(User Product)
attr_accessor :report
@matthutchinson
matthutchinson / .vimrc
Last active December 17, 2015 14:49
Quickly google for something in vim (uses visual text selection for the query)
" get visually selected words/lines
function! GetVisualSelection()
let [lnum1, col1] = getpos("'<")[1:2]
let [lnum2, col2] = getpos("'>")[1:2]
let lines = getline(lnum1, lnum2)
let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][col1 - 1:]
return join(lines, ' ')
endfunction
# Returns a score for last 10 bookings' acceptance rate
# If 1 booking rejected over past 10 bookings, return 0.5
# If 2 bookings rejected, return 0.0
def booking_acceptance_score
total_bookings_to_be_considered = 10
booking_ids = []
offset = 0
while booking_ids.length < total_bookings_to_be_considered do
# Fetch histories one by one
# WARNING: fragment cache is no longer cleared on deploy to clear completely
# use a version key or bump FRAGMENT_CACHE_VERSION above
def fragment_cache(name, options = {}, &block)
old_within_fragment = @within_fragment
@within_fragment = true
# trace execution for NewRelic
CachingHelper.trace_execution_scoped(["Custom/Fragment cache overhead: #{name}"]) do
if_conditions = Array.wrap(options[:if])
unless_conditions = Array.wrap(options[:unless])
[mysqld]
thread_concurrency = 16
#log-bin=mysql-bin
#binlog_format=mixed
innodb_data_file_path = ibdata1:100M:autoextend
innodb_buffer_pool_size = 1024M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 256M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 2
@matthutchinson
matthutchinson / gem-public_cert.pem
Created June 3, 2013 11:11
My public gem certificate, for installing my gems with the HighSecurityPolicy
-----BEGIN CERTIFICATE-----
MIIDdDCCAlygAwIBAgIBATANBgkqhkiG9w0BAQUFADBAMQ0wCwYDVQQDDARtYXR0
MRowGAYKCZImiZPyLGQBGRYKaGlkZGVubG9vcDETMBEGCgmSJomT8ixkARkWA2Nv
bTAeFw0xMzA2MDMxMDA0NDNaFw0xNDA2MDMxMDA0NDNaMEAxDTALBgNVBAMMBG1h
dHQxGjAYBgoJkiaJk/IsZAEZFgpoaWRkZW5sb29wMRMwEQYKCZImiZPyLGQBGRYD
Y29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApUgO+NlewgetOcmX
8kk5IiISAmGGYqoFrDnzO7/NGjlWcSit91hZszadsQ00OM9h30WMDqSGPlwt2qVL
CQShDjOTx4PQcN9O8PchlhLow/wNVfB5b5sYQX3aDIiIoSLViQt+zquPhTHExN4X
HJJFxwUVIQot0JHV7mh9jApu+RJIpiVPM0is18NnOC2BIXjrGYxqHr7cG4BafvLz
tNTmPtpnp+bxKtp/bGP0wRtPSU9jX/a3V1p1DyI48O5wDLzctXJq/I088sTmB0Ao
# /usr/local/etc/nginx/nginx.conf
worker_processes 4;
events {
worker_connections 1024;
}
http {
server {
listen 443 ssl;
server_name housetrip.dev;
root /u/apps/housetrip/public;
index index.html index.htm;
### SSL log files ###
access_log logs/housetrip.dev-ssl-access.log;
error_log logs/housetrip.dev-ssl-error.log;