Skip to content

Instantly share code, notes, and snippets.

#place this inside config/initializers/
require 'oauth/request_proxy/typhoeus_request'
module OAuthFix
def self.included(base)
base.send :include, InstanceMethods
base.module_eval %q{
alias_method :old_post_parameters, :post_parameters
module Mongo
module ControllerRuntime
extend ActiveSupport::Concern
protected
attr_internal :mongo_runtime
def cleanup_view_runtime
module MongoInstrumenter
class LogSubscriber < ActiveSupport::LogSubscriber
def self.runtime=(value)
Thread.current["mongoid_query_runtime"] = value
end
def self.runtime
Thread.current["mongoid_query_runtime"] ||= 0
end
@alanho
alanho / gist:1020716
Created June 11, 2011 16:14
call me a geek...
a = "\"\n\nprint \"a = \\\"\"\nprint a.inspect[1..-2]\nprint a\n"
print "a = \""
print a.inspect[1..-2]
print a
@alanho
alanho / gist:2833791
Created May 30, 2012 04:34
Monkey patch in Rails Initializers example
ActionDispatch::Callbacks.to_prepare do
Devise::Oauth2Providable::Client.class_eval do
attr_accessible :name, :website, :redirect_uri, :development_mode
end
end
@alanho
alanho / gist:2906165
Created June 10, 2012 15:20
Rails Monkey Patch
ActionDispatch::Callbacks.to_prepare do
# monkey patch here
end
@alanho
alanho / BeatBoxFinal.java
Created October 19, 2012 12:50 — forked from michellesun/BeatBoxFinal.java
Beatbox with GUI and chat function
// make a beatbox
import java.awt.*;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.io.*;
import javax.sound.midi.*;
import java.util.*;
@alanho
alanho / gist:5428387
Created April 21, 2013 03:50
Rails with Apache
ServerName www.example.com:80
DocumentRoot "/path/to/rails/app/public"
RewriteEngine On
<Proxy balancer://railsapp>
BalancerMember http://127.0.0.1:5000
BalancerMember http://127.0.0.1:5001
</Proxy>
@alanho
alanho / legco_extract.rb
Created April 22, 2013 09:24
Extract voting result JPEGs/PDFs from LegCo website
require "nokogiri"
require "open-uri"
require "uri"
urls = [
"http://www.legco.gov.hk/general/chinese/counmtg/yr08-12/mtg_0809.htm",
"http://www.legco.gov.hk/general/chinese/counmtg/yr08-12/mtg_0910.htm",
"http://www.legco.gov.hk/general/chinese/counmtg/yr08-12/mtg_1011.htm",
"http://www.legco.gov.hk/general/chinese/counmtg/yr08-12/mtg_1112.htm",
"http://www.legco.gov.hk/general/chinese/counmtg/yr12-16/mtg_1213.htm"
<?php
/**
* Coordinates.php
* An utility for converting HK80 to WGS84 coordinates
*
* Copyright (C) 2010, 2013 Kelvin Wong
* Licensed under the MIT License (http://opensource.org/licenses/MIT)
*
* Note: For the glossaries and conventions for coordinates convertion, please refer to
* the website of Geodetic Survey of Hong Kong.