Skip to content

Instantly share code, notes, and snippets.


Chris Your chrisyour

View GitHub Profile
chrisyour /
Last active Mar 15, 2018
AWS S3 Command Line Tool for Backups

How to quickly copy an AWS S3 bucket to your local hard drive (without FTP):

aws s3 sync s3://mybucket .

The Problem

Using FTP to backup a large S3 bucket is slow. That's because FTP creates a new request for each file, downloads the file, and closes the request. That adds a lot of time to your download.

chrisyour / gist:11183907
Created Apr 22, 2014
Build Help: Get Started with Rails
View gist:11183907
# Open bash.rc in Terminal using the 'mate' command
mate ~/.bashrc
# Do you have this line in your .bashrc file? The PostgresApp should have added PostgresApp to your PATH.
chrisyour /
Created Jan 10, 2014
CoffeeScript to load Twitter's twitter-wjs JavaScript. Tip: Any link that goes to an intent URL (like acts like a Twitter button with all the Widget-wjs functionality with events, so you can customize the look of your button without having to use the Twitter generated iFrame buttons.
# Load Twitter Widgets
window.twttr = ((d, s, id) ->
js = undefined
fjs = d.getElementsByTagName(s)[0]
unless d.getElementById(id)
js = d.createElement(s) = id
js.src = "//"
fjs.parentNode.insertBefore js, fjs
window.twttr || t = { _e: [], ready: (f)-> t._e.push(f) }
chrisyour / development.rb
Created Sep 9, 2013
Limit the size of your development.log and test.log files in your Rails 4 and Rails 3 apps.
View development.rb
# Add this to config/environments/development.rb
# Limit your development log file to 5 MB
config.logger =["log"].first, 1, 5242880) # 5 megabytes
chrisyour / gist:6127005
Created Jul 31, 2013
Compass working with a Rails 4 app using the rails4-hack branch on GitHub.
View gist:6127005
# Gemfile
gem 'rails', '4.0.0'
gem 'pg'
gem 'sass-rails', '~> 4.0.0'
gem 'compass-rails', github: 'Compass/compass-rails', branch: 'rails4-hack'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
# etc...
# config/initializers/compass.rb
chrisyour / Remove Textmate 2 Cache
Created Jul 29, 2013
If your bundles start acting funny and aren't loading properly, you can always remove TextMate's cache and start again. For example, the basic HTML indenting features in Textmate 2 suddenly vanished on me along with some other HTML commands I use everyday. I removed the cache folder and restarted Textmate 2 and everything was back to normal.
View Remove Textmate 2 Cache
rm -rf ~/Library/Application\ Support/TextMate/Cache/*
chrisyour / gist:4047680
Created Nov 9, 2012
Colored Bullets SCSS Mixin (works in IE 8+)
View gist:4047680
// Simple SCSS mixin for adding colored bullets to your <li> elements
@mixin colored-bullet($color){
text-indent:-19px; // Adjust the text-indent to your specific needs based on your font-size and the typeface you're using
content:"\002022\00a0\00a0\00a0"; // Add a bullet character and three spaces before your <li> content starts
color:$color; // Add color to the bullet
chrisyour / associations.rb
Created Apr 8, 2011
Change to ActiveRecord's associations.rb (around line 1500)
View associations.rb
if reflection.options[:conditions]
reflection_table = (reflection.options[:class_name] || reflection.options[:source] ||'::', '_').tableize
if reflection.options[:conditions].to_s.include?("#{reflection_table}")
send("DISTINCT #{through.quoted_table_name}.#{primary_key}").joins(reflection.options[:source]).where(reflection.options[:conditions]).map! { |r| r.send(primary_key) }
send("DISTINCT #{through.quoted_table_name}.#{primary_key}").where(reflection.options[:conditions]).map! { |r| r.send(primary_key) }
send("DISTINCT #{through.quoted_table_name}.#{primary_key}").map! { |r| r.send(primary_key) }
chrisyour / date_validator.rb
Created Mar 8, 2011
Simple date validator for Rails 3.
View date_validator.rb
# Validator:
# /app/validators/date_validator.rb
class DateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value.to_s =~ /^\d{4}-\d{2}-\d{2}$/i
record.errors[attribute] << (options[:message] || "is an invalid date")
chrisyour / post_spec.rb
Created Mar 6, 2011
Super handy way to modify and return the instance of an object
View post_spec.rb
# Ruby 1.9
# Object.tap
# Here we use tap to set the post factory's author (since Factory Girl doesn't create singleton instances).
# Using tap passes a block where you can "tap" into the object.
# At the end of the block, the object is returned.
let(:author) { Factory(:author) }
let(:post) {
Factory(:post).tap do |p|
post.update_attribute(:author, author)