Skip to content

Instantly share code, notes, and snippets.

View stevenharman's full-sized avatar

Steven Harman stevenharman

View GitHub Profile
@nybblr
nybblr / rails-with-bower.md
Last active November 27, 2023 15:41
Rails with Bower. Without bower-rails.
# 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', ->

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>
@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"
@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
@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
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
@KieranP
KieranP / 1 app-models-session.rb
Last active October 8, 2020 16:11
A Ruby on Rails implementation of a Database and Cookie hybrid session storage for Devise that supports session revocation and storage of session ip and user agent for security (similar to Github)
# A user session class, a simplified mix of the following code samples:
# * https://github.com/blog/1661-modeling-your-app-s-user-session
# * http://www.jonathanleighton.com/articles/2013/revocable-sessions-with-devise/
class Session < ActiveRecord::Base
# Uncomment if you use Hobo Fields, else add these yourself
# fields do
# session_id :string, :index => true, :unique => true
# accessed_at :datetime
# user_ip :string
@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
# Goal: put a non-Rails-aware Ruby library using normal `require`s in
# lib/sim. Have it transparently reloaded between requests like Rails app
# code is.
#
# The code here goes inside of your configure block in
# config/environments/development.rb. There are two parts, commented inline.
# Reload code whenever the simulator changes.
config.watchable_dirs["lib/sim"] = [:rb]
config.watchable_files << "lib/sim.rb"