Below you will find pages that utilize the taxonomy term “Dev”
MisterHouse : Setting up “modes”
MisterHouse is a fantastic home automation software with an impressive out-of-the-box feature set, and it only gets better if you know a bit of Perl.
You can conveniently set “modes”, which are settings with states you can define and use. You can then fire events upon state change, and so are they very useful to define some sort of macros.
A few examples :
- the “Security” mode could be “on” or “off” : setting it “on” would close the shutters and activate the alarm system; setting it “off” would do the opposite;
- the “Heating” mode could be “day”, “night”, “frost protection only” : setting it on “day” would set the target temperature to 20â°C, “night” to 15â°C and “frost protection only” to 7â°C
- the “Cinema” mode could be “on” or “off” : setting it to “on” would close the blinds and dim the lights; “off” would bring those back to their former states.
Facebook API : Exporting your friends birthdays into vCards format
The following sample Facebook desktop application exports your friends birthdays in a vCard file format. This file is suitable to be imported into your GMail contacts for example.
Perl : Counting occurences of IP addresses in Apache logs
This Perl one-liner is intended to print the 10 most frequent client IP addresses in an Apache log file. It can easily be recycled to count anything, though.
Perl+Twitter : Getting @mentions from command line
This code snippet demonstrates how easy it is to collect your twitter @mentions in Perl, coupled with curl for simplicity.
Perl : Using the Finance::Quote module to get your stock prices
Finance::Quote is a Perl module which can be used to obtain stock information from various internet sources. I thought I’d rather share this code snippet as an example showing how easy it is to use, before I turn it into a bloatware with an SQL backend to compute average price per share and what not 🙂
So here is a simple snippet demonstrating how to get the price of a stock :
D-Bus introduction in Perl
As stated in Wikipedia :
D-Bus (Desktop Bus) is a simple inter-process communication (IPC) system for software applications to communicate with one another.
This post provides a simple code snippet in Perl to help you getting started with D-Bus programming.
MySQL : binary log files
MySQL uses the so called binary log files to implement master/slaves replication.
Perl : Convert time from Epoch to local time

This little Perl one-liner can get handy when you need to translate “time in seconds since the Epoch” (for example in logs) to local time :
% perl -e 'print scalar(localtime(1202484725)), "\n";'<br /> Fri Feb 8 16:32:05 2008<br /> %
This was pretty useful today when browsing through Nagios event logs, where times are given in seconds from the Epoch.
By the way, the Epoch is defined as 00:00 UTC on January, 1st, 1970.
Perl : A module to play with a GSM mobile
As you might have read in my previous post about accessing your cell phone with the AT-commands under Linux.
If not, you might want to start there for a little context.
I finally wrote and released on CPAN a Perl module which will help to automate cell phone operations such as saving/restoring the phonebook or sending an SMS.
Examples are included in the documentation. I believe I made it easy to use, but let me know if I’m wrong 😀 .
Linux + GSM : How to access your cell phone innards with Linux
This article explores your options to access your GSM cell phone from a linux system, and manipulate SMS and phonebook entries.
Doesn’t provide hints about how to unlock a GSM cell phone though 😉
Perl : Optimizing pattern searches with Regexp::Assemble
When you perform a pattern matching with multiple “or” (|) clauses, such as /pattern1|pattern2|pattern3/, Perl regexp engine will try to match each of them one after the other in sequence, resulting in poor performance if you have a long list of “or” clauses.
In order to optimize such a pattern matching, you can use the Regexp::Assemble module.
PostgreSQL : create a user, a database and grant accesses
The following step-by-step will let you create a user, a database (DB) and grant full access to the user to this DB.
Scripting Twitter with Perl + LWP
A little follow up on yesterday article about scripting Twitter with cURL: the solution was working, but somehow inconvenient. Not practical to have to go and fetch the user id every time you want to send a direct message !
This time, I scripted Twitter direct message with Perl and LWP (libwww-perl), for a much more convenient solution. I designed it to be used like a sort of universal paging service.
Scripting Twitter with cURL
Twitter already provides an API but it is currently very limited. It will let you fairly easily change your status, but won’t let you send a direct message.
Comes in cURL. cURL is a very versatile command line utility which is designed to script web pages interactions. As a little demo, I’ll show you how to use it to easily overcome the shortcomings of Twitter’s API.
Dump an entire SubVersioN repository into a flat file
There are many reasons you might want to dump your SVN repository to a flat file : for example to simplify backup operation, to transfer to another server, or to convert your repository from FSFS to BDB or the opposite.
Fun with google maps
I’ve written 2 sample applications to demonstrate how easy it is to use the API v2 of Google Maps.
I was honnestly surprised to see how easy it actually is… Have a look at the source of the pages and see for yourself 😉
DocBook
Bored of fighting with MS-Word to have proper titles numbering ? Tired of messing around styles ? Want a more “meaning oriented formating” and less “aesthetic oriented formating” ? Would like to generate HTML, PDF, WindowsHelp, or anything from the same source file ?
Have a look at DocBook ! DocBook is a document standard which lets you do all of this, and much more …
And XMLMind XML Editor is a nice free (like beer not ideas) editor which lets you edit DocBook Documents in a WYSIWYG fashion.
Websites with Catalyst
If you like Perl and you make dynamic websites with databases backends, Catalyst is definitely worth a look.
It is basically an MVC engine for websites. It lets you nicely separate your business logic, the display and the database backend.
It has extended plugins to deal with things like authentications, sessions, templates, RSS, and God knows what 🙂
It can integrate Apache, and harness mod_cgi’s power for high-performance web applications.
It is a little bit tricky to get it right at the beginning, but there are nice tutorials.
Deploying Perl apps
I usually code my perl programs on a development machine, and then ty to make in run in the production environment.
I used to manage by myself the various needed packages and tried to have them installed on the production environment as needed.
And one day I had to make a script run on a machine where Perl itself was not even installed…
This has been a nightmare until recently, that is to say until I discovered the PAR module. PAR is closed to the Java JAR files.
Character conversions in Perl
If you want to convert strings from, say, UTF-8 to Latin1, then you can do this as simply as this :
use Unicode::String qw(utf8);
print utf8(“string in utf-8”)->latin1
Easy ? 😀
Coding a Jabber Bot in Perl
I finally got it to work and it is not so difficult with the right packages (Net::XMPP) and parameters …
#! /usr/bin/perl</code>
use strict;
use warnings;
use Net::XMPP;
#################
# Config params #
#################
my $hostName = 'jaim.at';
my $portNumber = 5222;
my $componentName = 'jaim.at';
my $userName = 'totosk1008';
my $passWord = 'totosk1008';
my $resource = 'NiceLittleBot';
my $tls = 0;
my $connectionType = 'tcpip';
my $debugLevel = 0;
# Create the client
my $bot = new Net::XMPP::Client(debuglevel => $debugLevel);
$bot->SetCallBacks(
onconnect => &connectedCB, # gets called when connected
onauth => &authedCB, # when authenticated
ondisconnect => &disconnectedCB, # when disconnected
);
$bot->SetMessageCallBacks( # callback for messages
chat => &messageCB, # chat-type messages
);
$bot->Execute( # entering the main loop
hostname => $hostName,
port => $portNumber,
tls => $tls,
username => $userName,
password => $passWord,
resource => $resource,
register => 0,
connectiontype => $connectionType,
);
##############
# Callbacks #
##############
sub messageCB { # call back implementing the echo
my $sid = shift;
my $msg = shift;
my $from = $msg->GetFrom;
my $to = $msg->GetTo;
my $name;
my $data;
print "From : ", $from, "\n",
"Subject : ", $msg->GetSubject, "\n",
$msg->GetBody, "\n";
$name = $msg->GetBody;
$data = $msg->GetBody;
print ">>$name<<\n";
print $data, "\n";
$bot->MessageSend(
to => $from,
from => $to,
resource => 'Gaim',
type => $msg->GetType,
subject => $msg->GetSubject,
body => $data,
);
}
sub connectedCB {
print "Connected\n";
}
sub authedCB {
print "Authed\n";
$bot->PresenceSend;
}
sub disconnectedCB {
print "Disconnected\n";
}
me <- proud ! ;-)
I finally finished it (though I expect to have to make some changes in the future …) :
Now I can setup my home automation events in MisterHouse throught my Mozilla Calendar ! The code has been submited and accepted for being integrated in MisterHouse and will be in the next release 🙂
Code is here.
Parsing an ICal file with Perl
I finally almost got it …
Here is a code snippet for parsing and showing pieces of an ICal file :
use strict; use warnings; use Data::ICal; use Data::ICal::DateTime; use DateTime; my $cal = Data::ICal->new(filename => 'holidays.ics'); my @events = $cal->events(); foreach my $event (@events) { print "summary:", $event->property('summary')->[0]->value, "n"; print "dtstart:", $event->start, "n"; print "dtend:", $event->end, "n"; } print DateTime->now, "n";
What I want to do ? Drive my home automation events with my Mozilla Calendar !! I’ll soon be there, if I gather enough time to do it !