Skip to content

Instantly share code, notes, and snippets.

View ryanjones's full-sized avatar

Ryan Jones ryanjones

View GitHub Profile
@cflipse
cflipse / Post.rb
Last active October 1, 2019 15:56
External Validations using only ActiveModel
require 'active_model'
# Most of this is the basic boilerplate described in the docs for active_model/errors; ie, the bare minimum
# a class must have to use AM::Errors
class Post
extend ActiveModel::Naming
attr_reader :errors
attr_accessor :title, :author, :publication_date
@threetee
threetee / unicorn_wrapper.sh
Created January 20, 2012 19:52
Wrapper to allow runit to send signals to the unicorn master even when its PID changes
#!/bin/sh
set -e
APP=$1
APP_PATH="/srv/${APP}/current"
RAILS_ENV=$2
UNICORN_CONFIG="/etc/unicorn/${APP}.rb"
UNICORN_PID_FILE="/tmp/unicorn.${APP}.pid"
@jcasimir
jcasimir / sessions_and_conversations.markdown
Created September 11, 2011 23:07
Sessions and Conversations in Rails 3

Sessions and Conversations

HTTP is a stateless protocol. Sessions allow us to chain multiple requests together into a conversation between client and server.

Sessions should be an option of last resort. If there's no where else that the data can possibly go to achieve the desired functionality, only then should it be stored in the session. Sessions can be vulnerable to security threats from third parties, malicious users, and can cause scaling problems.

That doesn't mean we can't use sessions, but we should only use them where necessary.

Adding, Accessing, and Removing Data

@jpmckinney
jpmckinney / utc_offset_to_friendly_identifier.rb
Created January 5, 2011 05:18
Changes from UTC offset to time zone identifier in Rails
# blog post: http://blog.slashpoundbang.com/post/2605632137/changing-from-utc-offset-to-time-zone-identifier-in
identifier = {
-11 => 'Samoa',#International Date Line West, Midway Island
-10 => 'Hawaii',
-9 => 'Alaska',
-8 => 'Pacific Time (US & Canada)',#Tijuana
-7 => 'Mountain Time (US & Canada)',#Arizona, Chihuahua, Mazatlan
-6 => 'Central Time (US & Canada)',#Central America, Guadalajara, Mexico City, Monterrey, Saskatchewan
-5 => 'Eastern Time (US & Canada)',#Bogota, Indiana (East), Lima, Quito