Skip to content

Instantly share code, notes, and snippets.

View makevoid's full-sized avatar

Francesco 'makevoid' Canessa makevoid

View GitHub Profile
@makevoid
makevoid / gist:112726
Created May 16, 2009 16:17
exception.info
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 15:05
contstants and inheritance
class Account
def initialize
@host = self.class::HOST
end
end
class A < Account
HOST = "host A"
end
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' })
@makevoid
makevoid / gist:127643
Created June 11, 2009 01:34
Jquery ping
/**
* 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);
@makevoid
makevoid / [fool] gl_tail named parser.rb
Created July 25, 2009 00:40
gl_tail named parser.rb
#-----------------------------------------------------------------------------------------------------------#
# Example:
#-----------------------------------------------------------------------------------------------------------#
#
# - gl_tail.yaml config file:
#
# servers:
# server_named:
# host: dns1.fooldns.com
# files: /var/log/named_querylog
@makevoid
makevoid / [fool] gl_tail named parser core.rb
Created July 25, 2009 00:51
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 January 11, 2010 02:56
Cocoa file search from bundle
// 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 January 11, 2010 07:03
Inspecting objects counts
objects = {}
p ObjectSpace.each_object{|obj| objects[obj.class] += 1}
pp objects.sort_by{|k,v| -v}
@makevoid
makevoid / Posting with Net::HTTP.rb
Created April 7, 2010 01:55
Posting with Net::HTTP
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!
@makevoid
makevoid / Multipart file upload ruby.rb
Created April 7, 2010 02:08
Multipart file upload ruby
# 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