Syncing with J-Pilot via Bluetooth

Probably I am a little bit old-fashioned, but I still use J-Pilot on my PC and my Tungsten T5 and sync them. It mostly serves as a kind of backup so I have my valuable address and datebook data on separate media. So in case my PC gets inaccessible then I have my data on this device at least.

These are the commands I use.

echo 1 > /proc/sys/net/ipv4/ip_forward
/usr/bin/dund --listen --channel 1 --pppd /usr/sbin/pppd call dun
hciconfig hci0 piscan

File /etc/ppp/peers/dun is

debug
115200
noauth
nopersist
local
passive
netmask 255.255.255.0
192.168.178.118:192.168.178.119
ms-dns 192.168.178.1

Local address 118 of my PC is mapped to 119.

On the Palm you have to configure your bluetooth connection. Below are screenshots of this.

Go to preferences and choose Connection.
IMG_20140413_124739

Here is the Connection screen.
IMG_20140413_124800

IMG_20140413_124816

IMG_20140413_124836

IMG_20140413_124912

IMG_20140413_124933

IMG_20140413_125010

Go to HotSync screen and open the menu, i.e., third symbol after home symbol at the bottom.
IMG_20140413_124652

In this menu you choose which conduits to sync. If you sync all of them this could take too much time. So I deselect most of them.
IMG_20140413_171003

Now you can go to your HotSync screen and tap the HotSync symbol.

This follows mostly what was written in handhirn or in ArchWiki: Hotsync over Bluetooth.

There is an interesting article on the Palm history in Palm, a Silicon Valley soap opera, on its rise and demise. Palm went though a series of brands, from Palm, U.S. Robotics, 3Com, Handspring, Palm Computing, PalmSource and palmOne, ACCESS, finally HP. Some quotes from Palm, a Silicon Valley soap opera: What else might HP get? The management team? Seriously? Have you seen how Palm’s management team managed Palm? What about the webOS engineers? Well, if HP had waited a few months, Palm would have imploded, and those engineers could have been picked up for a mere recruiting fee.

Youtube video to mp3

Assume you want to download just the music of below video on Youtube, so you can listen to the music on your phone, while you are on the road.

Here are the necessary steps on the command line:

youtube-dl www.youtube.com/watch?v=aHjpOzsQ9YI
mv Crystallize\ -\ Lindsey\ Stirling\ \(Dubstep\ Violin\ Original\ Song\)-aHjpOzsQ9YI.mp4 LindseyStirling-Crystallize.mp4
avconv -i LindseyStirling-Crystallize.mp4 LindseyStirling-Crystallize.mp3

One can use ffmpeg instead of avconv. ffmpeg was initially written by this incredible French Fabrice Bellard, who is also the author of tcc.

avconv or ffmpeg on Ubuntu do not come with MP3 support by default. Sou you have to install this by

apt-get install libavcodec-extra-53

Here are the relevant versions involved:

$ youtube-dl --version
2013.12.17.2

$ avconv -version
avconv version 0.8.10-4:0.8.10-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Feb  6 2014 20:56:59 with gcc 4.6.3
avconv 0.8.10-4:0.8.10-0ubuntu0.12.04.1
libavutil    51. 22. 2 / 51. 22. 2
libavcodec   53. 35. 0 / 53. 35. 0
libavformat  53. 21. 1 / 53. 21. 1
libavdevice  53.  2. 0 / 53.  2. 0
libavfilter   2. 15. 0 /  2. 15. 0
libswscale    2.  1. 0 /  2.  1. 0
libpostproc  52.  0. 0 / 52.  0. 0

See also: superuser: How can I convert MP4 video to MP3 audio with ffmpeg?

For moving the MP3 file to my Android phone I use SSHelper, see also ssh and rsync for Android.

Enabling Power-Aware Applications on Linux Using Cyrogenic Module

A post in Phoronix: “Cryogenic” Linux Kernel Drops Power Use shed light on a Linux kernel module improving power consumption.

This module was written as part of a master thesis in computer science at TUM (Technical University of Munich) by Alejandra Morales Ruiz. The thesis is well written, showing what others have already done in this area, providing evidence that the new approach reduces power consumption.

The thesis can be downloaded on https://gnunet.org. More on Cyrogenic in Cyrogenic.

Some excerpts from the thesis and above web-site: The whole implementation of Cryogenic is embedded in a kernel module that works as a character device driver. When Cryogenic is loaded, a set of character devices is created and a subset of system calls is defined. The system calls handle the character devices through the device nodes created under /dev/cryogenic/. This is the API that developers will use later to manage the interaction between applications and hardware devices. (…) Non-urgent tasks may not only force devices to wake up, but also prevent them from going to sleep, since they may reset the timeout to enter the sleep state. Therefore, the second action taken by Cryogenic is to lengthen the duration of idle periods. This way, the overall consumption decreases and it is more likely that the device enters into sleep. Cryogenic is capable to achieve savings between 1% and 10% for a USB WiFi device.

morales1

The thesis takes a UDP client as example.

Calculating number of seats in parliament using d’Hondt’s method

Wikipedia contains an article on d’Hondt’s method for calculating the number of seats given the number of votes for each party. I wrote a short Perl program for its calculation including the case when d’Hondt’s method by its design leads to drawing the lots. Its input contains a list of party names and its corresponding votes. The number of seats is given as parameter -s. This implementation of d’Hondt uses integer division and rounds the division to the lower integer (floor).

#!/usr/bin/perl -W
# Calculate seats in parliament according d'Hondt's method

use strict;
use Getopt::Std;
my %opts = ('d' => 0, 's' => 2);
getopts('ds:',\%opts);
my $s = (($opts{'s'} > 0) ? $opts{'s'} : 2);

my (@F,@votes,@party,@seat,@calc,@divisor,$i,$j,$n,$max,$multi,@drawing);

while (<>) {
        @F = split;
        push @party,$F[0];
        push @votes,$F[1];
        push @calc,$F[1];
}

for ($i=0; $i<=$n; ++$i) {
        ($seat[$i],$divisor[$i]) = (0,1);
}

# $u is used seats so far
for (my $u=0; $u<$s; ++$u) {
        ($max,$j) = ($calc[0],0);       # calculate maximum in @calc
        $drawing[$multi=0] = 0;
        for ($i=1; $i<=$n; ++$i) {
                if ($calc[$i] > $max) {
                        ($max,$j) = ($calc[$i],$i);
                        $drawing[$multi=0] = $i;
                } elsif ($calc[$i] == $max) {
                        $drawing[++$multi] = $i;
                }
        }
        if ($u + $multi >= $s) {
                printf("Drawing of lots for %d seats required for parties:", $s - $u);
                for ($i=0; $i<=$multi; ++$i) {
                        print " $party[$drawing[$i]]";
                }
                print "\n";
                last;
        }
        $seat[$j] += 1;
        $divisor[$j] += 1;      # this is specific for d'Hondt
        $calc[$j] = int($votes[$j] / $divisor[$j]);
}

for ($i=0; $i<=$n; ++$i) {
        print "$party[$i] - $seat[$i]\n";
}

Code is also in GitHub.

Here are some results.

Test case #1 from Wikipedia where 4 parties compete for 8 seats in parliament:

Party A        100,000
Party B         80,000
Party C         30,000
Party D         20,000

printf "A 100000\nB 80000\nC 30000\nD 20000\n" | dHondt -s8 gives

A - 4
B - 3
C - 1
D - 0

Test case #2 from Bundeswahlleiter with 3 parties again competing for 8 seats:

Party A       10,000
Party B        6,000
Party C        1,500

Running printf "A 10000\nB 6000\nC 1500\n" | dHondt -s8 produces

A - 5
B - 3
C - 0

Test case #3 from R function to calculate the seats in parliament with 5 parties competing for 10 seats:

Party A         448
Party B       7,685
Party C       5,445
Party D         482
Party E       6,266

Running printf "A 448\nB 7685\nC 5445\nD 482\nE 6266\n" | dHondt -s10 gives

A - 0
B - 4
C - 3
D - 0
E - 3

I think the given implementation in R is faulty, although for above example it is correct.

Test case #4 checks the borderline.

Party A       8
Party B       8
Party C       8

Running printf "A 8\nB 8\nC 8\n" | dHondt -s1 gives

Drawing of lots for 1 seats required for parties: A B C
A - 0
B - 0
C - 0

Test case #5 also checks borderline. Input as given in test case #4 but number of seats is 2. Perl program computes

Drawing of lots for 2 seats required for parties: A B C
A - 0
B - 0
C - 0

Some historical notes on d’Hondt. According Friedrich Pukelsheim in his report seen in wahlrecht.de the naming of various methods used for seat allocation are good examples of Stigler’s law of eponymy. D’Hondt’s method was already used by Thomas Jefferson. D’Hondt’s method is also known under the name Hagenbach-Bischoff method.

Statistics of this Blog: 2.600 Views, 78 Countries, 20 Comments

In two previous posts

  1. My Blog Statistics by Country and
  2. Statistics of this Blog: 1.000 Views, 60 Countries, 10 Likes

I showed the statistics of this blog in September and October last year. The last few weeks I was quite heavily loaded with work, so I couldn’t announce that I broke the 2.000 views barrier. Here are the numbers.

viewsFeb2014World

Above picture does not show all 78 countries. It is quite interesting that this time the US has clearly outnumbered any other country, even when all european countries are combined. In October 2013 Germany alone had the lead.

viewsFeb2014

Plotting this with gnuplot:

viewsPerMonth

Commands:

set terminal png
set output "outputfile.png"

set xdata time
set timefmt "%Y/%m"
set xrange ["2014/01":"2015:01"]
set format x "%b"

plot "inputfile" using 1:2 with lines title 'Views per month'

using data entered as

2014/01 24
2014/02 17
2014/03 23
2014/04 28
2014/05 26
2014/06 60
2014/07 64
2014/08 116
2014/09 324
2014/10 328
2014/11 260
2014/12 564
2015/01 735

So far the following posts seem to be the most viewed:

  1. Malcolm Gladwell: Don’t go to Harvard, go to the Lousy Schools!
  2. OpenGL Program: Earth with Moon Rotating around Sun
  3. Programming in Excel VBA Compared To LibreOffice (OpenOffice) Calc
  4. About
  5. Gil Kalai on Zhang’s Breakthrough in Number Theory
  6. How to use TrueType Fonts in xterm or uxterm
  7. Collected Links
  8. What Makes a Good Programming Environment?
  9. Torricelli’s Trumpet: Infinite Surface Area but Finite Volume
  10. Working with System V IPC queues in Perl and PHP

The relative order of the About-page is a confirmation what was written here: Why About Pages are Essential by timethief.

Where do I get my referrers? By far this is from Google searches, see below.
referFeb2014b

Scheduling Cron Jobs on Business Days

I found a marvelous way to run jobs on certain business days via cron. The solution was depicted in Scheduling Cron Jobs on Business Days and it was written by a user named rdcwayx. The idea is to use the output of cal and some Awk or Perl string-trickery.

The output of cal looks like this

   February 2014      
Su Mo Tu We Th Fr Sa  
                   1  
 2  3  4  5  6  7  8  
 9 10 11 12 13 14 15  
16 17 18 19 20 21 22  
23 24 25 26 27 28

Here is the procedure, named chkbusday, to decide whether current date is $1-st business day of the month. The point is to extract the numbers below Mo-Fr, then split them, put each number into an array. The array index is $1-st business day, disregarding holidays.

#!/usr/bin/perl -W

use strict;
my ($i,$s) = (0,"");
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
exit 1 if ($#ARGV < 0);
open(IN,"cal -h |") || exit 2;    # turn off highligthing of today
while (<IN>) {
        next if (++$i <= 2);
        $s .= substr($_,2,15);
}
my @F = split(/\s+/,$s);
exit 3 if ($#F < $ARGV[0]);
exit ($F[ $ARGV[0] ] != $mday);

So with chkbusday it is now easy, for example, to check whether the current day is the fourth business day. Just prepend each command in cron with

chkbusday 4 && command

A sample cron configuration is given below using above test for specific business day within a month.

# On 4th business day at 12:03 remind people
3 12 1-24 * *   chkbusday 4 && some-command
#
# On 5th business day at 09:03 remind again
3 9 1-24 * *    chkbusday 5 && another-command

It looks that using cal and cutting out parts of its output is easier than redoing the calculation in ncal. Source code of ncal is here: ncal.c.

Watch out for the difference between cal and ncal. Ubuntu uses ncal by default. On Red Hat one can use “cal -s” for starting with Sunday — this option is not available in Ubuntu. On Ubuntu “cal -h” suppresses highlighting. This option is not available on Red Hat’s version of cal.