Skip to content

Instantly share code, notes, and snippets.

desc "remote console"
task :console, :roles => :app do
input = ''
run "cd #{current_path} && bundle exec rails c production" do |channel, stream, data|
next if data.chomp == input.chomp || data.chomp == ''
print data
channel.send_data(input = $stdin.gets) if data =~ /:\d{3}\s+(\*|>)/
end
end
GC.disable
class A
def h
#ApplicationController.helpers.hidden_field_tag('s', 1, :class => 1)
ApplicationController.helpers.text_field_tag('s', 1, :class => 1)
end
def t
ApplicationController.helpers.text_field_tag('s2', 11, :class => 2)
" Vim syntax file
" Language: Slim
" Maintainer: Andrew Stone <[email protected]>
" Version: 1
" Last Change: 2010 Sep 25
" TODO: Feedback is welcomed.
" Quit when a syntax file is already loaded.
if exists("b:current_syntax")
finish
@j-manu
j-manu / gist:1559754
Created January 4, 2012 12:01 — forked from dx7/gist:1333785
Installing ruby-debug with ruby-1.9.3-p125
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1559754)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p125 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
# Let's assume these models Department, Subject, User, Allotment, Test
# Allotment table has department_id, subject_id, user_id
# Test table has department_id, :subject_id
# Problem: allow the user to edit a test if he is alloted the subject
# for that department OR if he is special (dean) OR if the number of allotments
# of that user in that department exceeds 3
#
class Ability
@j-manu
j-manu / gist:2246085
Created March 30, 2012 02:59 — forked from iwinux/gist:1529093
config.assets.precompile
def compile_asset?(path)
# ignores any filename that begins with '_' (e.g. sass partials)
# all other css/js/sass/image files are processed
if File.basename(path) =~ /^[^_].*\.\w+$/
puts "Compiling: #{path}"
true
else
puts "Ignoring: #{path}"
false
end
@j-manu
j-manu / uri.js
Created April 21, 2012 04:07 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.host; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
class UserRegistrationService
def initialize(params)
@params = params
end
def register
user = User.new(@params)
if user.save
# send_email
@j-manu
j-manu / gist:2762570
Created May 21, 2012 14:24 — forked from jpallen/gist:2762417
Add a .findOrBuild() method to Backbone Models
// keep models fetched in different views in sync
// Finding and creating models
// ===========================
//
// We might need to get a reference to a model from anywhere in our code
// and we want to make sure that these references all point to the same model.
// Otherwise updates to one copy of the model won't affect another.
//
// The methods here let you get models through a wrapper that will either
// create the model if it doesn't exist anywhere, or return a reference to
@j-manu
j-manu / rails_routing_invalid_chars_fix.rb
Created May 30, 2012 04:52 — forked from bensomers/rails_routing_invalid_chars_fix.rb
3.0.x monkeypatch for fixing Invalid Char 500s
# Fix for a Rails - Ruby 1.9 bug
# Rails Router, now that it's UTF-8 default, blows up when routing requests
# with invalid chars in the URL; it should properly return a 400 error
# Have to monkey-patch the fix in, since it's not scheduled for release until
# Rails 4.0.
# Adapted Andrew White (pixeltrix)'s fix at
# https://github.com/rails/rails/commit/3fc561a1f71edf1c2bae695cafa03909d24a5ca3,
# but edited to work in 3.0.x.
# 3.1.x, 3.2.x compatibility unknown
require 'action_dispatch/routing/route_set'