Archive

Archive for August, 2013

wget with no output

August 13, 2013 Leave a comment

silencerProblem
You want to call wget from a script but you want wget to stay silent, i.e. it shouldn’t produce any output.

Solution

wget -q URL
Advertisements
Categories: bash Tags: , ,

redis: getting started

August 12, 2013 Leave a comment

Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.” (source)

Also, redis commands are atomic operations.

Installation

# Check out the home page for the latest version!
$ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
$ tar xvzf redis-2.6.14.tar.gz
$ cd redis-2.6.14
$ make
$ sudo make install

Then start the redis server:

$ redis-server

The server, by default, will listen on localhost:6379.

Graphical interface
Do you like phpMyAdmin? Well, there is something similar to redis too called Redis Commander. Check out the project’s home page for installation instructions.

Redis Commander is written in node.js. For installing node.js, refer to this post: Installing Node.js and NPM on Ubuntu/Debian.

Python binding
At this point you might ask the natural question: “OK, but how can I use it from Python?”. You need the following client:

sudo pip install redis -U

Let’s test it:

>>> import redis
>>> r = redis.Redis()    # default: localhost, port 6379
>>> r.set("name", "jabba")
True
>>> r.get("name")
'jabba'

Let’s see another example with a list:

>>> import redis
>>> r = redis.Redis()
# the list is called "test"
# rpush: right push, i.e. put an element on its right side (tail)
>>> r.rpush("test", 24)
1L
>>> r.rpush("test", 67)
2L
>>> r.rpush("test", 9)
3L
# list all the elements (-1 is the index of the last element)
>>> r.lrange("test", 0, -1)
['24', '67', '9']
# number of elements 
>>> r.llen("test")
3
# delete the list if you don't need it anymore
>>> r.delete("test")
1

Save the database
It is possible to save the database to disk. When you restart the server, it can restore the database from disk.

The database will be saved to the directory where you started redis! For instance, you started redis from your HOME directory. In a Python script you called “r.save()“, which creates a snapshot of the database and dumps it to “~/dump.rdb“. When you start the server, it checks for this dump file in the current directory. If “./dump.rdb” is found, it will be loaded.

If you run redis-server in a terminal, check out its log. It will indicate if it found and loaded a database upon startup.

Links

Categories: python Tags: ,

Mongoose web server

August 11, 2013 Leave a comment

It’s very easy to start a Python web server on localhost.

If you want something more serious but still lightweight, check out the Mongoose web server.

Fetch and compile:

wget https://mongoose.googlecode.com/files/mongoose-3.8.tgz
tar xvzf mongoose-3.8.tgz
cd mongoose
make linux

The user manual is here.

Categories: Uncategorized Tags: ,

Scala tutorials

August 11, 2013 Leave a comment

Wanna learn Scala? Visit http://scalatutorials.com/.

[ found here ]

Categories: programming Tags: ,

PrimCom: manage and access your personal knowledge base easily

August 4, 2013 Leave a comment

I am proud to announce my newest project called PrimCom, which is a personal knowledge base manager, primarily made for programmers. I made a detailed description of the project here, I don’t want to repeat the whole text here.

A screenshot:

Links

Update (20130808)
PrimCom was included in Python Weekly #99. Great!

Related work

  • cheat (It was designed to help remind *nix system administrators of options for commands that they use frequently, but not frequently enough to remember.)
Categories: python Tags: ,

Log in to comment

August 2, 2013 Leave a comment

Dear Readers,

The spam filter on wordpress.com has not been very efficient recently. Too many spam messages get the “pending” status that I need to review manually. I can’t imagine why they aren’t flagged automatically as spam…

I got tired of these spam messages, thus from now on you must be logged in if you want to leave a comment. Thank you for your understanding. I hope you will still leave comments, I love receiving feedbacks.

Best wishes,

Jabba Laci

Categories: wordpress Tags: ,