This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Within jquery you can listen to global ajax event handlers for the outcome of any ajax requests for when you want to write | |
// your own callback from predefined ajax calls | |
// e.g. | |
// the below js call is in a separate js file say 'main.js' | |
function makeAjaxCall(){ | |
//... | |
$.ajax({ | |
url: 'http://something.com' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'optparse' | |
require 'optparse/time' | |
require 'ostruct' | |
require 'pp' | |
class OptparseExample | |
CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary] | |
CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocalResource | |
attr_reader :uri | |
def initialize(uri) | |
@uri = uri | |
end | |
def file | |
@file ||= Tempfile.new(tmp_filename, tmp_folder, encoding: encoding).tap do |f| | |
io.rewind |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm | |
http://www.cyberciti.biz/faq/vi-show-line-numbers/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Abstract event binding | |
Example: | |
var MyEventEmitter = function(){}; | |
MyEventEmitter.prototype = new AbstractEventsDispatcher; | |
var emitter = new MyEventEmitter(); | |
// Bind to single event | |
emitter.bind('foo_event', function(data){ alert(data)} ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# dr = DateRange.new(Date.today) | |
# dr.each{|d| puts d} | |
# enum = dr.lazy | |
# enum.next | |
# enum.find_all{|d| d.cwday < 5 } # returns all | |
# enum.detect{|d| d.cwday < 3 } # only returns the first instance | |
require 'date' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
def ndays_from(from, step=7) | |
Enumerator.new {|y| | |
loop { | |
y.yield from | |
from += step | |
} | |
} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Multiton pattern | |
# extension to the Singleton pattern which maps unique keys to specific instances of a class. The idea is that there should only be one instance of an object for each unique key in use, limiting the number of objects that need to be created | |
class Font | |
class << self | |
def file_names | |
@file_names ||= {} | |
end | |
def instances |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1) Create your private key (any password will do, we remove it below) | |
$ cd ~/.ssh | |
$ openssl genrsa -des3 -out server.orig.key 2048 | |
# 2) Remove the password | |
$ openssl rsa -in server.orig.key -out server.key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "socket" | |
class MyLogger | |
attr_accessor :format | |
def initialize | |
@format = '%<severity>s %<time>s %<host>s %<pid>s %<message>s' | |
end | |
def error(message) |