Skip to content

Instantly share code, notes, and snippets.

View olistik's full-sized avatar

Maurizio De Magnis olistik

View GitHub Profile
@olistik
olistik / current_method_name.rb
Created November 26, 2009 14:36
Method name in every method
# http://www.ruby-forum.com/topic/75258#116892
# you could eventually put this in your rails config/environment.rb
module Kernel
private
def this_method
caller[0] =~ /`([^']*)'/ and $1
end
end
@olistik
olistik / log_the_backtrace.rb
Created December 10, 2009 10:24
Log the backtrace in Rails
begin
raise "boom"
rescue => detail
Rails.logger.warn detail.backtrace.join("\n")
end
# ripped from here: http://codesnippets.joyent.com/posts/show/1983
require 'irb/completion'
require 'map_by_method'
require 'what_methods'
require 'pp'
require 'wirble'
Wirble.init
Wirble.colorize
IRB.conf[:AUTO_INDENT] = true
# tons of warnings when trying to run rails3b3 activemodel's test suite:
portal:activemodel olistik$ rake
(in /Volumes/data/code/ruby/rails/projects/rails3/contribute/rails/activemodel)
/Users/olistik/.rvm/gems/ruby-1.9.2-head@rails3beta3/gems/bundler-0.9.19/lib/bundler.rb:70: warning: instance variable @setup not initialized
/Users/olistik/.rvm/gems/ruby-1.9.2-head@rails3beta3/gems/bundler-0.9.19/lib/bundler/shared_helpers.rb:106: warning: method redefined; discarding old gem
/Users/olistik/.rvm/gems/ruby-1.9.2-head@rails3beta3/gems/bundler-0.9.19/lib/bundler/shared_helpers.rb:103: warning: previous definition of gem was here
/Users/olistik/.rvm/gems/ruby-1.9.2-head@rails3beta3/gems/bundler-0.9.19/lib/bundler/shared_helpers.rb:138: warning: method redefined; discarding old from_gems_in
[...]
$ rvm info
system:
uname: "Darwin portal.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386 i386"
shell: "bash"
version: "3.2.48(1)-release"
rvm:
type: "rvm is a function"
version: "rvm 0.1.27 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]"
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.buongiorno.gpp.wwf.portlet.core.extension.AnnotationHandlerMapping#0' defined in PortletContext resource [/WEB-INF/context/portlet/registrationPortlet.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: Lcom/buongiorno/innovation/gambling/api/ParamDigestService;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.sp
# run me with: ruby wait_for_lucid_lynx.rb
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'ruby-growl'
g = Growl.new "localhost", "ruby-growl",
["ruby-growl Notification"]
require 'net/http'
module Http
def self.get(uri)
url = URI.parse uri
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) do |http|
http.request(req)
end
res.body
## IS THERE A SIMPLER WAY OF CHANGING some fields of a DateTime Object?
real = DateTime.parse(DateTime.now.to_s)
fixed = DateTime.new(real.year, real.month, real.day, real.hour, real.minute, real.second)
## SOLUTION
## http://api.rubyonrails.org/classes/DateTime.html
## DateTime#change
new_date = DateTime.now.change({year: 2012, sec: 42})
@olistik
olistik / twitter_following_list.js
Created November 24, 2010 16:01
how to obtain the list of user I'm following on twitter
/*
* I'm using Google Chrome
* 1) open http://twitter.com/#!/olistik/following
* 2) scroll to the very end of the page
* 3) switch to console tab (ALT+CMD+J)
*/
var following = [];
jQuery('.user-name strong').each(function() {
following.push(jQuery(this).html());