Skip to content

Instantly share code, notes, and snippets.

View tombruijn's full-sized avatar

Tom de Bruijn tombruijn

View GitHub Profile
# Paperclip gem
# How to fix the issue with ImageMagick crashing on non-image files.
# Must be placed before has_attached_file
# Source: http://awesomeful.net/posts/33-attach-non-image-files-in-rails-with-paperclip
before_post_process :image?
def image?
!({your_model}_content_type =~ /^image.*/).nil?
end
@tombruijn
tombruijn / spree_config.rb
Created August 25, 2011 13:21
Spree i18n config -> When you don't want an error on db:migrate
# config/initializers/spree_config.rb
# Check if Spree::Config is loaded
# If you don't you'll get an error on migrate (the first time only)
if Spree::Config.instance
Spree::Config.set(:default_locale => "nl-NL")
end
@tombruijn
tombruijn / gist:3904610
Created October 17, 2012 09:09
curl post with headers
curl -s -d'postdata=something' -D- http://url -o/dev/null
@tombruijn
tombruijn / failer.js.coffee
Created November 9, 2012 10:26
Konacha testing setup for classes
# app/assets/javascripts/failer.js.coffee
class Failer
ze: (i) ->
i + "wa"
window.failer = new Failer
@tombruijn
tombruijn / hello.jst.eco
Created November 9, 2012 10:28
Konacha testing setup for output
# spec/javascripts/templates/hello.jst.eco
<h1>Hello <%= @name %>!</h1>
# Eco uses instance variables for variables given by the test
@tombruijn
tombruijn / cancan_strong_parameters.rb
Created February 21, 2013 13:54
CanCan + strong_parameters easiest hack
# From: https://github.com/ryanb/cancan/pull/757
# Here for reference
##
# Tell CanCan to use the user-controller resource_params method
# rather than its own (when the user-method) is available
module CanCan
class ControllerResource
def resource_params
@tombruijn
tombruijn / caveatPatchor.js
Last active December 14, 2015 10:18 — forked from protocool/caveatPatchor.js
Propane extension that shows avatars and full names
/*
As of version 1.1.2, Propane will load and execute the contents of
~Library/Application Support/Propane/unsupported/caveatPatchor.js
immediately following the execution of its own enhancer.js file.
You can use this mechanism to add your own customizations to Campfire
in Propane.
Below you'll find two customization examples.
@tombruijn
tombruijn / counter-config.js
Last active March 31, 2016 07:47
Counter.js example configuration
$("#counter").counter({
autoStart: false, // true/false, default: true
duration: 5000, // milliseconds, default: 1500
countFrom: 10, // start counting at this number, default: 0
countTo: 30, // count to this number, default: 0
runOnce: true, // only run the counter once, default: false
placeholder: "?", // replace the number with this before counting,
// most useful with autoStart: false. default: undefined
easing: "easeOutCubic", // see http://gsgd.co.uk/sandbox/jquery/easing
// for all available effects, see visual examples:
@tombruijn
tombruijn / prawn-fonts.rb
Created August 31, 2013 18:59
Quick prawn setup file for font testing
require "prawn"
pdf = Prawn::Document.new do |prawn|
prawn.font_families.update("OpenSans" => {
normal: "book/assets/fonts/OpenSans-Regular.ttf",
italic: "book/assets/fonts/OpenSans-Italic.ttf",
bold: "book/assets/fonts/OpenSans-Bold.ttf",
bold_italic: "book/assets/fonts/OpenSans-BoldItalic.ttf"
})
["Helvetica", "Courier", "OpenSans"].each do |f|
@tombruijn
tombruijn / appsignal-capistrano-3.rake
Created February 27, 2014 09:08
Modified AppSignal deploy task to make it work with Capistrano 3.
namespace :appsignal do
# Description is required for it to show up in the tasks list.
desc 'Notify AppSignal of this deploy!'
task :deploy do
# 1. Needs to be run inside an `on` block
# 2. `appsignal_roles` setting set and supplied with default
on roles(fetch(:appsignal_roles, :app)) do
env = fetch(:rails_env, 'production')
user = ENV['USER'] || ENV['USERNAME']