<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:admin="http://webns.net/mvcb/"
>
<channel>
<title>sham_blog</title>
<link>http://shammash.homelinux.org/blog</link>
<description>... never said that!</description>
<dc:language>en-us</dc:language>
<dc:creator>shammash</dc:creator>
<dc:date>2008-10-18T18:50:30+02:00</dc:date>
<admin:generatorAgent rdf:resource="http://nanoblogger.sourceforge.net" />
<item>
<link>http://shammash.homelinux.org/blog/archives/2008/10/index.html#e2008-10-18T18_46_36.txt</link>
<title>delicious backup</title>
<dc:date>2008-10-18T18:46:36+02:00</dc:date>
<dc:creator>shammash</dc:creator>
<dc:subject>var</dc:subject>
<description><![CDATA[
A slightly improved version of
<a target=_blank href='http://snippets.dzone.com/posts/show/290'>this ruby script</a>
you can use to backup your delicious bookmarks to an sqlite3 database.<br><br>

<pre>
#!/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 = &lt;&lt;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


</pre>]]></description>
</item>
<item>
<link>http://shammash.homelinux.org/blog/archives/2008/10/index.html#e2008-10-18T14_49_47.txt</link>
<title></title>
<dc:date>2008-10-18T14:49:47+02:00</dc:date>
<dc:creator>shammash</dc:creator>
<dc:subject>var</dc:subject>
<description><![CDATA[]]></description>
</item>
<item>
<link>http://shammash.homelinux.org/blog/archives/2008/09/index.html#e2008-09-24T15_09_33.txt</link>
<title>stop software patents world day</title>
<dc:date>2008-09-24T15:09:33+02:00</dc:date>
<dc:creator>shammash</dc:creator>
<dc:subject>tech</dc:subject>
<description><![CDATA[
<br>
<a href="http://stopsoftwarepatents.org/">
<img alt="http://stopsoftwarepatents.org" src="http://stopsoftwarepatents.wdfiles.com/local--files/banners/banner-x60.png" border="0">
</a>
<br>]]></description>
</item>
<item>
<link>http://shammash.homelinux.org/blog/archives/2008/07/index.html#e2008-07-02T00_13_21.txt</link>
<title>native vde support in qemu</title>
<dc:date>2008-07-02T00:13:21+02:00</dc:date>
<dc:creator>shammash</dc:creator>
<dc:subject>tech</dc:subject>
<description><![CDATA[
The patch is
<a target=_blank href='http://lists.gnu.org/archive/html/qemu-devel/2008-07/msg00026.html'>here</a>.<br>
I hope it will get upstream.<br>]]></description>
</item>
<item>
<link>http://shammash.homelinux.org/blog/archives/2008/06/index.html#e2008-06-27T10_53_41.txt</link>
<title>tempo</title>
<dc:date>2008-06-27T10:53:41+02:00</dc:date>
<dc:creator>shammash</dc:creator>
<dc:subject>var, fun</dc:subject>
<description><![CDATA[
Ricevo in terra irlandese e pubblico un segno evidente del tempo che passa:<br>
<br>
<img border=0 alt='occhio beppe'
src='http://shammash.homelinux.org/blog/entrimg/occhio_beppe.jpg'><br>
<br>
<i>Nota: il valore di verit&agrave; non cambia sia interpretando "tempo" come
clima (si suda) che come anni (si portano gli occhiali).</i>]]></description>
</item>
<item>
<link>http://shammash.homelinux.org/blog/archives/2008/05/index.html#e2008-05-06T15_20_04.txt</link>
<title>quicksort</title>
<dc:date>2008-05-06T15:20:04+02:00</dc:date>
<dc:creator>shammash</dc:creator>
<dc:subject>tech, fun</dc:subject>
<description><![CDATA[
Let's write a quicksort implementation in
<a target=_blank href='http://www.jsoftware.com/'>J programming language</a>..<br>
<br>
<pre>
quicksort=:(($:@(<#[),(=#[),$:@(>#[))({~?@#))^:(1<#)
</pre>
<br>
<i>Many thanks to Vlad! :)</i><br>]]></description>
</item>
<item>
<link>http://shammash.homelinux.org/blog/archives/2008/04/index.html#e2008-04-01T01_29_21.txt</link>
<title>A F this K</title>
<dc:date>2008-04-01T01:29:21+02:00</dc:date>
<dc:creator>shammash</dc:creator>
<dc:subject>var, tech</dc:subject>
<description><![CDATA[
see you :)<br>
<br><br>
<img alt='google.ie' src='http://shammash.homelinux.org/blog/entrimg/ggie.gif'>
<br>]]></description>
</item>
<item>
<link>http://shammash.homelinux.org/blog/archives/2008/02/index.html#e2008-02-15T16_00_04.txt</link>
<title>fosdem 2008</title>
<dc:date>2008-02-15T16:00:04+02:00</dc:date>
<dc:creator>shammash</dc:creator>
<dc:subject>tech</dc:subject>
<description><![CDATA[
Sinceramente questa patacca mi ricorda vagamente i diari delle compagne di<br>
classe delle medie, mediamente piu` alti di tutti i libri di testo impilati.<br>
<br>
Vabbeh, mettiamolo giusto per aggiornare questo blog :)<br>
<br>
<a href="http://www.fosdem.org">
	<img src="http://www.fosdem.org/promo/going-to"
	alt="I'm going to FOSDEM, the Free and Open Source Software Developers' European Meeting" />
</a>]]></description>
</item>
<item>
<link>http://shammash.homelinux.org/blog/archives/2008/01/index.html#e2008-01-25T21_45_55.txt</link>
<title>a volte ritornano</title>
<dc:date>2008-01-25T21:45:55+02:00</dc:date>
<dc:creator>shammash</dc:creator>
<dc:subject>tech</dc:subject>
<description><![CDATA[
<pre>
Last login: Wed Dec 24 01:40:40 2003 from 192.168.1.3
</pre>]]></description>
</item>
<item>
<link>http://shammash.homelinux.org/blog/archives/2007/11/index.html#e2007-11-28T22_25_32.txt</link>
<title>gaston</title>
<dc:date>2007-11-28T22:25:32+02:00</dc:date>
<dc:creator>shammash</dc:creator>
<dc:subject>cit</dc:subject>
<description><![CDATA[<i>
You know, one day, when I was a little boy, my mother she took me on her knee<br>
and she said: "Gaston, my son. The world is a beautiful place. You must go into<br>
it, and love everyone, not hate people. You must try and make everyone happy,<br>
and bring peace and contentment everywhere you go." And so... I became a<br>
waiter...<br>
</i>
<br><br>
Monty Python - The Meaning of Life
<br><br>]]></description>
</item>
</channel>
</rss>
