Skip to content

Instantly share code, notes, and snippets.

View pioz's full-sized avatar
🧙‍♂️
[object Object]

Enrico pioz

🧙‍♂️
[object Object]
View GitHub Profile
@pioz
pioz / gist:3758471
Created September 20, 2012 21:29
Wrap a string to 78 char
s.gsub(/(.{1,78})(?: +|$)\n?|(.{78})/, "\\1\\2\n")
@pioz
pioz / gist:3742623
Created September 18, 2012 11:17
Tweet streaming
require 'tweetstream'
TweetStream.configure do |config|
config.consumer_key = 'AA'
config.consumer_secret = 'BB'
config.oauth_token = 'CC'
config.oauth_token_secret = 'DD'
config.auth_method = :oauth
end
@pioz
pioz / gist:2926686
Created June 13, 2012 21:48
Generate HTML pages using rails without a webserver
ENV['RAILS_ENV'] = 'development'
require '/Users/pioz/Code/ecommerce/config/application.rb'
app = Megiston::Application.initialize!
session = ActionDispatch::Integration::Session.new(app)
session.get '/'
puts session.body
@pioz
pioz / gist:1477585
Created December 14, 2011 17:34
Inputbox in Ruby using win32ole
require 'win32ole'
def inputbox(message, title = '')
sc = WIN32OLE.new("ScriptControl")
sc.language = "VBScript"
sc.eval("Inputbox(\"#{message}\", \"#{title}\")")
end
def popup(message)
wsh = WIN32OLE.new('WScript.Shell')
@pioz
pioz / gist:1476188
Created December 14, 2011 11:18
Autovote on Monster WoW
require 'rubygems'
require 'mechanize'
require 'nokogiri'
agent = Mechanize.new
# Do login
page = agent.get('http://monster-wow.com/')
form = page.form_with(:name => 'login_form')
form.username = ARGV[0]
@pioz
pioz / gist:1353683
Created November 10, 2011 00:30
Sum with bitwise boolean and left shift instructions only
int
add (int a, int b)
{
int gen = a & b; // carries
int pro = a ^ b; // sum
gen |= pro & (gen << 1);
pro = pro & (pro << 1);
gen |= pro & (gen << 2);
pro = pro & (pro << 2);
gen |= pro & (gen << 4);
@pioz
pioz / gist:1352181
Created November 9, 2011 17:28
Code for accessing a square of the bitboard
typedef unsigned long long bboard; // 64 bit unsigned integer
bboard
get (bboard b, int square)
{
return (b & (1ULL << square));
}
@pioz
pioz / gist:1318460
Created October 27, 2011 00:43
Use QT and Webkit to manipulate the DOM
require 'Qt'
require 'qtwebkit'
class Viewer < Qt::WebView
slots 'change_h1()'
def initialize(parent = nil)
super(parent)
connect(self, SIGNAL('loadFinished(bool)'), self, SLOT('change_h1()'))
@pioz
pioz / gist:1288451
Created October 14, 2011 21:46
Zip files and directories recursively
require 'zip/zip'
module Zip
def self.create(filename, *files)
Zip::ZipFile.open(filename, Zip::ZipFile::CREATE) do |zip|
files.each { |file| add(zip, file) }
end
end
@pioz
pioz / gist:1285711
Created October 13, 2011 22:17
Kill Unicorn server on port 3000
kill `ps ax | grep -v grep | grep -e "unicorn_rails .*-p 3000" | awk 'NR==1{print $1}'`