Skip to content

Instantly share code, notes, and snippets.

View makevoid's full-sized avatar

Francesco 'makevoid' Canessa makevoid

View GitHub Profile
@makevoid
makevoid / ruby_exceptions_cheatsheet.rb
Created October 22, 2011 13:03
Exceptions cheatsheet from Avdi Grimm talk
# exceptions cheatsheet from Avdi Grimm talk
# talk: http://confreaks.net/videos/523-roa2011-exceptional-ruby
# retry
begin
rescue
retry
@makevoid
makevoid / csv.rb
Created October 20, 2011 22:08
Convert Hashes to CSV easily
# Convert Hashes to CSV easily
# source.rb
#
# { valid: "ruby", hash: "" }
# { another: "valid", ruby: "hash" }
# { etc...
# usage:
#
@makevoid
makevoid / http_server.rb
Created October 20, 2011 04:03
Net:HTTP tutorial #2: simple HTTPServer - useful to test your pages/api calls and to play with plain http
# simple HTTPServer:
# useful to test your pages/api calls!
class HTTPServer
def initialize(port, body)
require 'socket'
@server = Thread.new do
server = TCPServer.open port
loop do
@makevoid
makevoid / net_http_keepalive.rb
Created October 19, 2011 16:19
Net:HTTP tutorial #1: start block and keep alive requests
# Use the right Net::HTTP api for the right job
#
# use start block and do all requests within it
#
# usecase examples: to build a proxy, a scraper or similars
require 'net/http'
class Getter # simplifies the Net::HTTP api a bit
@makevoid
makevoid / your_model_spec.rb
Created October 14, 2011 13:19
running model specs requiring active record
require 'active_record' # or older require "activerecord"
require_relative 'app/models/your_model'
ActiveRecord::Base.establish_connection(adapter: 'mysql', host: 'localhost', username: 'root', database: 'your_database')
describe "something" do
it "should spec somehting" do
YourModel.first.should be_a(YourModel)
end
end
@makevoid
makevoid / Gemfile
Created September 12, 2011 02:59
Rails 3.1 Gemfile with DataMapper, RSpec, Haml, Sass, CoffeeScript and Thin (in dev)
source 'http://rubygems.org'
gem 'activesupport', :require => 'active_support'
gem 'actionpack', :require => 'action_pack'
gem 'actionmailer', :require => 'action_mailer'
gem 'railties', :require => 'rails'
gem 'mysql2'
DM_VERSION = '~> 1.2.0.rc1'
@makevoid
makevoid / switch_to_vim.sh
Created September 7, 2011 00:42
A function in my .profile to help me remember to learn vim :)
function editor() { # randomly chooses an editor for you :)
[[ `expr $RANDOM % 2` == 0 ]] && editor="vim" || editor="mate"
$editor $1
}
@makevoid
makevoid / README.md
Created August 27, 2011 02:23 — forked from reborg/open_local_html_hotcocoa_webview.rb
Hotcocoa basic WebView hello world (to embed a webpp in a native one basically)

Run

if you don't have macruby and hotcocoa already:

rvm use macruby
gem i hotcocoa

ok then you can run:

hotcocoa webviewbasic

@makevoid
makevoid / hosted_example.txt
Created August 27, 2011 02:01
JQuery DOM HighLighter (it's a basic "Inspect element" simple implementation to mimic what webkit inspector and firebug do)
http://uploads.makevoid.com/jquery_dom_highlighter.html
@makevoid
makevoid / new_term.rb
Created April 27, 2011 13:07
open new terminal tab and executes a command (with rb-appscript)
require 'appscript' # gem i rb-appscript
include Appscript
command = "ls"
app('Terminal').activate()
app("System Events").application_processes["Terminal.app"].keystroke("t", :using => :command_down)
tab = app('Terminal').windows[1].tabs.last.get
app('Terminal').do_script(command, :in => tab)