Skip to content

Instantly share code, notes, and snippets.

View erubboli's full-sized avatar

Enrico Rubboli erubboli

View GitHub Profile
User.include_root_in_json = true
User.first.to_json(:only => [:screen_name,:id])
#=> {"user":{"id":1,"screen_name":"test"}}
User.include_root_in_json = false
User.first.to_json(:only => [:screen_name,:id])
#=> {"id":1,"screen_name":"test"}
res = `file "#{ARGV[0]}"`
#puts "#{ARGV[0]} -> #{res}"
if res.match /Microsoft/
fn = ARGV[0].split('.')
fn[fn.size-1] = 'lit'
puts "mv \"#{ARGV[0]}\" \"#{fn.join('.')}\""
end
parent.image.combine_options do |c|
c.fill hex_color
c.pointsize @obj.media.font_size
#c.font "#{RAILS_ROOT}/public/images/fonts/#{@obj.font.downcase}.ttf"
draw_params = ''
draw_params += "gravity #{gravity} " if gravity
#cmd += "scale #{scale},#{scale} " if scale
draw_params += "rotate #{degrees} " if degrees
##TODO: escape text characters!!
<script>
function A() {
alert("new A called");
this.my_method = function(element) {
alert("a#method called");
}
};
A.initialize = function() {
alert ("A#initialize called");
def destroy
@journal = current_user.journals.find(params[:id])
begin
Page.skip_callback(:save, :after, :run_rendering)
Page.skip_callback(:destroy, :before, :remove_from_list)
@journal.destroy
ensure
Page.set_callback(:save, :after, :run_rendering)
Page.set_callback(:destroy, :before, :remove_from_list)
end
mike@rbci:~$ psql -U postgres
psql (9.0.3)
Type "help" for help.
postgres=# update pg_database set datallowconn = TRUE where datname = 'template0';
UPDATE 1
postgres=# \c template0
You are now connected to database "template0".
template0=# update pg_database set datistemplate = FALSE where datname = 'template1';
UPDATE 1
@erubboli
erubboli / gist:934220
Created April 21, 2011 11:20
request_utf8.txt
POST /api/journals.json?authentication_token=RW6XUuI7hP0EnB4hZa0cjcsXLHkW1RhfXThhaKpen2nicMAsteU8gt1EgMoz HTTP/1.1
Host: localhost:3000
User-Agent: upage 0.8 (iPad Simulator; iPhone OS 4.3; en_US)
Content-Type: application/json;charset=utf-8;charset=utf-8
Accept-Encoding: gzip
Accept: */*
Content-Length: 207
Cookie: _upage-web_session=BAh7CEkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjoGRVRbCEkiCVVzZXIGOwBGWwZpBkkiIiQyYSQxMCRzNnJxbkJaVFFvSDNIaTdNMEw5Mkp1BjsAVEkiHXdhcmRlbi51c2VyLnVzZXIuc2Vzc2lvbgY7AFR7BkkiFGxhc3RfcmVxdWVzdF9hdAY7AEZJdToJVGltZQ2rzhvAPaKZQAY6C0Bfem9uZSIIVVRDSSIPc2Vzc2lvbl9pZAY7AEYiJTIzYWNiMmU0NGM2NTYyNzcyNzlhZDdmNjgzNTYyNjlj--4ec972c052e55126acc68df354a0409b0142b2c6
Connection: keep-alive
@erubboli
erubboli / gist:948593
Created April 29, 2011 16:36
failing_spec.rb
require 'spec_helper'
describe 'rspec' do
it { true.should be_true }
it "mock methods" do
my_obj = double('obj', {:my_method => 2})
my_obj.send('my_method').should == 2
end
it "mock hyphen methods" do
@erubboli
erubboli / auctions.html
Created May 6, 2011 12:23
Faye example
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Auctions Test</title>
<script type="text/javascript" charset="utf-8" src="node_modules/faye/faye-browser.js"></script>
<script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.js"></script>
<script type="text/javascript" charset="utf-8">
bayeux_client = new Faye.Client('http://localhost:8000/auctions');
@erubboli
erubboli / code.rb
Created May 7, 2011 10:11
method access vs variable access
require 'benchmark'
def a_method
10
end
a_var = 10
Benchmark.bm do |x|
x.report("variable access") do
for i in 0..200000000 do