Skip to content

Instantly share code, notes, and snippets.

@diego-aslz
diego-aslz / left_join.rb
Last active May 10, 2016 15:59
Method to do a LEFT OUTER JOIN on an ActiveRecord model class.
class ActiveRecord::Base
# Does a left join through an association. Usage:
#
# Book.left_join(:category)
# # SELECT "books".* FROM "books"
# # LEFT OUTER JOIN "categories"
# # ON "books"."category_id" = "categories"."id"
#
# It also works through association's associations, like `joins` does:
#
@dankeezer
dankeezer / kiosk
Last active September 12, 2018 15:09
AppleScript + directions to auto-launch Chrome in full-screen at startup.
# I'd just give you the .app but you need to change the code to the correct URL.
## Create the kiosk App
# using AppleScript Editor create a script called “kiosk”
# here’s the code
do shell script "open '/Applications/Google Chrome.app' http://phhhoto.com/d/websterhall/5/2"
tell application "Google Chrome" to activate
@ryansobol
ryansobol / gist:5252653
Last active November 22, 2023 11:53
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@josevalim
josevalim / 0_README.md
Created September 13, 2012 21:52
Sinatra like routes in Rails controllers

Sinatra like routes in Rails controllers

A proof of concept of having Sinatra like routes inside your controllers.

How to use

Since the router is gone, feel free to remove config/routes.rb. Then add the file below to lib/action_controller/inline_routes.rb inside your app.

class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@acwright
acwright / gist:1944639
Created February 29, 2012 21:40
Sinatra / ActionMailer / Sendgrid / Heroku
require 'sinatra'
require 'action_mailer'
class Mailer < ActionMailer::Base
def contact
mail(
:to => "test@example.com",
:from => "test@example.com",
:subject => "Test") do |format|
format.text
@kaelig
kaelig / application.js
Created January 10, 2012 10:43
Open external links and PDFs in a new window or tab
$(document).ready(function() {
// Open external links in a new window or tab
$(document).on('click', 'a[rel$="external"]', function() {
$(this).attr('target', "_blank");
});
$(document).on('click', 'a[href$=".pdf"]', function() {
$(this).attr('target', "_blank");
});
// Open all urls that don't belong to our domain in a new window or tab
$(document).on('click', "a[href^='http:']:not([href*='" + window.location.host + "'])", function() {
@rke
rke / devise_patch.rb
Created July 15, 2011 01:49
email change notification for devise based on https://github.com/Mandaryn's solution
module Devise
module Models
# This just allows valid_password to be called if encrypted_password is blank.
# The code exists in devise-1.3 and later, this just backports it to out 1.2.1
module DatabaseAuthenticatable
def valid_password?(password)
return false if self.encrypted_password.blank?
bcrypt = ::BCrypt::Password.new(self.encrypted_password)
password = ::BCrypt::Engine.hash_secret("#{password}#{self.class.pepper}", bcrypt.salt)
Devise.secure_compare(password, self.encrypted_password)
@denmarkin
denmarkin / will_paginate_array_helper.rb
Created February 8, 2011 21:48
How to extend array to support .paginate with will_paginate
# See http://rubydoc.info/gems/will_paginate/2.3.15/WillPaginate/Collection.create
# See https://github.com/mislav/will_paginate/blob/master/lib/will_paginate/array.rb
# Do in application_helper.rb or application_controller.rb (or somewhere else application-wide)
require 'will_paginate/collection'
Array.class_eval do
def paginate(options = {})
raise ArgumentError, "parameter hash expected (got #{options.inspect})" unless Hash === options
WillPaginate::Collection.create(
options[:page] || 1,