Skip to content

Instantly share code, notes, and snippets.

@chrisyour
chrisyour / s3.md
Last active March 15, 2018 21:41
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
chrisyour / gist:11183907
Created April 22, 2014 15:36
Build Help: Get Started with Rails
# 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.
PATH="/Applications/Postgres.app/Contents/Versions/9.3/bin:$PATH"
@chrisyour
chrisyour / _twitter_wjs.js.coffee
Created January 10, 2014 07:29
CoffeeScript to load Twitter's twitter-wjs JavaScript. Tip: Any link that goes to an intent URL (like http://twitter.com/intent/tweet) 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)
js.id = id
js.src = "//platform.twitter.com/widgets.js"
fjs.parentNode.insertBefore js, fjs
window.twttr || t = { _e: [], ready: (f)-> t._e.push(f) }
@chrisyour
chrisyour / development.rb
Created September 9, 2013 21:47
Limit the size of your development.log and test.log files in your Rails 4 and Rails 3 apps.
# Add this to config/environments/development.rb
# Limit your development log file to 5 MB
config.logger = Logger.new(config.paths["log"].first, 1, 5242880) # 5 megabytes
@chrisyour
chrisyour / gist:6127005
Created July 31, 2013 23:04
Compass working with a Rails 4 app using the rails4-hack branch on GitHub.
# 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
chrisyour / Remove Textmate 2 Cache
Created July 29, 2013 19:31
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.
rm -rf ~/Library/Application\ Support/TextMate/Cache/*
@chrisyour
chrisyour / gist:4047680
Created November 9, 2012 19:27
Colored Bullets SCSS Mixin (works in IE 8+)
// Simple SCSS mixin for adding colored bullets to your <li> elements
@mixin colored-bullet($color){
list-style:none;
text-indent:-19px; // Adjust the text-indent to your specific needs based on your font-size and the typeface you're using
&:before{
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
chrisyour / associations.rb
Created April 8, 2011 16:59
Change to ActiveRecord's associations.rb (around line 1500)
if reflection.options[:conditions]
reflection_table = (reflection.options[:class_name] || reflection.options[:source] || reflection.name).gsub('::', '_').tableize
if reflection.options[:conditions].to_s.include?("#{reflection_table}")
send(through.name).select("DISTINCT #{through.quoted_table_name}.#{primary_key}").joins(reflection.options[:source]).where(reflection.options[:conditions]).map! { |r| r.send(primary_key) }
else
send(through.name).select("DISTINCT #{through.quoted_table_name}.#{primary_key}").where(reflection.options[:conditions]).map! { |r| r.send(primary_key) }
end
else
send(through.name).select("DISTINCT #{through.quoted_table_name}.#{primary_key}").map! { |r| r.send(primary_key) }
@chrisyour
chrisyour / date_validator.rb
Created March 8, 2011 19:37
Simple date validator for Rails 3.
# 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")
end
end
@chrisyour
chrisyour / post_spec.rb
Created March 6, 2011 17:22
Super handy way to modify and return the instance of an object
# 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)