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:917630
Created April 13, 2011 14:22
Fuzzy searching
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdio.h>
const char *
bitap_fuzzy_search (const char *text, const char *pattern, int errors)
{
const char *result = NULL;
int m = strlen (pattern);
@pioz
pioz / gist:958229
Created May 6, 2011 00:14
Gstreamer 'hello world' multimedia player
#include <glib.h>
#include <gst/gst.h>
// Compile with: gcc hello.c `pkg-config gstreamer-0.10 --libs --cflags`
static gboolean
bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg))
@pioz
pioz / gist:967559
Created May 11, 2011 22:45
Paypal express checkout setup purchase with options
require 'rubygems'
require 'activemerchant'
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
:login => 'xxx',
:password => 'yyy',
:signature => 'zzz'
}
::PAYPAL_EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
@pioz
pioz / gist:970793
Created May 13, 2011 15:57
Country codes
COUNTRIES = {
'AF' => 'Afghanistan',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla',
'AQ' => 'Antarctica',
'AG' => 'Antigua and Barbuda',
@pioz
pioz / gist:988946
Created May 24, 2011 15:42
Crack Alice WIFI router
require 'digest/sha2'
def ssid_to_sn(ssid_number)
key = ssid_number[0..1]
if SN_TABLE[key]
sn_part_1 = SN_TABLE[key][0]
k = SN_TABLE[key][1]
q = SN_TABLE[key][2]
sn_part_2 = ((ssid_number.to_i - q) / k).to_i
return "#{sn_part_1}X#{'%.7i' % sn_part_2}"
@pioz
pioz / gist:1123540
Created August 3, 2011 19:19
Readline
require 'readline'
loop do
line = Readline::readline('> ')
break if line.nil? || line == 'quit'
Readline::HISTORY.push(line)
puts "echo: #{line}"
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}'`
@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: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: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));
}