This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.
publish message to foo channel from user nickname.
$ python pub.py foo nickname
PUBLISH to channel #foo
| Facebook Canvas apps are loaded like this: | |
| * User clicks link to app or tab ("page as tab") | |
| * An iframe is inserted which loads content from the FB server (NOT yours, yet) | |
| Something along the lines of: | |
| <iframe src="http://facebook.com/page_proxy.php?appid=123"> | |
| * The FB server returns some HTML & JS with an automatically submitting form: | |
| <form id="humbaba" target="http://you.com/facebook"> | |
| <input type="hidden" name="signed_request"/></form> |
| // Given a query string "?to=email&why=because&first=John&Last=smith" | |
| // getUrlVar("to") will return "email" | |
| // getUrlVar("last") will return "smith" | |
| // Slightly more concise and improved version based on http://www.jquery4u.com/snippets/url-parameters-jquery/ | |
| function getUrlVar(key){ | |
| var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search); | |
| return result && unescape(result[1]) || ""; | |
| } |
| # SSL self signed localhost for rails start to finish, no red warnings. | |
| # 1) Create your private key (any password will do, we remove it below) | |
| $ openssl genrsa -des3 -out server.orig.key 2048 | |
| # 2) Remove the password | |
| $ openssl rsa -in server.orig.key -out server.key |
| require 'rubygems' | |
| require 'mechanize' | |
| agent = Mechanize.new | |
| agent.set_proxy('proxy.example.com', 80, 'username', 'password') | |
| agent.add_auth('http://hoge.com','b_username','b_password') | |
| agent.user_agent_alias = "Windows Mozilla" | |
| res = agent.get('http://hoge.com/some/page') | |
| puts res.body |
| require 'benchmark' | |
| class DSL1 | |
| def initialize | |
| @i = 1 | |
| end | |
| def self.register(&block) | |
| @block = block |
| require 'sinatra' | |
| require 'json' | |
| require 'csv' | |
| # Serve data as JSON | |
| get '/hi/:name' do | |
| name = params[:name] | |
| content_type :json | |
| { :message => name }.to_json | |
| end |
| class Integer | |
| N_BYTES = [42].pack('i').size | |
| N_BITS = N_BYTES * 16 | |
| MAX = 2 ** (N_BITS - 2) - 1 | |
| MIN = -MAX - 1 | |
| end | |
| p Integer::MAX #=> 4611686018427387903 | |
| p Integer::MAX.class #=> Fixnum | |
| p (Integer::MAX + 1).class #=> Bignum |
| while true; do date; sleep 5; done |
| # ActiveRecord's find_each and find_in_batches ported to Sequel. | |
| # Sequel's paged_each is not practical when converting large data due to its use of transaction and offset. | |
| # | |
| # Usage: | |
| # | |
| # SequelEachInBatches.find_each(dataset, keys) { |record| ... } | |
| # | |
| # It can also monkey patch Sequel::Dataset: | |
| # | |
| # Sequel::Dataset.send(:include, SequelEachInBatches) |