Archive for May, 2010
Tasque Conky Script
Posted by Boris in Miscanelous on May 14, 2010
Here is the script I’ve written to display on conky next Tasque ToDo items:
#!/usr/bin/env python import sqlite3 from os.path import expanduser import pprint from sys import argv from math import ceil limit = 0 widthLimit = 0 if len(argv) > 1: limit = int(argv[1]) if len(argv) > 2: widthLimit = int(argv[2]) con = sqlite3.connect(expanduser("~/.config/tasque/sqlitebackend.db")) con.isolation_level = None cur = con.cursor() counter = 0 for lastIteration in range(0,2): if lastIteration == 0: cur.execute("SELECT Name, State FROM Tasks WHERE DueDate >= 0 ORDER BY DueDate asc, Name COLLATE NOCASE asc;") else: cur.execute("SELECT Name, State FROM Tasks WHERE DueDate < 0 ORDER BY Name COLLATE NOCASE asc;") currentItem = cur.fetchone() while currentItem and ((limit != 0 and counter < limit) or limit == 0): if(currentItem[1] == 0): if(widthLimit == 0): print currentItem[0].encode("utf-8") else: for i in range(int(ceil(len(currentItem[0].encode("utf-8"))/widthLimit + 1))): print currentItem[0].encode("utf-8")[i*widthLimit:(i+1)*widthLimit] counter+=1 currentItem = cur.fetchone() con.close()
The .conkyrc line to display 5 next ToDo items using this script is:
${exec tasqueTasksScript 5}If you want to go to the next line after 50 characters, use:
${exec tasqueTasksScript 5 50}Amazon MP3 downloader on Lucid…
Posted by Boris in Miscanelous on May 13, 2010
The new Ubuntu has been released, and with it, new versions of software packages. Some of you may have remarked that the Amazon MP3 downloader doesn’t seem to work any more (actually, I expect it to be not-functional, but I haven’t had it before upgrading to lucid, so all I can say is that installing it AFTER the upgrade doesn’t work. By the way if someone has the problem with the software installed BEFORE the upgrade, let me know, I’ll upgrade this post with the new information).
Though, I’ve got it installed, and it works. All I’ve done is to get old needed packages from the Hardy package repository, and get them installed. Then I’ve installed the Amazon mp3 downloader, and now, all works like a charm. I know this workout is not the best way to get things done, but until Amazon updates its mp3 downloader, I think that’s the best way to make it work.
Edit: I’ve made an architecture-independent shell script (I’ve only tested it on my i686 box, a review on an other architecture will be welcomed) to prepare your distribution for Amazon MP3 downloader. Download it here, then check “Allow executing file as program” in Properties > Permissions, then launch it in a terminal.
Ruby
Posted by Boris in Software and Development on May 1, 2010
Yesterday, a friend of mine asked me if I’d recommend Ruby programming language. I’ve said that, even if I had never tried it, it is said to be very reliable. Nevertheless, I’ve decided to try it, just by curiosity. So I’ve gone to the Ruby language website, and there, I’ve found some code, a hello word example:
# The Greeter class class Greeter def initialize(name) @name = name.capitalize end def salute puts "Hello #{@name}!" end end # Create a new object g = Greeter.new("world") # Output "Hello World!" g.salute
I tried it, and until today, forgotten it. But, today, I wanted to do a script to generate all IP addresses in an IP block. I first thought to do it in python, a language I’m more familiar with, but, still driven by curiosity, I’ve wondered if I could do it in Ruby. And that’s what it gave:
#!/usr/bin/env ruby # The NetMask class class NetMask @mask @baseIP def initialize() @mask = 0 @baseIP = 0 end def parseFromString(str) array = str.split(".") if array.length != 4 array = str.split("-") end if array.length == 4 @mask = array[0].to_i + array[1].to_i * 256 + array[2].to_i * 65536 + array[3].to_i * 16777216 end end def setFromInt(value) @mask = ('1' * value + '0' * (32 - value)).to_i(2) end def parseBaseIPFromString(str) array = str.split(".") if array.length != 4 array = str.split("-") end if array.length == 4 @baseIP = array[0].to_i * 16777216 + array[1].to_i * 65536 + array[2].to_i * 256 + array[3].to_i end end def formatIntToIP(int) return (int/16777216).to_s+ "." + ((int/65536)%256).to_s + "." + ((int/256)%256).to_s + "." + (int%256).to_s end def getMask() return formatIntToIP(@mask) end def getBaseIP() return formatIntToIP(@baseIP) end def generateIPList() array = [] for i in (@baseIP & @mask) .. ((@baseIP & @mask) | ((2**32)-1)-@mask) do array.push(formatIntToIP(i)) end return array end end mask = NetMask.new() args = ARGV[0].split("/") if args.length == 2 mask.parseBaseIPFromString(args[0]) mask.setFromInt(args[1].to_i) else mask.parseBaseIPFromString(ARGV[0]) mask.setFromInt(ARGV[1].to_i) end puts mask.generateIPList()
Just for information, the help is here.


