This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If your workers are inactive for a long period of time, they'll lose | |
# their MySQL connection. | |
# | |
# This hack ensures we re-connect whenever a connection is | |
# lost. Because, really. why not? | |
# | |
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar) | |
# | |
# From: | |
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
class Encryptor | |
def initialize(key_pass, key_size = 1024, key_name = 'rsakey.sec', cipher = OpenSSL::Cipher.new('aes-256-cbc')) | |
@key_size = key_size | |
@cipher = cipher | |
@key_name = key_name | |
if( File.exists?(@key_name) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
require 'yaml' | |
class Encryptor | |
def initialize(key_pass, key_size = 2048, key_name = 'rsakey.sec', cipher = OpenSSL::Cipher.new('aes-256-cbc')) | |
@key_size = key_size | |
@cipher = cipher | |
@key_name = key_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Output csv from sqlite | |
$ sqlite3 db.sqlite | |
sqlite> .mode csv | |
sqlite> .header on | |
sqlite> .output db.csv | |
sqlite> .separator , | |
sqlite> select * from table; | |
sqlite> .exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RSpec | |
module Matchers | |
class AllowMassAssignmentOf # :nodoc: | |
def initialize hash = nil | |
raise if hash.nil? | |
raise unless hash.kind_of? Hash | |
raise unless hash.length > 0 | |
@attributes = hash | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
# |
OlderNewer