Skip to content

Instantly share code, notes, and snippets.

class UserRegistrationService
def initialize(params)
@params = params
end
def register
user = User.new(@params)
if user.save
# send_email
@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"
@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
# 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: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
" Vim syntax file
" Language: Slim
" Maintainer: Andrew Stone <andy@stonean.com>
" 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
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)
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
@j-manu
j-manu / fixes.md
Created December 4, 2011 16:30 — forked from thbar/fixes.md
Getting rid of nokogiri segfaults

This readme is a mixture of everything I read on SO+nokogiri wiki, which ultimately worked out for me.

Here are the steps which worked for me to get rid of segfaults with Nokogiri 1.4.4, on both Lion and Snow Leopard, with Ruby 1.8.7 (patchlevel 334 and +).

First diagnose which version of libxml2 you're using:

bundle exec nokogiri -v

If you have 2.7.3 listed somewhere, you're in bad waters (known to segfault). Install this:

@j-manu
j-manu / workers.rake
Created December 4, 2011 07:09 — forked from karmi/workers.rake
Rake taks to launch multiple Resque workers in development/production with simple management included
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.