Skip to content

Instantly share code, notes, and snippets.

View stevenharman's full-sized avatar

Steven Harman stevenharman

View GitHub Profile
@pcreux
pcreux / postgresql.conf
Last active August 29, 2015 13:56
Speed up Rails test suite!
fsync = off
synchronous_commit = off
full_page_writes = off
@searls
searls / postgres-regexp_replace.md
Created August 20, 2014 20:01
regex find-and-replace in Postgresql queries

Regex replacements in postgres

I had to make a simple change to all the strings in a table, and I was dreading having to load them into memory, iterate over them, searching for the string, and updating replacements. So instead, I learned that postgresql can actually do regex replacements in an update statement.

For example, if I have a links table with a url column with a bunch of URLs erroneously ending in "?":

Link.where("long_url like '%?'").count #=> 487185
@searls
searls / heroku-set-cedar
Last active August 29, 2015 14:05
Blindly upgrade from Heroku's Bamboo stack to Cedar stack
#!/bin/bash -e
PREV_PWD=`pwd`
mkdir -p "$HOME/tmp"
cd "$HOME/tmp"
echo "-----> Cloning into $1"
heroku git:clone -a $1
cd $1
echo "-----> Setting stack to cedar"

Ember Cheatsheet

1. Templates / Handlebars

1.1 The Application Template: (Think layout.html.erb)

<script type="text/x-handlebars">
  <header>..</header>
  {{outlet}} <-- this displays the route specific template (Rails: yield)
  <footer>..</footer>
# show keyboard shortcuts (app/views/shared/_keyboard_shortcuts_help.slim)
# display help
Shortcutter.Keyboard.bindShortcut '?', 'Show/hide this help dialog', ->
$('#keyboard-shortcuts-help').modal('toggle')
false
# focus on search
Shortcutter.Keyboard.bindShortcut '/', 'Focus on the "Search" form at the top', ->
@brson
brson / gist:8da87f07d463fc4413e0
Created January 6, 2015 02:58
Fixing the mess from last night's bad .pkg
Delete this crap from /usr/local by hand:
components
COPYRIGHT
install.sh
LICENSE-APACHE
LICENSE-MIT
manifest-cargo.in
manifest-rustc.in
manifest-rust-docs.in
@stevenharman
stevenharman / constraint_staff.rb
Last active September 2, 2015 16:41
Use Routing Constraints to limit access to Rails Routes. An example from Brewdega Cellar app.
module Constraint
class Staff
def matches?(request)
warden(request).authenticated? &&
warden(request).user.staff?
end
private
#!/bin/bash
set -e
if [ $# -gt 0 ]; then # we have args
filename=$1
(set +e; grep -r 'spec_helper' $filename) > /dev/null
if [ $? -eq 1 ]; then # no match; we have a stand-alone spec
standalone_spec=1
fi
@remi
remi / screen.css
Created May 17, 2011 19:57
Catchy <span class="translation_missing"> elements
.translation_missing {
background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0.00, red), color-stop(16%, orange), color-stop(32%, yellow), color-stop(48%, green), color-stop(60%, blue), color-stop(76%, indigo), color-stop(1.00, violet));
color: #fff;
text-shadow: 1px 1px 0px #000;
font-family: "Comic sans MS";
padding: 0.2em 0.4em;
outline: 2px dashed red;
}
task :cron => :environment do
DatabaseBackup.back_up_to_s3!
end