Archive

Archive for February, 2011

Backup your Gmail messages

February 28, 2011 Leave a comment

You must have heard about the Gmail incident that occurred today. 150,000 users found their e-mail accounts reset.

Remember the motto: “Shit happens.” Gmail is not an exception, so make regular backups of your mails.

Short version

Install Thunderbird, link it with your Gmail account with IMAP, and let Thunderbird synchronize your mails regularly.

Longer version

  • install Mozilla Thunderbird
  • Thunderbird 3.x has built-in support for Gmail, so it’s very easy to set up an account that links Thunderbird with your Gmail account. Create an IMAP account, not a POP3. You can also refer to this post for more info.
  • Don’t be greedy, don’t try to download all your mails in one session. Give it some days, otherwise you risk that Google shuts your account down because of the high load. Download about max. 1 GB a day.

More security

If you make a local backup of your mails, you should protect it. If someone gets to your machine, (s)he can read your mails, right? I suggest storing this backup on a TrueCrypt volume [more info here]. On my laptop, I have an encrypted partition of 20 GB, and I keep my backups there.

Another advantage

If you download your mails with Thunderbird, it has another advantage. As pointed out in this post, with Thunderbird you can sort your messages in descending order by size, thus you can remove messages with large attachments easily. If your Gmail account is 90% full, consider this method.

Categories: google Tags: , , , ,

Conceptual drawings for Star Wars

February 26, 2011 Leave a comment

Here is a nice video with the conceptual drawings of Ralph McQuarrie. “Ralph McQuarrie (born June 13, 1929) is a conceptual designer and illustrator who designed Star Wars (all of the original trilogy), the original Battlestar Galactica (TV), E.T. the Extra-Terrestrial and Cocoon, for which he won an Academy Award.” (from wikipedia)

 

Home page of the artist: http://www.ralphmcquarrie.com.

I found this video in this post (in Hungarian).

Categories: movie Tags:

mp3 tag editor

February 26, 2011 Leave a comment

EasyTAG is a utility for viewing and editing tags for MP3, MP2, MP4/AAC, FLAC, Ogg Vorbis, MusePack, Monkey’s Audio and WavPack files. Its simple and nice GTK+ interface makes tagging easier under GNU/Linux or Windows.” (source)

Installation:

sudo apt-get install easytag

With EasyTAG you can process your mp3 files in batch mode. For instance, you can set the album name for several files with just one click.

Tip: if you want to edit the MP3s in the current directory, launch the application with “easytag .“.

Categories: ubuntu, windows Tags: , , ,

Hide the sidebar on wordpress.com

February 25, 2011 2 comments

Problem

You want to hide the sidebar(s) on your wordpress.com blog.

Solution

Refer to the post Widgets on static pages or single posts by Panos, everything is detailed there.

Lessons learned for me: My current theme (iNove) is a good choice as it supports the possibility to deactivate the sidebar (under Appearance -> Theme Options; this option applies to the blog in general – all dynamic and static pages). Extra for me: the pages without the sidebar become large, I prefer that. There are some themes listed under the link above that have no sidebars but the text is very narrow.

I also posted this question to the forum.

Categories: wordpress Tags: , , ,

Copy and paste the output of a program

February 24, 2011 Leave a comment

It is a common task to copy the output of a program/script and paste it somewhere else. If the output is short (just some lines), we can select the text easily with the mouse. What about longer outputs?

Old method

Until now I’ve been using the following method:

  • ./produce-long-output >a (redirect the output to a temporary file)
  • gedit a (open the temp file with a text editor)
  • CTRL+A (select the whole text)
  • copy selected text to the clipboard
  • paste text to somewhere else
  • rm a (remove the temp file)

New method

Recently, I discovered some tools (xclip and xsel) that can copy a text to the clipboard. With them, it is unnecessary to use a temporary file.

./produce-long-output | xsel

It’ll copy the text to the “primary” clipboard that you can paste with the middle mouse button. If you prefer pasting with Shift + Insert, then copy texts to the 3rd clipboard (it is simply called “clipboard”).

./produce-long-output | xsel -b

Life has become a little bit less complicated :)

Categories: bash Tags: , , , ,

Copy string to X clipboard in shell

February 24, 2011 6 comments

This entry is based on the post Copy Shell Prompt Output To Linux / UNIX X Clipboard Directly.

Problem

Under Linux, you want to copy a given text to the X clipboard. How to do that?

Three different clipboards

First of all, we should know that under X there are three clipboards :)

  • “primary”: The primary one’s paste operation is usually accessed with the middle mouse button.
  • “secondary”: This one didn’t really work for me…
  • “clipboard”: Its paste operation is accessed with Shift + Insert (or right mouse click and Paste in popup menus).

The xclip command

Reads from standard in, or from one or more files, and makes the data available as an X selection for pasting into X applications. Prints current X selection to standard out.

Installation:

sudo apt-get install xclip

Copy a string to the clipboard. By default, xclip copies to the “primary” clipboard.

echo "this is a test" | xclip
echo "this is a test" | xclip -selection primary
echo "this is a test" | xclip -selection p

The three variations are equivalent.

Copy a string to the “clipboard” (3rd clipboard).

echo "another test" | xclip -selection clipboard
echo "another test" | xclip -selection c

The two variations are equivalent.

Copy the contents of a file to the clipboard.

cat file.txt | xclip

Print the contents of the clipboard to the standard output.

xclip -o

Of course, you can use redirection.

xclip -o > out.txt

The xsel command

Retrieve and set the X selection.

xsel is similar to xclip, but it offers some additional features like append, clear, etc.

Installation:

sudo apt-get install xsel

Copy a string to the primary clipboard (default).

echo "1" | xsel
echo "1" | xsel -p

The two variations are equivalent.

Copy a string to “clipboard” (3rd clipboard).

echo "1" | xsel -b

Copy the contents of a file to the clipboard.

cat file.txt | xsel

Print the contents of the clipboard to the standard output.

xsel -o

Homework

Find a solution to copy a string to the “primary” and “clipboard” clipboards, i.e. on both. Hint: “echo homework | xsel -p -b” and “echo homework | xclip -selection p -selection c” won’t work. Post your solution in the comments.

Categories: bash Tags: , , ,

Archives List Generator for wordpress.com

February 23, 2011 2 comments

Problem

I wanted to have an “Archives” page that lists the titles of my posts. This way, I could find the post I’m looking for much easier. Unfortunately I didn’t find this functionality on wordpress.com. I was searching for a solution and I found WordPress ListMaker v2. However, the author provides an EXE only and his program requires your username. This is something I would never give out… On the other hand, I use Linux, so I prefer open source solutions.

So I’ve decided to write a Python script that produces an HTML output, similar to WordPress ListMaker v2.

Demo

You can see my Archives list here. It was generated with my script.

Download

Visit https://github.com/jabbalaci/Archives-List-Generator. Source code is here.

Solution

In a previous post I showed how to get the list of your blog posts. This script is an extended version, it simply produces a formatted HTML output.

Usage:

Modify the beginning of the script: precise the address of your blog, your username, password, etc. Then just simply execute the script. You can redirect the output to a file, then paste the contents of the file to your wordpress.com blog.

[ @reddit ]

Categories: project, python, wordpress Tags: ,

Get the list of your posts on wordpress.com with a Python script using the MetaWeblog API

February 22, 2011 4 comments

Problem

You have a blog on wordpress.com and you want to get the list of your posts. For this task, you want to use a Python script.

Solution

#!/usr/bin/env python

import xmlrpclib
import sys
import pprint

pp = pprint.PrettyPrinter(indent=4)

# you can use the HTTP or the HTTPS protocol below:
server = xmlrpclib.ServerProxy('https://NAME_OF_YOUR_BLOG.wordpress.com/xmlrpc.php')
result = server.metaWeblog.getRecentPosts('NAME_OF_YOUR_BLOG', 'USER_NAME', 'USER_PASSWORD', sys.maxint)
pp.pprint(result)
print
print 'Number of posts: %d.' % len(result)

The script will download the list of all your posts. If you want, for instance, the latest 20 posts, write 20 instead of sys.maxint.

Links

What next?

I would like to have an “Archives” page that would list the titles of my posts. This way, I could find the post I’m looking for much easier. Unfortunately I didn’t find this functionality on wordpress.com. I was searching for a solution and I found WordPress ListMaker v2. However, the author provides an EXE only and his program requires your username. This is something I would never give out… On the other hand, I use Linux, so I prefer open source solutions.

So the next project is to complete the Python script above to produce an HTML output, similar to WordPress ListMaker v2. I’ll do it when I have some free time.

Update (20110223): The script is ready, see this post.

cron and crontab

February 22, 2011 Leave a comment

If you want a detailed presentation of the topic, refer to this post. Here I write just a short summary.

Cron is the daemon that executes scheduled commands. Crontab is the program to maintain crontab files for individual users. If we want to schedule a command, we need to use crontab.

List your sceduled tasks:

crontab -l

Edit the list of your sceduled tasks:

crontab -e

Example #1:

* * * * * date >>/tmp/date.log

It will append the date to /tmp/date.log every minute. It can be used for testing to see if you have the rights to schedule cron jobs.

Structure:

{minute} {hour} {day of month} {month} {day of week} {command}

Example #2:

0 22 * * * date >>/tmp/date.log

Meaning: every day at 22h, execute the given task.

Example #3:

0 */2 * * * date >>/tmp/date.log

Execute the task every 2 hours. Notice that the minute must be specified (can be different from 0)! If you write “* */2 * * *“, it will still be executed every minute.

Calling a graphical application from crontab
If you want to launch a GUI application, you’ll get an error message: “Error: Can’t open display:”. To solve this problem, add an extra line to your crontab:

DISPLAY=:0
0 */2 * * * /path/to/gui_app.py >>/tmp/log.txt

Related

Categories: bash Tags: ,

Python tutorials of Full Circle Magazine in a single PDF

February 21, 2011 1 comment

Please read first the update information at the end of the post.

Description

Full Circle Magazine (FCM) started a Python tutorial series in issue #27. At the time of writing, the current issue is #45, and the tutorial is still there :)

Problem: it would be nice to extract these tutorials from the issues and put them together in a single PDF. Thus, we would have all the tutorials together in one document.

Download

For the lazy pigs, here is the PDF (6 MB). Get it while it’s hot :)

How to produce the single PDF

For those who are interested, here I explain how to produce the single PDF above.

First, download the issues of FCM. I suppose that the required files are named issue27_en.pdf, issue28_en.pdf, …, issue45_en.pdf. Put them in a directory called full-circle.

Here is a CSV file that contains data about which pages to extract from the issues:

# issue; start page; end page
27;7;10
28;7;11
29;7;11
30;7;9
31;8;11
32;8;12
33;8;12
34;8;15
35;10;13
36;7;11
37;7;11
38;7;11
39;7;11
40;8;14
41;8;12
42;8;11
43;7;9
44;7;9
45;7;8

Put this file (download link) to the same directory where the PDF files are. Here, create a subdirectory called pieces. The extracted PDFs will be stored there.

We will use the following Python script to produce the commands that will do the extraction:

#!/usr/bin/env python

# extract.py

f1 = open('python.csv', 'r')

for line in f1:
    if line.startswith('#'):
        continue
    # else
    line = line.rstrip('\n')
    (issue, start_page, end_page) = line.split(';')
    command = "pdftk issue%s_en.pdf cat %s-%s output pieces/%s-python.pdf" % (issue, start_page, end_page, issue)
    print command

f1.close()

By executing the script (download link), you will get the following output:

pdftk issue27_en.pdf cat 7-10 output pieces/27-python.pdf
pdftk issue28_en.pdf cat 7-11 output pieces/28-python.pdf
pdftk issue29_en.pdf cat 7-11 output pieces/29-python.pdf
pdftk issue30_en.pdf cat 7-9 output pieces/30-python.pdf
pdftk issue31_en.pdf cat 8-11 output pieces/31-python.pdf
pdftk issue32_en.pdf cat 8-12 output pieces/32-python.pdf
pdftk issue33_en.pdf cat 8-12 output pieces/33-python.pdf
pdftk issue34_en.pdf cat 8-15 output pieces/34-python.pdf
pdftk issue35_en.pdf cat 10-13 output pieces/35-python.pdf
pdftk issue36_en.pdf cat 7-11 output pieces/36-python.pdf
pdftk issue37_en.pdf cat 7-11 output pieces/37-python.pdf
pdftk issue38_en.pdf cat 7-11 output pieces/38-python.pdf
pdftk issue39_en.pdf cat 7-11 output pieces/39-python.pdf
pdftk issue40_en.pdf cat 8-14 output pieces/40-python.pdf
pdftk issue41_en.pdf cat 8-12 output pieces/41-python.pdf
pdftk issue42_en.pdf cat 8-11 output pieces/42-python.pdf
pdftk issue43_en.pdf cat 7-9 output pieces/43-python.pdf
pdftk issue44_en.pdf cat 7-9 output pieces/44-python.pdf
pdftk issue45_en.pdf cat 7-8 output pieces/45-python.pdf

As can be seen, the extraction will be done with pdftk (more info here). Now, these commands are simply printed to the standard output. Here is how to execute them too:

./extract.py | sh

That is, pass the commands to the shell “sh”, which will execute them line by line.

Okay, now we have the pieces in the directory “pieces”. Enter the directory “pieces” and join the PDFs:

pdftk *.pdf cat output all.pdf

Known issue

Well, to tell the truth, this method will produce a huge single PDF. The extracted pieces are also very big (5 to 10 MB), and the final PDF is about 130 MB! So actually I used Adobe Acrobat 8 Professional to merge the pieces with the conversion setting “Smaller File Size”. Acrobat Pro optimized the files and produced a file of size 6 MB. If you know how to have a similar result with open source tools, let me know.

Update (20110305):

It seems FCM comes out with a similar idea: http://fullcirclemagazine.org/python-special-edition-1/. They collected the first 8 parts of the already published Python tutorials in a special edition.

Update (20110329):

I pushed this project to GitHub, see https://github.com/jabbalaci/Full-Circle-Magazine-Series. I added some changes but I won’t rewrite this post each time. For the latest version, please refer to GitHub.

[ @reddit ]

Categories: python Tags: , ,
Follow

Get every new post delivered to your Inbox.

Join 61 other followers