Skip to content

Instantly share code, notes, and snippets.

💭
😏

Pietro Di Bello xpepper

💭
😏
Block or report user

Report or block xpepper

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@xpepper
xpepper / capistrano_rails_guide.md
Created Mar 22, 2012 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide
View capistrano_rails_guide.md

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

View vim_tips.md

Continued from I'm learning vim. Here's how I'm doing it, by Chris Geihsler

I've committed to learning vim to become more productive without the crutch of an expensive tool and to decouple myself from a specific OS.

Here's what I've done so far:

@xpepper
xpepper / class_detector.rb
Created Apr 4, 2012
How do you tell if a Ruby object is a class?
View class_detector.rb
class Object
def is_a_class?
respond_to? :superclass
end
end
class MyClass
end
View class_method_lookup.rb
class Parent
class << self
def who_am_i
puts "I'm #{self}"
end
def singleton
class << self; self; end
end
end
@xpepper
xpepper / document.rb
Created May 16, 2012
Adding autoload feature to a Ruby class
View document.rb
class Document
def self.reload
instance_methods(false).each { |m| remove_method(m) }
class << self
Document.methods(false).reject {|m| m == "reload" }.each do |m|
remove_method(m)
end
end
load(__FILE__)
@xpepper
xpepper / issues_with_modules.md
Created Dec 1, 2012 — forked from ryanb/issues_with_modules.md
Points on how modules can make code difficult to read.
View issues_with_modules.md

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base
View search.rb
def search(search_options)
name_regexp = search_options[:name_regexp] || ""
starting_date = search_options[:starting_date] || Date.today
ending_date = search_options[:ending_date] || Date.today
where(:name => /#{name_regexp}/, "efforts.date" => {'$gte' => Date.parse(starting_date)}, "efforts.date" => {'$lte' => Date.parse(ending_date)})
end
@xpepper
xpepper / transactions_in_rails.rb
Created Mar 6, 2013
test delle transazioni in Rails
View transactions_in_rails.rb
# Ho creato una app rails semplice, con un modello User e uno Order.
# User:
class User < ActiveRecord::Base
attr_accessible :name, :surname
has_many :orders
end
#Order:
class Order < ActiveRecord::Base
View benchmark.rb
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
View pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

You can’t perform that action at this time.