Skip to content

Instantly share code, notes, and snippets.

@jessieay
jessieay / home_office.md
Last active August 24, 2017 23:21
Jessie's home office setup
@jessieay
jessieay / google_hangouts_audio_restart.sh
Last active April 19, 2017 19:34
Command to reset system sound for Google Hangouts
sudo kill -9 `ps ax|grep 'coreaudio[a-z]' |awk '{print $1}'`
@jessieay
jessieay / til_9_20_2016.md
Last active September 20, 2016 22:09
A GitHub lesson, and a Rails lesson (for Heroku and Cloud Foundry)

Lessons learned are enumerated at the bottom for those who want the tl;dr

Background:

Lately, I've noticed that the Rails app I am working on does this funny little thing where it logs everyone out every time we deploy. Sorry, ppl!

Investigation

I wanted to fix this, and so I went looking into our auth system. Turns out, we store the user's id in a session var and find the user based on that value. WHAT? You might say. Well..it is totally OK because my friend Rails encrypts all session vars.

To prevent session hash tampering, a digest is calculated from the session with a server-side secret (secrets.secret_token) and inserted into the end of the cookie.

namespace :ckeditor do
desc 'Create nondigest versions of all ckeditor digest assets'
task :create_nondigest_assets do
fingerprint = /\-([0-9a-f]{32})\./
for file in Dir['public/assets/ckeditor/**/*']
next unless file =~ fingerprint
nondigest = file.sub(fingerprint, '.')
filename = nondigest.sub('public/assets/', '').sub(/.gz$/, '')
@jessieay
jessieay / gist:11057713
Created April 18, 2014 18:23
The X of X List
Xerox
Groupon
Kleenex
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.015 000.015: --- VIM STARTING ---
000.132 000.117: Allocated generic buffers
000.599 000.467: locale set
000.606 000.007: window checked
001.068 000.462: inits 1
001.076 000.008: parsing arguments
@jessieay
jessieay / spec for field entry
Last active December 29, 2015 18:59
field entry spec
require 'spec_helper;
describe FieldEntry, '#to_hash' do
it 'returns the correct hash format' do
field_entry = FieldEntry.new("room",["a","b,"c"]).to_hash
expect(field_entry).to eq { name: 'room', values: [ "a", "b", "c"] }
end
end
@jessieay
jessieay / gist:7489216
Created November 15, 2013 18:25
Restoring local database from Heroku
$ heroku pgbackups:capture --expire --app APP_NAME
$ curl -o latest.dump `heroku pgbackups:url --app APP_NAME`
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -d DEVELOPMENT_DATABASE_NAME latest.dump
require 'spec_helper'
describe RecommendationHelper, '#user_name' do
it 'returns the name if the user has a name' do
user = create(:user)
user.stubs(:name).returns('Jane Doe')
ask = create(:ask, user: user)
user_name = user_name(ask)
@jessieay
jessieay / merge.rb
Created June 21, 2013 16:35
custom paperclip processor - lives in lib/paperclip_processors
module Paperclip
class Merge < Processor
def initialize file, options = {}, attachment = nil
super
@format = File.extname(@file.path)
@basename = File.basename(@file.path, @format)
@files = attachment.instance.files
end
def make