Skip to content

Instantly share code, notes, and snippets.

View ryanjones's full-sized avatar

Ryan Jones ryanjones

View GitHub Profile
@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
@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"
@seanlilmateus
seanlilmateus / gist:7777282
Last active December 30, 2015 04:39
THREAD-SAFETY for every one... simple way to wrap any object with a thread-safe wrapper,
class << NSProxy
def method_added(meth)
end
def inherited(klass)
end
end
class Proxy < NSProxy
def self.const_missing(n)
@seanlilmateus
seanlilmateus / evernote.rb
Last active January 25, 2016 19:24
ScriptingBridge with MacRuby or Rubymotion
#!/Library/RubyMotion/bin/ruby -wKUW0
# if your using MacRuby you might change this to
# => #!/usr/bin/env macruby -wKUW0
framework 'Foundation'
framework 'ScriptingBridge'
# the original is part of an arstechnica article by Ryan
# SOURCE: http://arstechnica.com/apple/2011/09/tutorial-os-x-automation-with-macruby-and-the-scripting-bridge/
# this script with get your favourite songs and create a Evernote Note # German and English
@chrismo
chrismo / README.md
Last active October 19, 2016 20:32
Bundler 1.3 --binstubs vs. Rails 4

On a clean Rails 4 install with Bundler 1.3.0, using --binstubs causes competition between Rails and Bundler for the contents of bin/rails (and bin/rake).

Just running bundle will rewrite the Rails version of bin/rails to a version that doesn't work.

The fix is to use the new bundle binstubs <gemname> command.

(see rails/rails#8974)

@mingderwang
mingderwang / gist:10963621
Created April 17, 2014 08:14
install s3cmd on mac os x
download tarball (http://s3tools.org/download)
$ sudo python setup.py install
$ s3cmd --configure
Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.
Access key and Secret key are your identifiers for Amazon S3
@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
@mperham
mperham / after.rb
Created July 4, 2012 19:30
Thread-friendly shared connection
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@ats
ats / mover.rb
Created April 27, 2013 21:48
Command-line tool for browsing, downloading and uploading using the mover.io API. Requires a move.io account, a linked storage space (i.e. a "connector" such as Dropbox) and private user API keys available with the mover.io account.
#!/usr/bin/ruby
# mover.rb
# general purpose utility for finding, getting and uploading files using the mover.io API.
# YAML config file is required in ~/.mover, contains API IDs and keys provided by mover.io. Example db.yaml:
# ---
# connector: mover_connector_ID
# app_id: mover_user_app_ID
# app_secret: mover_user_secret_key
@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