Archive

Archive for August, 2011

Remove pppoe settings

August 31, 2011 1 comment

Problem

In my apartment we had pppoe connection that I could configure with “sudo pppoeconf“. However, when I moved to a new place where a direct connection was provided without pppoe, my network settings didn’t work. My laptop still wanted to connect through pppoe… I tried to execute pppoeconf again, but it said “no pppoe is available”. Great!

Solution

Remove pppoe settings manually. First, edit /etc/network/interfaces and comment out the pppoe part:

auto lo
iface lo inet loopback

# auto dsl-provider
# iface dsl-provider inet ppp
# pre-up /sbin/ifconfig eth0 up # line maintained by pppoeconf
# provider dsl-provider

auto eth0
iface eth0 inet manual

Then change the last line from manual to dhcp:

iface eth0 inet dhcp

Remove the file /etc/ppp/peers/dsl-provider. Finally, restart networking: “sudo /etc/init.d/networking restart“.

Credits
This tip was taken over from here.

Browse all pages of a subreddit

August 27, 2011 Leave a comment

Problem

When you visit a subreddit on reddit.com, for instance http://www.reddit.com/r/python, at the bottom of the page you will find just a “next” link to the next page. Needless to say, browsing older entries like that is a PITA…

Solution
I made a simple script that generates a static HTML page with links to all the older pages: [1] [2] [3]…

Download
You can find the script reddit_get_all_pages.py in my Bash-Utils collection, in the reddit/ folder.

Usage
Customize the constant REDDIT in the header of the script and execute it:

./reddit_get_all_pages.py

Limitation
This script made me figure out that reddit lists only the last 1000 posts! Older posts are hidden. If you have a direct link to them, fine, otherwise they are gone :( So this script will only list 40 pages. This is a limitation of reddit.

More info:

Categories: python Tags: ,

Norton Commando

August 13, 2011 2 comments

If you used DOS, you must have had Norton Commander on your machine, which was the first orthodox file manager. The first version was released in 1986.

Today I learned that there exists Norton Commando too, which was a British made motorcycle with a twin cylinder engine, produced by the Norton Motorcycle company. During the ten years it was in production it was popular all over the world. In the United Kingdom it won the MCN “Machine of the Year” competition for five successive years from 1968-1972. Some regard it as the British Motorcycle Industry’s swan song, selling well from its introduction in 1967 through the end of the British bike industry as a commercial concern in the mid 1970s. (from wikipedia)

It’s interesting that later they made a motorcycle called Norton Commander. It was in production bettween 1988 and 1992; 253 units were produced in total. (from wikipedia)

Marakana.com — open source training

August 13, 2011 Leave a comment

Marakana‘s raison d’être is to help people get better at what they do professionally. We accomplish this by organizing software training courses (both public and private) as well as publishing learning resources, sharing knowledge from industry leaders, providing a place to share useful tidbits and supporting the community. Our focus is open source software.”

Open Source Training – Marakana

Browse your favorite subreddits painlessly

August 11, 2011 Leave a comment

Problem

You visit your favorite subreddit and you notice that it’s full of new posts. If you want to check them all, you need to click on each post. How to open all these posts in new tabs?

Solution

I made a little Python script for solving this problem (available here, in the folder “reddit”). Just specify a subreddit and what to extract (comment links [-c switch] or direct URLs [-u switch]). The script will list the available links. With another script of mine you can open these links in Firefox.

Basic usage

./reddit_get_posts.py -c /r/earthporn

Get links to comments of subreddit “earthporn”.

./reddit_get_posts.py -u /r/earthporn

Get links to direct URLs of subreddit “earthporn”.

./reddit_get_posts.py -u http://www.reddit.com/r/earthporn

You can specify the complete URL of the subreddit.

./reddit_get_posts.py -u http://www.reddit.com/r/EarthPorn/?count=25&after=t3_jffyd

You can even browse pages on reddit.com.

./reddit_get_posts.py -u

Extract links of your favourite subreddit (specify it with the constant DEFAULT_REDDIT).

Advanced usage

This script can be used together with another script of mine called open_in_tabs.py, which
is part of this Bash-Utils project too. open_in_tabs.py can open the extracted links in
your Firefox instance. Example:

./reddit_get_posts.py -u /r/earthporn | open_in_tabs -s

This will open the links simultaneously (-s switch) in Firefox.

Categories: python Tags: , ,

Making gnome-terminal usable

August 11, 2011 Leave a comment

On one of my laptops I had problems with the terminal emulators “konsole” and “terminator”. I had tried “gnome-terminal” a long time ago but I didn’t like it. Now I gave it another try and I could make it usable :)

By default, gnome-terminal starts in a little window of dimension 80×25. If you want it maximized, start like this: “gnome-terminal --maximize“.

I made a custom profile but whenever I restarted gnome-terminal, it loaded the default profile. So I removed the custom profile and modified directly the “Default” one under Edit -> Profile Preferences.

General tab
Untick the “Use the system fixed width font” if you want to use larger fonts. Monospace 12 is fine for me.

I don’t like blinking cursors and unfortunately you cannot change it here. To disable blinking, you need a little hacking. Execute the following command in a terminal:

gconftool-2 --set "/apps/gnome-terminal/profiles/Default/cursor_blink" --type boolean "False"

This tip is from here.

Colours tab
I’ve always hated that ugly purple background of gnome-terminal. You can get rid of it by unticking “Use colors from system theme”. I prefer the “Gray on black” built-in scheme. Under “Palettes”, I chose the “Linux console” scheme.

Edit -> Keyboard shortcuts…
Here untick “Enable the menu shortcut key (F10 by default)” and then you won’t have any problems with Midnight Commander. For opening new tabs, I prefer the “CTRL + T” shortcut.

Pretty print a JSON file

August 10, 2011 Leave a comment

This post is based on the following SO threads: one; two.

Problem

You have an unreadable JSON file from which you want to extract some data… How to prettify it, i.e. how to make it human readable?

Solution

There are web-based and command-line solutions. As an extra, we show you how to do it in Vim too.

Web-based prettifiers

Command-line beautifiers

Vim :)

This tip is based on this post: Editing json files in vim.

In my .vimrc file I had to add the following lines:

" pretty-print JSON files
autocmd BufRead,BufNewFile *.json set filetype=json
" json.vim is here: http://www.vim.org/scripts/script.php?script_id=1945
autocmd Syntax json sou ~/.vim/syntax/json.vim
" json_reformat is part of yajl: http://lloyd.github.com/yajl/
autocmd FileType json set equalprg=json_reformat

When opening a .json file, it will be colored using the json.vim syntax file. Selecting a text and pressing the “=” button will indent the marked text using json_reformat.

Firefox add-on

There are several JSON visualizer add-ons for Firefox, e.g. JSONView.

Download a webpage and print it to the standard output

August 10, 2011 Leave a comment

Problem
You want to download a webpage and print its content to the standard output. For instance you want to push it through a pipe for further processing.

Solution
The easiest way is to use “curl” since by default it prints the downloaded content to the stdout:

curl http://www.python.org | less

You might want to add the switch “-s” to make curl silent, i.e. hide the progress bar.

With “wget” it’s a bit more complicated:

wget -qO- http://www.python.org | less

If you want to add syntax highlighting to less, see this post.

References
Redirecting wget to STDOUT – now with Syntax Highlighting

Add syntax highlighting to “less”

August 10, 2011 Leave a comment

This entry is based on this post: Redirecting wget to STDOUT – now with Syntax Highlighting.

Less is a program similar to more, but it allows backward movement in the file as well as forward movement. Example:

cat big_text_file.txt | less

If you have vim installed, it comes with a script called less.sh that acts as a replacement of less providing syntax highlighting. Here is how to use it:

$ locate less.sh
/usr/share/vim/vim73/macros/less.sh
$ sudo ln -s /usr/share/vim/vim73/macros/less.sh /usr/bin/vless
$ curl http://www.python.org | vless
Categories: bash, vim Tags: , ,

Connect to sqlite3 databases and make queries

August 10, 2011 Leave a comment

Problem
You have a binary sqlite3 database file and you want to make some queries on it: find out what tables it has, look at the content of the tables, etc.

Solution
There is a command called “sqlite3” which is a client for sqlite3 databases. Let’s say our database is stored in a file called “database.sqlite“. (Here “.sqlite” is the file extension.)

# open database.sqlite with the client:
sqlite3 database.sqlite
# let's get the list of tables in this database:
.tables
# Say it has a table called "images". Let's see its content:
select * from images;

To learn more about the commands, just type “.help” in the client. You can dump a database in SQL text format, you can get the schema of a table, etc.

Tip
Although .sqlite database files are binary files, you can open them with a text editor too. At the top you can see the schemas of the tables in text format. Just be careful not to modify it.

Create a database from a schema (update 20111120)

sqlite3 database.sqlite < schema.sql
Follow

Get every new post delivered to your Inbox.

Join 72 other followers