Archive

Archive for June, 2013

Online Security

June 29, 2013 Leave a comment

Read this: The Best Browser Extensions that Protect Your Privacy @lifehacker.

I installed the following extensions:

Categories: firefox, security Tags: ,

beep when ready

June 29, 2013 1 comment

Problem
Sometimes I launch a script and if it takes too much time to finish, I leave the machine alone. I do something else but I check back from time to time to see if it has finished. It would be nice if I could get an audio notification when the job is done.

Idea
Here it is:

$ ./slow_operation.sh; beep

Implementation
There is a package called “beep” that should do it but it was mute on my system, so I came up with an own solution. First, you need a short audio file. Here is mine: alert.wav. Download it and put it in the directory $HOME/bin. Make sure $HOME/bin is in your PATH.

Then add the following lines to your ~/.bashrc file:

#uncomment the next 2 lines to add $HOME/bin to your PATH
#PATH=$PATH:$HOME/bin
#export PATH

alias beep="mplayer -ao alsa $HOME/bin/alert.wav &>/dev/null"

Test
Open a new terminal and try this:

$ sleep 2; beep
Categories: bash Tags: , , ,

mplayer doesn’t quit

June 28, 2013 Leave a comment

Problem
When I play a song with mplayer (from the package mplayer2), the song is played but mplayer doesn’t quit, I don’t get the prompt back. This is annoying if I want to play sound effects from a script and tens of mplayer processes are hanging…

Solution
Add the “-ao alsa” switch as a temporary solution (tip from here):

mplayer -ao alsa audio.mp3
Categories: bash Tags: ,

Google’s URL shortener

June 25, 2013 Leave a comment

Problem
You want to shorten a long URL from the command line / from a script.

Solution
There are lots of URL shorteners. With the Google URL shortener you can do it like this:

curl https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d '{"longUrl": "https://ubuntuincident.wordpress.com"}'

Sample output:

{
    "kind": "urlshortener#url",
    "id": "http://goo.gl/Zeigx",
    "longUrl": "https://ubuntuincident.wordpress.com/"
}

Exercise
Let’s do it in Python using the requests module:

import requests
import json

url = "https://www.googleapis.com/urlshortener/v1/url"
data = {"longUrl": "https://ubuntuincident.wordpress.com"}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, data=json.dumps(data), headers=headers)
print r.text
print 'Short URL:', r.json()["id"]

Links

Name generators

June 25, 2013 Leave a comment

I had a project idea that would have needed fake names. I postponed this project but I found some useful links that I would collect here for future references:

Categories: python Tags: ,

Locate by IP

Problem
You have an IP address and you want to get more info about it.

Solution
infoSNIPER does the job. However, I didn’t find an API to it.

MaxMind offers several services. They also have a free service called GeoLite, which is a bit less accurate and the databases are updated once a month. If you want to use it from Python, here is an API (pygeoip) to the databases (that you need to download and extract and they take about 44 MB disk space).

If you don’t want to download any databases then IPInfoDB can be a nice solution. They have an API, thus you can use this service in your applications. You’ll have to register for a free API key. There is a Python library to it called pyipinfodb.

Categories: python Tags: ,

10 Productivity tips for software developers

Follow

Get every new post delivered to your Inbox.

Join 73 other followers