Skip to content

Instantly share code, notes, and snippets.

Avatar
:atom:

Francesco 'makevoid' Canessa makevoid

:atom:
View GitHub Profile
View gist:112726
class StandardError
def info
"#{self.class}: #{message}#$/#{backtrace.join($/)}"
end
end
begin
raise "Kaboom!"
rescue RuntimeError => e
puts e.info
@makevoid
makevoid / gist:113028
Created May 17, 2009
contstants and inheritance
View gist:113028
class Account
def initialize
@host = self.class::HOST
end
end
class A < Account
HOST = "host A"
end
View example_gist_create.rb
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
/**
* 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
#-----------------------------------------------------------------------------------------------------------#
# 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
#-----------------------------------------------------------------------------------------------------------#
# Example:
#-----------------------------------------------------------------------------------------------------------#
#
# - gl_tail.yaml config file:
#
# servers:
# server_named:
# host: dns1.fooldns.com
# files: /var/log/named_querylog
@makevoid
makevoid / cocoa file search from bundle.m
Created Jan 11, 2010
Cocoa file search from bundle
View cocoa file search from bundle.m
// 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])
@makevoid
makevoid / inspecting_objects_count.rb
Created Jan 11, 2010
Inspecting objects counts
View inspecting_objects_count.rb
objects = {}
p ObjectSpace.each_object{|obj| objects[obj.class] += 1}
pp objects.sort_by{|k,v| -v}
View Posting with Net::HTTP.rb
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
# 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