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: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: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: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: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: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: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:850939
Created March 2, 2011 13:36
Convert latin1 database in UTF8
mysqldump DBNAME -u USER -p > backup.sql
cat backup.sql | sed s/latin1/utf8/ > converted.sql
mysql -u USER -p --execute="drop database DBNAME;"
mysql -u USER -p --execute="create database DBNAME character set utf8 collate utf8_general_ci;"
mysql DBNAME -u USER -p < converted.sql
@pioz
pioz / gist:850764
Created March 2, 2011 10:51
Convert all HTML files in . to HAML
find . -type f -name '*.html' | sed s/html// | xargs -I {} html2haml {}html {}haml
@pioz
pioz / gist:843754
Created February 25, 2011 13:02
init.d script to run solr
#!/bin/sh
PATH=/opt/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=solr
DESC=apache-solr
VERSION=1.4.1
SOLR_PATH=/opt/solr-$VERSION
COMMAND=/usr/bin/java
OPTIONS="-Dsolr.solr.home=$SOLR_PATH/solr -Djetty.home=$SOLR_PATH -jar $SOLR_PATH/start.jar"
PIDFILE=/var/run/$NAME.pid
@pioz
pioz / campfire.rb
Created February 17, 2011 10:12 — forked from tenderlove/campfire.rb
require 'uri'
require 'psych'
require 'net/http'
require 'meme' # Install meme_generator
module Campfire
class API
attr_reader :uri, :token, :pass