Skip to content

Instantly share code, notes, and snippets.

View erubboli's full-sized avatar

Enrico Rubboli erubboli

View GitHub Profile
<!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 / faye_server.js
Created May 10, 2011 09:40
Faye Server - nodejs
var http = require('http'),
faye = require('faye');
var bayeux = new faye.NodeAdapter({
mount: '/auctions',
timeout: 45
});
// Handle non-Bayeux requests
var server = http.createServer(function(request, response) {
@erubboli
erubboli / concatenation.rb
Created May 7, 2011 10:31
concatenation vs interpolation
require 'benchmark'
Benchmark.bm do |x|
x.report("concatenation") do
for i in 0..30000000 do
str = "a=" << "10" << ",b=" << "20" << ",c=" << "30" << "."
end
end
x.report("interpolation") do
@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
@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 / 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 / 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
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
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
<script>
function A() {
alert("new A called");
this.my_method = function(element) {
alert("a#method called");
}
};
A.initialize = function() {
alert ("A#initialize called");