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: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: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: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: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: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: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:3860147
Created October 9, 2012 17:17
Simple video player in Ruby
# Written by Pioz.
#
# Deps:
# sudo apt-get install libgtk2.0-dev libgstreamer0.10-dev gstreamer0.10-plugins-base
# gem install gtk2 gstreamer
require 'gtk2'
require 'gst'
if ARGV.size != 1
@pioz
pioz / gist:4739362
Last active December 12, 2015 07:49
roflcopter
#!/usr/bin/env ruby
require 'curses'
include Curses
init_screen
curs_set(frame = 0)
Thread.new { system "say -v Alex the rofl copter says #{'siff ' * 1000}" }
@pioz
pioz / gist:4883502
Created February 13, 2013 02:17
Simple preforking echo server in Ruby
# simple preforking echo server in Ruby
require 'socket'
# Create a socket, bind it to localhost:4242, and start listening.
# Runs once in the parent; all forked children inherit the socket's
# file descriptor.
acceptor = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
address = Socket.pack_sockaddr_in(4242, 'localhost')
acceptor.bind(address)
acceptor.listen(10)
@pioz
pioz / gist:5587388
Created May 15, 2013 21:08
Ruby gstreamer 2.0 don't work for me under ruby-2.0.0-p0
2.0.0-p0 :001 > require 'gst'
=> true
2.0.0-p0 :002 > bin = Gst::ElementFactory.make('playbin')
NameError: uninitialized constant Gst::ElementFactory
from (irb):2