Archive for the ‘work’ Category

The long awaited migration from Qmail to Postfix

I’ve been running qmail based mail servers for years. And you can imagine how many if I am planning this migration from at least 3 years. To be very honest qmail does a very very good job. This is the reason it took so much time to actually do it. In fact qmail has only one problem: it’s stuck in the past. If you want to install something new: say SPF of DKIM you need to patch, recompile. And who would want to do that when it has such a perfect install running for so much time untouched ? Of course if you are ready to make this step then you are probably know you don’t want to do that any time soon so maybe it’s better to install something else. Say postfix? But what about this nice install, and the migration? This is the thinking which took so much time for me and it was only after doing the hardy to lucid upgrade that I decided to be bold enough to do it :) (more…)

The value of “.” (a bug’s life)

Track summary no 1463: Client detected a bug. Bug replication took 2.5h. Bug correction took 2 min. Modification consisted of unification of several cases where position of b in XML is variable a.b => a..b. Project compilation 10 minutes. Actual difference in code is insignificant. Total time: over 3h.

Status RSS plugin for pidgin

As a pidgin user I am used at not expecting many fancy things but one of the features I’ve wished for some time is a plugin which updates the status automatically to the last entry in a RSS feed. As an example I’d like to update the status to the last post on my blog. So, even if I don’t like perl too much here is a simple plugin which does just that. It’s inspirationaly called: Status RSS :)

(more…)

Delete self-pings

It seems that self-pings are bad for Google page ranking. Well, I have never spended too much time thinking about SEO but I find them a bit clutering and thus I’ve decided to remove them. There are some plugins which block new self-pings but none which deletes the existing ones. So here is a mysql command which does just that:

Warning: don’t execute sql commands on your db if you don’t know anything about what sql is, it might ruin your base.

SELECT count(*) FROM {prefix}_comments WHERE comment_type = 'pingback' AND
    locate((SELECT option_value FROM {prefix}_options WHERE option_name = 'siteurl'), comment_author_url) = 1;
DELETE FROM {prefix}_comments WHERE comment_type = 'pingback' AND
    locate((SELECT option_value FROM {prefix}_options WHERE option_name = 'siteurl'), comment_author_url) = 1;

Replace the {prefix} with your db tables prefix.

Python xml namespace parsing with libxml2

The goal of this tinkering was simple: to parse a KML file for further interpretation and use using python and libxml2. (more…)

Tethered capture with ubuntu and D450

Shooting a photo and the imediately seeing it on a large monitor is a feature I’ve always wished. I don’t say live view on a display but instant copy and display would suffice. And actually, as I found out, it’s quite easy to achieve on Ubuntu Linux (10.04) with a Canon D450. (more…)

Koha search #2

As I said in the previous post related to koha search system things are a bit more complicated than you might assume as someone using sql queries to do a search. Everything is done in Zebra and Zebra is a matter of indices.

(more…)

Koha search #1

For people used to web searches and database oriented application Koha way of dealing with searches (since v.3) might seem a bit alien. This is a small set of notes related to some not very obvious questions which I had to answer in order to do some configurations which seemed trivial at the beginning. I am not saying this is wrong or ineffective, just different and different means time to learn. I’m writing this to help you reduce this time.

(more…)

Mixing generated with mxml code

The problem this example tries to solve is the following: you have a Container component (Accordion, TabNavigator, etc.) and you wish it’s content to be generated dynamically but inside this generated content to use some content which is defined in the mxml, inside the Container. For those with Tapestry experience this behaviour is similar to the @RenderBody component.

<my:CustomWrapper ...>
    <mx:VBox> ... </mx:VBox>
</my:CustomWrapper>

This is very similar to a Container definition but the VBox will not end as a child of CustomWrapper but further down in the hierarchy.

Actually the main trick is to rewrite the DefaultProperty to something else than: childDescriptors since the childDescriptors property is used to create the children of the component (look inside Container.as if curious).

Your component will look similar to:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
 <mx:Metadata>
 [DefaultProperty("children")]
 </mx:Metadata>
 <mx:Script>
 <![CDATA[

 private var _children:VBox;

 public function set children( value:* ):void{
 _children = value as VBox;
 invalidateProperties();
 }

 public function get defaultSearch():VBox{
 return _children;
 }

 override protected function createChildren():void {
 super.createChildren();
 //add the _children somewhere else in the hierarchy
 }

 ]]>
 </mx:Script>
 <mx:HBox>
... other components here,
 </mx:HBox>
</mx:VBox>

Some other interesting links on this subject:

Programmatically get the MAC address in C

This is a small example on how you can get the MAC address in C both in Linux and Windows. The example searches in fact the MAC address corresponding to a given IP address and returns it.

/*
 * mac.cpp
 *  Created on: May 25, 2010
 *      Author: len
 */

#ifdef WIN32

#include <stdio.h>
#include <Windows.h>
#include <Iphlpapi.h>
#include <Assert.h>
#pragma comment(lib, "iphlpapi.lib")

/**
 * @return the mac address of the interface with the given ip
 */
char* getMAC(const char *ip){
 PIP_ADAPTER_INFO AdapterInfo;
 DWORD dwBufLen = sizeof(AdapterInfo);
 char *mac_addr = (char*)malloc(17);

 AdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof(IP_ADAPTER_INFO));
 if (AdapterInfo == NULL) {
 printf("Error allocating memory needed to call GetAdaptersinfo\n");
 return NULL;
 }

 // Make an initial call to GetAdaptersInfo to get the necessary size into the dwBufLen variable
 if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == ERROR_BUFFER_OVERFLOW) {
 FREE(AdapterInfo);
 AdapterInfo = (IP_ADAPTER_INFO *) malloc(dwBufLen);
 if (AdapterInfo == NULL) {
 printf("Error allocating memory needed to call GetAdaptersinfo\n");
 return NULL;
 }
 }

 if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == NO_ERROR) {
 PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info
 do {
 sprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X",
 pAdapterInfo->Address[0], pAdapterInfo->Address[1],
 pAdapterInfo->Address[2], pAdapterInfo->Address[3],
 pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
 printf("Address: %s, mac: %s", pAdapterInfo->IpAddressList.IpAddress.String, mac_addr);
 if(strcmp(ip, pAdapterInfo->IpAddressList.IpAddress.String) == 0){
 printf(" matches\n");
 free(AdapterInfo);
 return mac_addr;
 }
 printf("\n");
 pAdapterInfo = pAdapterInfo->Next;        
 }while(pAdapterInfo);                        
 }
 free(AdapterInfo);
 return NULL;
}
#endif

#ifdef linux
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

/**
 * @return the mac address of the interface with the given ip
 */
char *getMAC(const char *ip){
 struct ifaddrs *ifaddr, *ifa;
 int family, s;
 char host[NI_MAXHOST];
 struct sockaddr *sdl;
 unsigned char *ptr;
 char *ifa_name;
 char *mac_addr = (char*)calloc(sizeof(char), 18);

 if (getifaddrs(&ifaddr) == -1) {
 perror("getifaddrs");
 return NULL;
 }

 //iterate to find interface name for given server_ip
 for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
 if (ifa->ifa_addr != NULL){
 family = ifa->ifa_addr->sa_family;
 if(family == AF_INET){
 s = getnameinfo(ifa->ifa_addr, (family == AF_INET)?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6),
 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
 if (s != 0) {
 printf("getnameinfo() failed: %s\n", gai_strerror(s));
 return NULL;
 }
 printf("address: %s\n", host);
 if(strcmp(host, ip) == 0){
 ifa_name = ifa->ifa_name;
 printf("matching interface name: %s\n", ifa_name);
 }
 }
 }
 }

 //iterate to find corresponding ethernet address
 for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
 family = ifa->ifa_addr->sa_family;
 if(family == PF_PACKET && strcmp(ifa_name, ifa->ifa_name) == 0){
 sdl = (struct sockaddr *)(ifa->ifa_addr);
 ptr = (unsigned char *)sdl->sa_data;
 ptr += 10;
 sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5));
 printf("found mac address: %s\n", mac_addr);
 break;
 }
 }
 freeifaddrs(ifaddr);
 return mac_addr;
}
#endif

int main(int argc, char *argv[]){
 char *mac = getMAC(argv[1]);
 if(mac != NULL){
 printf("mac: %s\n", mac);
 }
 return 0;
}

This example mixes various informations found on the net. The windows version is based on this example. In order to compile this example under windows you need to disable the precompiled headers (tested in VC express 2008). The linux version just iterates interfaces and matches the name of the PF_PACKET (ethernet) with AF_INET (TCP) in order to find the mac of a given ip.

Related Posts with Thumbnails