Skip to content

Instantly share code, notes, and snippets.

View makaroni4's full-sized avatar

Anatoli Makarevich makaroni4

View GitHub Profile
@ledermann
ledermann / patch_acts_as_taggable_on.rb
Created August 5, 2010 16:10
Monkey patch for the Rails plugin "acts_as_taggable_on" to handle dirty tracking
# Monkey patch for the Rails plugin "acts_as_taggable_on" to handle dirty tracking
# http://github.com/mbleigh/acts-as-taggable-on/issues#issue/1
module ActsAsTaggableOn::Taggable
module Core
module InstanceMethods
def set_tag_list_on_with_dirty_tracking(context,new_list)
value = new_list.to_s
attr = "#{context.to_s.singularize}_list"
@thermistor
thermistor / assets.rake
Created October 20, 2011 13:55 — forked from shedd/assets.rake
Check asset encoding for valid UTF-8
namespace :assets do
desc "Check that all assets have valid encoding"
task :check => :environment do
paths = ["app/assets", "lib/assets", "vendor/assets"]
extensions = ["js", "coffee", "css", "scss"]
paths.each do |path|
dir_path = Rails.root + path
@peterc
peterc / unary.rb
Created November 8, 2011 16:44
Ruby unary operator overriding demo
class MagicString < String
def +@
upcase
end
def -@
downcase
end
def ~
@gmcintire
gmcintire / deploy.rb
Created December 16, 2011 02:21 — forked from stympy/deploy.rb
Skip asset pre-compilation when deploying if the assets didn't change
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
@stevehodgkiss
stevehodgkiss / freeagent.rb
Created February 25, 2012 23:42
Script to download all your attachments on FreeAgent
require 'rubygems'
require 'freeagent'
require 'eventmachine'
require 'em-synchrony'
require 'em-http-request'
require 'em-synchrony/fiber_iterator'
require 'active_support'
ATTACHMENTS_DIR = '/Users/steve/Documents/freeagent_attachments'
@route
route / gist:2489600
Created April 25, 2012 13:11
Additions to rr stubbing
# Dynamic method stubbing
# user = Factory(:user)
# callbacks = User._create_callbacks.map(&:filter)
# stub_methods("user", callbacks)
def stub_methods(name, methods)
methods.each do |method|
eval "stub(#{name}).#{method}"
end
end
@kirs
kirs / run
Created October 3, 2012 05:59
Unicorn service for Runit
#!/bin/sh
exec 2>&1
export RAILS_ENV=production
APP_ROOT=/home/deploy/project_name
UNICORN="/usr/local/rvm/bin/rvm 1.9.2@project_name exec bundle exec unicorn_rails -c $APP_ROOT/current/config/unicorn.rb -E $RAILS_ENV"
cd $APP_ROOT/current
exec $UNICORN
files = Dir["./**/*"]
files.each do |file|
next if File.directory?(file)
words = []
begin
File.read(file).scan /[\u0400-\u04FF\-]+/ do |match|
words << match
end
@oojikoo-gist
oojikoo-gist / bulletproof_404s_rails.md
Created April 1, 2015 16:16
rails: bulletproof 404s(exception handling)

A step by step guide to bulletproof 404s on Rails

origin: jerodsanto Blog

Step 1: Configure your router as the exceptions app

Since Rails 3 you’ve been able to configure an app to handle exceptions, which you want to point right at your router. To do this, add the following to config/application.rb:

@ik5
ik5 / daemon.rb
Created June 22, 2010 18:43
a quick and dirty jruby daemon based on basic_daemon
#!/usr/bin/env jruby
#
#
require 'rubygems'
require 'spoon'
EXEC = '/tmp/exec.rb'
PID_PATH = '/tmp/exec.pid'
WORK_PATH = '/tmp/'