View gist:112726
This file contains 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 |
View gist:113028
This file contains 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 |
View example_gist_create.rb
This file contains 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' }) |
View gist:127643
This file contains 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); |
View [fool] gl_tail named parser.rb
This file contains 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 |
View [fool] gl_tail named parser core.rb
This file contains 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 |
View cocoa file search from bundle.m
This file contains 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]) |
View inspecting_objects_count.rb
This file contains 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} |
View Posting with Net::HTTP.rb
This file contains 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! |
View Multipart file upload ruby.rb
This file contains 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