Skip to content

Instantly share code, notes, and snippets.

@tpitale
tpitale / deeply_hash.rb
Created August 25, 2014 18:12
Using default proc to deeply, arbitrarily nest new Hash
# http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-default_proc-3D
h = Hash.new {|hash, key| hash[key] = Hash.new(&hash.default_proc)}
h[:foo][:bar][:baz][:bat] = "hello"
p h
#=> {:foo=>{:bar=>{:baz=>{:bat=>"hello"}}}}
@pepelsbey
pepelsbey / hocus.scss
Last active March 1, 2024 11:03
Simple “Hocus” Sass @mixin for :hover and :focus pseudos. Makes them easier to write and you’ll never forget to specify both.
@mixin hocus {
&:hover,
&:focus {
@content;
}
}
// Before
E {
&:hover,
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@ka8725
ka8725 / dbconfig.rake
Last active July 28, 2016 10:03
database.yml generator. Global Rake implementation
require 'yaml'
desc 'Generates database.yml, optional arguments: [adapter, user, password]'
task :dbconfig => 'database.yml'
file 'database.yml', [:adapter, :username, :password] do |t, args|
Dir.chdir('config')
args.with_defaults(:project_path => Dir.pwd)
DBConfigGenerator.new(t, args).generate
end
@pcreux
pcreux / Gemfile
Last active December 11, 2023 20:24
Fast Rails + Heroku Configuration
group :production do
gem 'unicorn'
# Enable gzip compression on heroku, but don't compress images.
gem 'heroku-deflater'
# Heroku injects it if it's not in there already
gem 'rails_12factor'
end
@alistairholt
alistairholt / pdrop.sh
Created October 25, 2013 16:53
Rails & Postgres: Better dropping of the database – https://coderwall.com/p/qtkppg
pgdrop() {
RAILS_ENV=$1
: ${RAILS_ENV:="development"}
RUBY_SCRIPT=$(cat <<SCRIPT
db_config_path = File.expand_path("config/database.yml", Dir.getwd)
abort 'NO_CONFIG' unless File.exists?(db_config_path)
db_config = YAML.load(File.open(db_config_path))["$RAILS_ENV"]
abort 'NO_POSTGRES' unless db_config["adapter"] == "postgresql"
abort db_config["database"]
SCRIPT)
@trey
trey / alfred-sparkfile.md
Last active December 13, 2015 21:48
Alfred script to append to your Sparkfile

Alfred script to append to your Sparkfile

[Sparkfiles][1] are [great][2].

  1. Create a new Shell Script Extension.
  2. Give it the Keyword "spark".
  3. Click the "Advanced" button above the "Command" textarea and deselect "Spaces" under "Escaping".
  4. Close the Advanced dialog and paste this script into the "Command" textarea.
@trey
trey / mysql_commands.md
Last active December 13, 2015 18:29
Basic MySQL Commands

Basic MySQL Commands

Create a database.

$ mysqladmin -u[username] create [database name]

Dump a database.

@erutan
erutan / Homebrew.md
Last active December 10, 2015 21:48 — forked from alanivey/Homebrew.md
Installing a custom MAMP environment on OS X via Homebrew

Installing a custom MAMP environment on OS X via Homebrew

Prerequisites

Xcode

Go to http://developer.apple.com/downloads, log in with your Apple ID (free) and download the newest version of either Command Line Tools (OS X Lion) for Xcode or Command Line Tools (OS X Mountain Lion) for Xcode. Run the installer in the dmg and you'll have the LLVM compiler, make, and other build tools.

XQuartz

@trey
trey / gist:4403230
Last active April 19, 2017 17:59
No more editing VirtualHosts manually
# [your username].conf
<VirtualHost *>
VirtualDocumentRoot /Users/[your username]/Sites/%-2+
</VirtualHost>