Guy Rutenberg

Keeping track of what I do

Eject Your Kindle and Reconnect under Linux

without comments

I am Your User suggested a method to eject your Kindle in Linux. While his method works, you don’t need to specify the partition number. E.g.

$ sudo eject /dev/sdd

where /dev/sdd is the device file of the Kindle.

But what if you want to reconnect it back without plugging in and out the usb cable? You can add the -t switch.

$ sudo eject -t /dev/sdd

Even though it prints the following error:

eject: CD-ROM tray close command failed: Input/output error

it works, and the Kindle reappears in KDE.

Written by Guy

November 6th, 2010 at 4:02 pm

Posted in Linux,Tips

Tagged with

Django Backup Script

without comments

This is a backup script for Django projects. It’s able to automate backups to a local folder and a remote FTP server of both the database and files. It somewhat old and has a few limitations, mainly supporting only MySQL and not supporting the new way for specifying databases introduced in Django 1.2.

It’s loosly based on my WordPress backup script and inspired the database settings auto-detection found in the newer Wordrpess backup script.

Usage is simple:

$ django_backup /path/to/my/proj
$ django_backup --db-only /path/to/my/proj

The latter command only backups the database.

The script uses a few configuration variables in the top of the script to set the folder which the local backups are kept in and the remote FTP server settings. The database settings are extracted directly from the settings.py of the backed-up project.
Read the rest of this entry »

Written by Guy

October 14th, 2010 at 10:01 pm

Posted in Bash

Tagged with ,

Searching for Updates without emerge

without comments

The normal way to see which installed packages have available updates on Gentoo is running

$ emerge -puv world

And then you usually select the packages you really want to update and emerge them. However this workflow has several downsides:

  1. It’s slow. When portage checks for updates this way it fully resolves all the dependencies. This process is unnecessary, as in many cases you aren’t interested in updating all the packages, furthermore in their dependencies.
  2. It may fail. When portage fails to resolve the dependencies, it will either complain or completely fail. If it complains, it isn’t really that bad, except for the time used for resolving the unanswered dependencies. Sometimes it fails completely (usually when masking is involved) and won’t display any of the available packages, hence leaving the user in the dark (except for some dependency error message).
  3. It displays lot’s of output. Many times you’re not interesting in seeing the dependencies that will be updated if you emerge every package in the world file. It’s just confusing and distract you from the interesting updates for packages in the world file.

The following scripts tries to work around these problems. It works by querying the portage API for the best version available for each package in the world file. If that version isn’t installed it reports that there are updates waiting for that package. The script runs faster then emerge -pvu world and only displays the packages from the world file. If you find a package that you want to upgrade you can emerge it separately to see the required dependencies.

Read the rest of this entry »

Written by Guy

September 19th, 2010 at 11:19 pm

Posted in Linux

Tagged with

Capturing Video and Converting to H.264 using ffmpeg

with 2 comments

8-millimeter video tapes seem to slowly fade to oblivion. In order to save old family videos recorded in this format, I’ve decided to digitize them.

After a quick try with vlc, I’ve understood that it wasn’t the right tool for the task. It crashed with a cryptic error message every time I’ve tried to encode H.264 video, and it seemed that it best suited for real time encoding. Doing real time encoding, is sub-optimal as I can’t reach high quality encoding is a reasonable bit rate.

So I looked for another tool and recalled ffmpeg. While ffmpeg provided everything I looked: high quality video encoding using H.264 and stability, it wasn’t an easy start. ffmpeg’s defaults are notoriously ill-chosen. After hours of going through man pages, I’ve managed to capture and convert video tapes into high quality (encoded) digital video.

Basically the process involved capturing the raw video into a temporary file and then preform a two-pass encoding using H.264.
Read the rest of this entry »

Written by Guy

September 10th, 2010 at 7:21 pm

Posted in Tutorials

Tagged with ,

spass-2.0 – Secure Password Generator

without comments

This is a complete rewrite of my secure password generator. The new version uses my a true random number generator (and here).

The major change was using the new true random number generator in order to ensure strong passwords. Less significant changes include an easy way to specify password’s strips, and some calling convention changes.

Usage examples:

$ ./spass
E5pT35Fg
$ ./spass -l 14
R$tfOm4g_yRQ2J
$ ./spass -s 0-9a-f -l 32
8b5f14a1eeaabe58c2878ab5416a9ebb

Download the tarball spass-2.0.tar.bz2. The program depends on Boost‘s program_options (it was tested against version 1.37 and 1.42 and should work with other versions too).

Written by Guy

August 21st, 2010 at 2:44 pm

Posted in Projects,spass

Tagged with , ,

Statistical Tests for My Audio Based Random Number Generator

without comments

In May I’ve written about a way to generate random number from audio noise. Basically it went like this:

  1. Get audio sample from the microphone.
  2. Push the least significant bit to a buffer.
  3. Repeat steps 1-2 until the buffer is full (buffer size == block size for the hash function).
  4. Apply the hash function on the buffer.
  5. Get random bits from the digest.

In order to continue developing this random number generator (RNG), I’ve written a C++ class that simplifies working with it.
Read the rest of this entry »

Written by Guy

August 13th, 2010 at 12:37 am

Posted in C/C++,Projects

Tagged with ,

Deleting Comments from Tickets in Trac

without comments

Spammers apparently love Trac. After trying to fighting spam tickets and later installing the SpamFilter plugin, I’ve managed to control spam tickets in the Open Yahtzee Trac site.. But now spammers started spamming in the ticket comments. The bad news is that Trac (at least in version 0.11) doesn’t have built-in facilities to completely remove ticket comments.


Read the rest of this entry »

Written by Guy

May 19th, 2010 at 3:42 pm

Posted in Tips

Tagged with

Audio Based True Random Number Generator POC

with 3 comments

Few days ago I came up with an idea to create a true random number generator based on noise gathered from a cheap microphone attached to my computer. Tests showed that when sampling the microphone, the least significant bit behaves pretty randomly. This lead me to think it might be good source for gathering entropy for a true random number generator.
Read the rest of this entry »

Written by Guy

May 14th, 2010 at 3:18 pm

Posted in Projects,Python

Tagged with ,

Python’s base64 Module Fails to Decode Unicode Strings

without comments

If you’ve got a base64 string as a unicode object and you try to use Python’s base64 module with altchars set, it fails with the following error:

TypeError: character mapping must return integer, None or unicode

This is pretty unhelpful error message also occurs if you try any method that indirectly use altchars. For example:

base64.urlsafe_b64decode(unicode('aass'))
base64.b64decode(unicode('aass'),'-_')

both fail while the following works:

base64.urlsafe_b64decode('aass')
base64.b64decode(unicode('aass'))

While it’s not complicated to fix it (just convert any unicode string to ascii string), it’s still annoying.

Written by Guy

May 3rd, 2010 at 9:18 pm

Posted in Uncategorized

Tagged with ,

URL-Safe Timestamps using Base64

without comments

Passing around timestamps in URLs is a common task. We usually want our URLs to be as shortest as possible. I’ve found using Base64 to result in the shortest URL-safe representation, just 6 chars. This compares with the 12 chars of the naive way, and 8 chars when using hex representation.

The following Python functions allow you to build and read these 6 chars URL-safe timestamps:
Read the rest of this entry »

Written by Guy

April 30th, 2010 at 8:08 pm

Posted in Tips

Tagged with , ,