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 StandardError | |
def info | |
"#{self.class}: #{message}#$/#{backtrace.join($/)}" | |
end | |
end | |
begin | |
raise "Kaboom!" | |
rescue RuntimeError => e | |
puts e.info |
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 Account | |
def initialize | |
@host = self.class::HOST | |
end | |
end | |
class A < Account | |
HOST = "host A" | |
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
require 'net/http' | |
require 'uri' | |
# /api/v1/:format/new | |
# /api/v1/:format/gists/:user | |
# /api/v1/:format/:gist_id | |
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), | |
{ 'files[file1.ab]' => 'CONTNETS', | |
'files[file2.ab]' => 'contents' }) |
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
/** | |
* ping for jQuery | |
* | |
* @auth Jessica | |
* @link http://www.skiyo.cn/demo/jquery.ping/ | |
* | |
*/ | |
(function($) { | |
$.fn.ping = function(options) { | |
var opts = $.extend({}, $.fn.ping.defaults, options); |
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
#-----------------------------------------------------------------------------------------------------------# | |
# Example: | |
#-----------------------------------------------------------------------------------------------------------# | |
# | |
# - gl_tail.yaml config file: | |
# | |
# servers: | |
# server_named: | |
# host: dns1.fooldns.com | |
# files: /var/log/named_querylog |
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
#-----------------------------------------------------------------------------------------------------------# | |
# Example: | |
#-----------------------------------------------------------------------------------------------------------# | |
# | |
# - gl_tail.yaml config file: | |
# | |
# servers: | |
# server_named: | |
# host: dns1.fooldns.com | |
# files: /var/log/named_querylog |
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: | |
NSString *filePath = [self pathForItemNamed:@"file.ext" inFolder:[[NSBundle mainBundle] bundlePath]]; | |
+ (NSString *) pathForItemNamed: (NSString *) fname inFolder: (NSString *) path | |
{ | |
NSString *file; | |
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:path]; | |
while (file = [dirEnum nextObject]) { | |
//NSLog(@"file: %@", file); | |
if ([[file lastPathComponent] isEqualToString:fname]) |
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
objects = {} | |
p ObjectSpace.each_object{|obj| objects[obj.class] += 1} | |
pp objects.sort_by{|k,v| -v} |
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
url = URI.parse('http://www.example.com/todo.cgi') | |
req = Net::HTTP::Post.new(url.path) | |
req.basic_auth 'jack', 'pass' | |
req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';') | |
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } | |
case res | |
when Net::HTTPSuccess, Net::HTTPRedirection | |
# OK | |
else | |
res.error! |
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
# from: http://kfahlgren.com/blog/2006/11/01/multipart-post-in-ruby-2/ | |
# edited by makevoid, http://makevoid.com | |
URL = "http://localhost:3000/your_url" | |
TIMEOUT_SECONDS = 10 | |
params = {} | |
file = File.open(filename, "rb") | |
params["file[replay]"] = file |
OlderNewer