Skip to content

Instantly share code, notes, and snippets.

View makevoid's full-sized avatar

Francesco 'makevoid' Canessa makevoid

View GitHub Profile
@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 / 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 / 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 / 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 / Gemfile
Created November 21, 2011 00:05
dm constraints belongs_to "Can't create table 'dm_constraints.#sql-" bug
def github(gem)
"git@github.com:datamapper/#{gem}"
end
def gh_gem(gem)
gem gem, git: github(gem)
end
%w(dm-core dm-constraints dm-migrations dm-do-adapter dm-mysql-adapter).each do |g|
gh_gem g
@makevoid
makevoid / README.md
Created January 17, 2012 22:29
Thorrents.com JSONP embedded search example

Example of embedded http://thorrents.com search, and a tribute to Cory Doctorow ;) tnx to @thedod

See it live here.

If you want to embed this (or any other search) in an existing page:

  • Remove first and last line and paste this where you want it in the <body/>.
  • Change query to whatever you want to search (and maybe change limit).
@makevoid
makevoid / img_resize.js
Created January 23, 2012 00:29
Resize Images with Canvas on the clientside
var settings = {
max_width: 600,
max_height: 200
}
resize_image = function(img){
var ctx = canvas.getContext("2d")
var canvasCopy = document.createElement("canvas")
var copyContext = canvasCopy.getContext("2d")
@makevoid
makevoid / nginx.sh
Created February 29, 2012 01:52
nginx init.d file for centos/rhel - /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
@makevoid
makevoid / hack.sh
Created April 5, 2012 09:19 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
echo "Use current directory as default search scope in Finder"
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
echo "Show Path bar in Finder"
defaults write com.apple.finder ShowPathbar -bool true
echo "Disable the Ping sidebar in iTunes"
defaults write com.apple.iTunes disablePingSidebar -bool true
@makevoid
makevoid / config.ru
Created April 9, 2012 23:50
Rack Tidy FFI Sinatra Example
require 'rack-tidy-ffi'
require 'sinatra'
use RackTidyFFI
class MyApp < Sinatra::Base
get "/" do
"<div>aaaa<div>bbb</div><div>"
end
end