Skip to content

Instantly share code, notes, and snippets.

@chrisyour
chrisyour / Folder Preferences
Created December 4, 2010 20:05
Show hidden files and hidden folders (except .git) in your TextMate project drawer
View Folder Preferences
# Want to show hidden files and folders in your TextMate project drawer? Simple, just modify the file and folder patterns in TextMate's preferences.
# Instructions:
# Go to TextMate > Preferences...
# Click Advanced
# Select Folder References
# Replace the following:
# File Pattern
@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.
View development.rb
# 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 / enumerable_each_slice.html.erb
Created November 21, 2010 16:50
Display collections of records in groups using Ruby's Enumerable's each_slice method.
View enumerable_each_slice.html.erb
# So you have a collection of records you want to display in rows of 3.
# Use Enumerable's each_slice method:
<%= content_tag :div, :class => :thumbs do %>
<% @thumbs.each_slice(3) do |slice| %>
<%= content_tag :div, :class => :thumbs_row do %>
<% slice.each do |thumb| %>
<%= render 'thumb' %>
<% end %>
@chrisyour
chrisyour / s3.md
Last active March 15, 2018 21:41
AWS S3 Command Line Tool for Backups
View s3.md

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 / _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.
View _twitter_wjs.js.coffee
# 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 / gist:6127005
Created July 31, 2013 23:04
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
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.
View Remove Textmate 2 Cache
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+)
View gist:4047680
// 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)
View associations.rb
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.
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")
end
end