Wed 21 Apr 2010 @ 12:18 (1271848683)

urxvt selection2browser

Sometimes I need to open a few links from the terminal which are just words, so it's almost impossible to have them recognized by urxvt url matcher. This is why I've done this small script which allows you to open into your browser a piece of text previously selected on the terminal.

I'm far from being an urxvt expert so if you have better solutions please write me!

#! perl

sub on_start {
   my ($self) = @_;

   $self->{browser} = $self->x_resource ("urlLauncher") || "sensible-browser";

   ()
}

sub on_user_command {
   my ($self, $cmd) = @_;

   $cmd eq "selection2browser"
      and $self->exec_async ($self->{browser}, $self->selection);

   ()
}

I have this script saved as a file named selection2browser in my ~/.urxvt/perl/ directory and in order to activate it via Ctrl-Alt-w I put the following lines in ~/.Xresources:

URxvt.perl-lib: /home/shammash/.urxvt/perl/
URxvt.perl-ext-common: default,[other stuff],selection2browser
URxvt.keysym.C-M-w: perl:selection2browser

Posted by shammash | Permanent Link | Categories: tech

Sat 6 Mar 2010 @ 11:40 (1267872010)

tesi specialistica

Finalmente, dopo mesi di gestazione[1], sono arrivato a consegnare la tesi di laurea specialistica.

Design e implementazione del nuovo framework Virtual Distributed Ethernet: analisi delle prestazioni e validazione sulla precedente architettura.

Buona lettura!

[1] o,> e (o(


Posted by shammash | Permanent Link | Categories: var, tech

Sat 9 Jan 2010 @ 16:16 (1263050186)

debrick LiveScribe Pulse

A few days ago my friend Roberto received his new LiveScribe Pulse. After playing a bit with his new toy he decided to attach it to the computer, but unfortunately the pen got bricked during a firmware upgrade.

So with my friend Filippo we tried to perform various kinds of hard reset, following what's described in 29101 - Mac Master Reset and firmware update utility, but with no success.

We were about to give up when, just out of curiosity, I decided to attach the pen to my Linux machine. Using "lsusb -vv" I've discovered that the pen was stuck in its Device Firmware Upgrade mode waiting for something interesting to happen.

Fantastic! We found the pen firmware inside LiveScribe Flash Utility and we uploaded it using "dfutool" from BlueZ... The pen came back to life, very good!

After this forced upgrade the pen was basically working, but it lacked some functionalities like voice recording. But now official LiveScribe utilities were able to see the pen, so we re-flashed using them and we obtained a 100% working device.

These are the steps we used to flash the LiveScribe Pulse from Linux:

$ wget http://www.livescribe.com/downloads/support/LivescribeSmartpenFlashUtility_2.1.1_Mac.zip
$ unzip LivescribeSmartpenFlashUtility_2.1.1_Mac.zip
$ cd 2.1.1\ Pen\ Flash\ Utility.app/Contents/Resources/Bundles/
$ unzip SystemSoftwareV2.1.1_C.bnd -d SystemSoftwareV2.1.1_C
$ cd SystemSoftwareV2.1.1_C/Files/
$ dfutool upgrade bali_ams3.dfu
Filename  bali_ams3.dfu
Filesize  3365572
Checksum  40559ec9 (valid)

Available devices with DFU support:

  1) Bus 004 Device 002: ID 1cfb:1020 Interface 2



Posted by shammash | Permanent Link | Categories: tech

Sat 29 Aug 2009 @ 22:43 (1251578635)

two local interfaces without loopback

Today I was working with Filippo on some performance analysis. At some point we
needed to send some traffic between two different interfaces on the same Linux
box, but we did not want the traffic routed through the local loopback.

The main problem here seems to be the lack of a direct and clean way to say in
Linux: "yes, this address is on this machine, but do not use the local loopback
for the traffic originating from the same host which needs to reach it".

Different flavours of this problem have been approached in many ways, there is
also a Send-To-Self patch for the kernel.

So this is my sol^W^Wan hack to achieve that using four IP addresses, NAT, and
a few simple changes to the routing table.

ip l s tap1 up
ip l s tap2 up
ip a a 10.10.1.2/32 dev tap1
ip a a 10.10.2.2/32 dev tap2
ip r a 10.10.2.1/32 dev tap1
ip r a 10.10.1.1/32 dev tap2
iptables -t nat -A POSTROUTING -o tap1 -j SNAT --to-source 10.10.1.1
iptables -t nat -A POSTROUTING -o tap2 -j SNAT --to-source 10.10.2.1
iptables -t nat -A PREROUTING -i tap1 -j DNAT --to-destination 10.10.1.2
iptables -t nat -A PREROUTING -i tap2 -j DNAT --to-destination 10.10.2.2
arp -i tap2 -Ds 10.10.1.1 tap1
arp -i tap1 -Ds 10.10.2.1 tap2


Posted by shammash | Permanent Link | Categories: tech

Sat 18 Oct 2008 @ 18:46 (1224348396)

delicious backup

A slightly improved version of this ruby script you can use to backup your delicious bookmarks to an sqlite3 database.

#!/usr/bin/env ruby
require 'rexml/document'
require 'net/http'
require 'net/https'
require 'sqlite3'
require 'json'

dbfile_base = 'delicious_bkp_'
rcfile_base = '.delicious_bkp.rc'

agent = 'del.icio.us backup v0.2.1'

schema = <<EOF
create table bookmarks (
    hash char(32) primary key,
    url varchar(1024),
    title varchar(1024),
    note varchar(2048),
    time timestamp
);
create table tags (hash char(32), tag varchar(1024));
create index ix_tags_hash on tags (hash);
create index ix_tags_tag on tags (tag);
EOF
insert_url = 'insert into bookmarks (hash, url, title, note, time) ' +
             'values (?, ?, ?, ?, ?);'
insert_tag = 'insert into tags (hash, tag) values (?, ?);'


rcfile_path = File.join(ENV['HOME'], rcfile_base)
if (not FileTest.exist?(rcfile_path))
	puts "\nERROR: rc file not found!\n\n"
	puts "Create a file " + rcfile_path + " containing the following line:"
	puts "{ \"user\": \"username\", \"pass\": \"password\", \"dir\": \"/path/to/bkp\", \"max_bkp\": 0}\n\n"
	exit -1
end
rcfile = File.open(rcfile_path)
perms = sprintf("%o", rcfile.stat().mode)[-4..-1]
if (perms != "0600")
	puts "\nERROR: rc file permissions are not safe!\n\n"
	exit -1
end
begin
j = JSON.parse(rcfile.read())
rescue JSON::ParserError
	puts "\nERROR: bad syntax in rc file\n\n"
	exit -1
end
['user', 'pass', 'dir', 'max_bkp'].each { |key|
	if (not j.has_key?(key))
		puts "\nERROR: field " + key + " doesn't exist in rc file!\n\n"
		exit -1
	end
}
if (not FileTest.directory?(j['dir']))
	puts "\nERROR: Specified directory does not exist!\n\n"
	exit -1
end

dbfile_base = dbfile_base + j['user'] + "_"
dbfile_name = dbfile_base + Time.now.strftime("%Y-%m-%d.db")
dbfile_path = File.join(j['dir'], dbfile_name)
if (FileTest.exist?(dbfile_path))
	puts "Backup " + dbfile_name + " exists, exiting."
	exit 0
end

http = Net::HTTP.new('api.del.icio.us', 443)
http.use_ssl = true
xml = http.start { |http|
    req = Net::HTTP::Get.new('/v1/posts/all', {'User-Agent' => agent})
    req.basic_auth(j['user'], j['pass'])
    http.request(req).body
}

doc = REXML::Document.new(xml)

SQLite3::Database.open(dbfile_path).transaction { |db|
    db.execute_batch(schema)
    db.prepare(insert_url) { |url_stmt|
        db.prepare(insert_tag) { |tag_stmt|
            doc.elements.each('posts/post') { |el|
                url_stmt.execute(el.attributes['hash'],
                    el.attributes['href'], el.attributes['description'],
                    el.attributes['extended'], el.attributes['time'])
                el.attributes['tag'].split(' ').each { |tag|
                    tag_stmt.execute(el.attributes['hash'], tag)
                }
            }
        }
    }
}

if (j['max_bkp'] > 0)
	d = Dir.new(j['dir'])
	b = []
	re = Regexp.new(dbfile_base + "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\.db")
	d.each {|entry| if re.match(entry) then b.push(entry) end }
	if b.nitems > j['max_bkp']
        	b.sort()[0, (b.nitems - j['max_bkp'])].each {|olddb|
	                File.unlink(File.join(j['dir'], olddb))
        	}
	end
end



Posted by shammash | Permanent Link | Categories: var

Sat 18 Oct 2008 @ 14:49 (1224334187)


Posted by shammash | Permanent Link | Categories: var

Wed 24 Sep 2008 @ 15:09 (1222261773)

stop software patents world day


Posted by shammash | Permanent Link | Categories: tech

Wed 2 Jul 2008 @ 00:13 (1214950401)

native vde support in qemu

The patch is here.
I hope it will get upstream.

Posted by shammash | Permanent Link | Categories: tech

Fri 27 Jun 2008 @ 10:53 (1214556821)

tempo

Ricevo in terra irlandese e pubblico un segno evidente del tempo che passa:

occhio beppe

Nota: il valore di verità non cambia sia interpretando "tempo" come clima (si suda) che come anni (si portano gli occhiali).

Posted by shammash | Permanent Link | Categories: var, fun

Tue 6 May 2008 @ 15:20 (1210080004)

quicksort

Let's write a quicksort implementation in J programming language..

quicksort=:(($:@(<#[),(=#[),$:@(>#[))({~?@#))^:(1<#)

Many thanks to Vlad! :)

Posted by shammash | Permanent Link | Categories: tech, fun