Skip to content

Instantly share code, notes, and snippets.

@jessieay
jessieay / ActiveRecord Cheat Sheet v1
Created July 17, 2012 19:55
Active Record cheat sheet with examples of queries I've needed most so far
ActiveRecord cheat sheet / EXAMPLES
INSTALL
=======
$ gem install activerecord
in GEMFILE: gem ‘activerecord’
REQUIRE
=======
require ‘active_record’
@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.

@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
@jessieay
jessieay / vim
Created October 4, 2012 18:48
VIM vommands
hjkl - move around
:#,#d - deletes between two lines, eg: :10,12d deletes lines 10 through 12
x - delete character
o - insert on next line
O - insert on preceding line
a - insert after cursor
i - go into insert mode
w - move to beginning of next word (also W for whitespace delimited word)
e - move to end of word (also E for whitespace delimited words)
b - move backward to start of word (also B)
@jessieay
jessieay / git
Created October 3, 2012 18:55
thoughtbot Git Process
BEFORE: start trajectory story
* run specific tests wrote (eg: rspec spec/decorators/event_decorator_spec.rb:5)
rake
git status
git diff