Monday, April 15, 2013

Vacuum cleaning of $HOME to back it up


I've started with a simple script to compress Firefox's sqlite databases before creating a backup of my $HOME directory

alex@xubuntu:~$ cat bin/vacuumFirefox.sh
#!/bin/bash

[ -n "$(pidof firefox)" ] && {
  echo "ERROR: firefox is still running, close it first!"
  exit 1
}

counterBefore=0
counterAfter=0

for i in ~/.mozilla/firefox/*/*.sqlite; do
  fileSizeBefore=$(du -b $i|awk '{ print $1 }')
  counterBefore=$((counterBefore + fileSizeBefore))
  sqlite3 "$i" vacuum
  fileSizeAfter=$(du -b $i|awk '{ print $1 }')
  counterAfter=$((counterAfter + fileSizeAfter))
  echo "$fileSizeBefore $fileSizeAfter - $(basename $i)"
done
echo "Bytes saved: $(( counterBefore - counterAfter ))"

Here is a sample output:

Thursday, March 28, 2013

Ubuntu with the NetworkManager as a NAT gateway


Sometimes I use my Xubuntu notebook as a NAT gateway for my Windows 7 computer because its WLAN interface works in 5GHz band and Windows computer works only in 2.4GHz. So I connect my Win7 computer to my Xubuntu notebook using a crossover Ethernet cable and turn it ito a NAT gateway using a bash script.

Saturday, January 5, 2013

USB to Serial TTL cable

[Image]

I was looking for a cheap USB to Serial TTL cable that would have a 3,5mm audio plug on its end. Such a cable can easily be found on Amazon for 23,27€ which is just a road robbery. Having an old audio plug the same cable can be constructed for only 6€ and here is the algorithm:

Saturday, December 15, 2012

Annotate a JPG with its EXIF date and time

[Image]
If you need to annotate a bunch of JPG pictures the following simple bash script could come in handy. Script uses pictures EXIF date and time information but could be easily patched to include any other text. The only dependencies script has are Image Magic and awk:

Sunday, October 14, 2012

Design of a corner TV table

[Image]
Several years ago I wanted to buy a TV table that I could place into a corner. I went to every nearby furniture store but couldn't find any model designed for corners! So I had to build one myself.

Sunday, August 19, 2012

A little bit about Hilbert space-filling curve

[Image]

As a student I have investigated properties of different scanning algorithm to unwrap an N-dimensional array into one dimensional. One of the algorithms was  Hilbert space-filling algorithm. This algorithm can be applied to an array of any dimension and it is known as one of the unwrapping algorithms that preserves spatial relations between array's neighbors very well.

Monday, July 16, 2012

AVR-Stick as an infrared receiver and logger

[Image]

I have already described a project based on the AVR-Stick hardware. The next thing I wanted to try with that hardware is to create an infrared receiver and logger. In fact I wanted to emulate the dongle I described some time ago. But to emulate it I needed to know the protocol that is used. The easiest way to find out what protocol is used is to analyze signals with an oscilloscope of course but I didn't have one. So first of all I needed to implement a signal logging functionality.

Friday, June 29, 2012

AVR-stick as a temperature logger

[Image]
I've stumbled recently upon a little gem called AVR-Stick and bought two of them for about 7€ per stick. I also had a thermoregulated fan controller salvaged from a recycled computer. I decided to desolder a thermistor from that controller and put it onto the stick to use it as a USB temperature logger. Stick's ATtiny85 has an internal temperature sensor too but it should be calibrated otherwise its precision is ±10°C. Thermistor that I'm using is equivalent to the NTCLE100E3103JB0 and its resistance is 10K at 25°C. Any other NTC thermistor that has resistance around 10K at room temperature could also be used but it should be checked if manufacturer specifies Steinhart-Hart equation coefficients for it.

Thursday, June 7, 2012

Using of the xfce4-messenger-plugin

I was looking for a way to display an icon on a xfce desktop panel on some event. One possible solution is to use the xfce4-messenger-plugin. The plugin listens to messages on the D-Bus and displays them in a pop-up window or in the panel. Additionally it can display an icon if the message sent is prefixed with a identifier.
[Image]

Tuesday, June 5, 2012

dnsmasq cache size tuning

dnsmasq is a lightweight DNS forwarder and DHCP server used primarily in embedded systems (like routers) where resources are limited. DNS queries are small in size but latency introduced can be significant depending on the proximity of a DNS server that can answer the query. DNS queries are usually cached either by a web browser of by the operating system but if several clients are connecting to the Internet through a router they would all need to send 'possibly' same DNS requests over again. That's why dnsmasq running on a router has a local cache for DNS queries.