Skip to content

Instantly share code, notes, and snippets.

View regedarek's full-sized avatar
🏠
Working from home

Darek Finster regedarek

🏠
Working from home
View GitHub Profile
module M
def method
puts "hello"
end
end
def execute(current_module, &block)
Object.new.tap do |o|
o.extend(current_module)
o.instance_eval &block
@regedarek
regedarek / vim7.3_mac_install.rb
Created April 2, 2012 19:14 — forked from sirupsen/vim7.3_mac_install.rb
Script to install Vim 7.3 with ruby support for Mac OS X Lion
# requires root permissions in /usr/bin/
star = String.new
8.times { star += "*" }
Star = "\n#{star * 3}\n"
def newblock string
puts "\n#{Star}#{string}#{Star}\n"
end
@regedarek
regedarek / registrations_controller.rb
Created May 23, 2012 16:30 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@regedarek
regedarek / Plea.markdown
Created June 29, 2012 07:05 — forked from justinko/Plea.markdown
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this:

@regedarek
regedarek / .vimrc
Created September 12, 2012 22:03 — forked from andyfowler/.vimrc
Swap iTerm2 cursors in vim insert mode when using tmux
" tmux will only forward escape sequences to the terminal if surrounded by a DCS sequence
" http://sourceforge.net/mailarchive/forum.php?thread_name=AANLkTinkbdoZ8eNR1X2UobLTeww1jFrvfJxTMfKSq-L%2B%40mail.gmail.com&forum_name=tmux-users
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
@regedarek
regedarek / Plea.markdown
Created September 13, 2012 10:11 — forked from justinko/Plea.markdown
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this:

@regedarek
regedarek / gist:3734225
Created September 16, 2012 20:20 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@regedarek
regedarek / gist:3734399
Created September 16, 2012 21:07
Extending models in Rails
# See http://blog.waxman.me/extending-your-models-in-rails-3 for original post
module Extensions
module Popular
module ClassMethods
def most_popular(limit=10)
order('points desc').limit(limit).all
end
end
def popularity
class Name
def initialize(first_name, last_name)
@first_name, @last_name = first_name, last_name
end
def to_s
"#{first_name} #{last_name}"
end
end
@regedarek
regedarek / address_sanity_check.rb
Created November 27, 2012 14:06 — forked from tomash/address_sanity_check.rb
fix order addresses #438136
# sanity checking
users_with_multiple_addresses = []
User.all.each do |user|
addresses = Address.where(:addressable_type => 'User', :addressable_id => user.id)
if(addresses.count > 1)
users_with_multiple_addresses << user
end
end