Archive

Archive for January, 2014

free programming books

January 20, 2014 Leave a comment

Remove global menu bar from Firefox (22.0+)

January 17, 2014 Leave a comment

Problem
You managed to disable the stupid global menu in your Ubuntu but Firefox still has this shit. How to get rid of it?

Solution
Type in about:config and change the value of the line ui.use_unity_menubar to false.

Tip from here.

Categories: firefox, ubuntu Tags: ,

Installing Vagrant on Windows

January 15, 2014 Leave a comment

Problem
You have a Windows machine and you want to use Linux (e.g. Ubuntu) in it. That is, you want to install an Ubuntu VM (virtual machine) inside Windows. You want to use the command line only, thus you don’t need any graphical interface. Maybe you have a weak laptop where a graphical VM wouldn’t even run normally. In addition, you want to get it done quickly, you have no time to download an Ubuntu image and go through the installation process. What to do?

Solution
Use Vagrant. Vagrant is a tool for building complete development environments. We will use Vagrant with VirtualBox, so we need to install both.

Install VirtualBox
Visit https://www.virtualbox.org/ and select Downloads on the left side. Download and install the latest version for Windows hosts. You can also install the Extension Pack. Make sure to install the version that matches with the previously installed VirtualBox version. We won’t work with VirtualBox directly, but Vagrant is built on top of it, so Vagrant will need it.

Install Vagrant
Visit http://www.vagrantup.com/downloads and install the Windows version. For the curious, Vagrant is written in Ruby. It is very likely that you will have to restart your computer after the installation. After the restart, you can use the command “vagrant” in the shell, it is added to the PATH by the installer.

Basic usage of Vagrant
As indicated in the official guide, using vagrant is very easy.

I suggest that you should create a dedicated directory for your first Ubuntu VM, C:\vagrant for instance. Enter this directory, open a terminal (with the command “cmd“) and execute the following commands:

c:\vagrant> vagrant init precise32 http://files.vagrantup.com/precise32.box
c:\vagrant> vagrant up

The first command downloads a basic Ubuntu 12.04 LTS image. The second command starts the VM.

Now it’s time to log in to the running VM:

c:\vagrant> vagrant ssh    # there is a chance that it won't work...

Well, if it doesn’t work for you under Windows, here is alternative solution: use Putty. Details: hostname: 127.0.0.1, port: 2222, username: vagrant, password: vagrant.

Some other useful commands:

c:\vagrant> vagrant status  # Is the VM running?
c:\vagrant> vagrant halt    # stop the VM; counterpart of "vagrant up"

Use Bash as your shell
The default Windows shell “cmd” is quite lame. If you want to use a better shell, install the Cygwin environment, which is a Unix compatibility layer for Windows. It’s enough to install the default packages, but don’t forget to add the “openssh” package too. In my case, I installed the 64-bit version and added the “c:\cygwin64\bin” directory to my PATH. After this you can launch the command “bash” and execute these commands:

$ cd /cygdrive/c/vagrant
$ vagrant status    # Is it running?
$ vagrant up        # if it was not running
$ vagrant ssh       # thanks to the openssh package, it works now
...                 # work with the VM
$ vagrant halt      # stop it if you don't need it anymore


Using Vagrant under Linux

vagrant

bittorrent client from the command line

January 14, 2014 Leave a comment

Install:

sudo apt-get install transmission-cli

Usage:

$ transmission-cli  -w <download_dir>  <file|url|magnet>
Categories: bash Tags: ,

docker series

January 14, 2014 Leave a comment
Categories: docker

docker-redis

January 14, 2014 Leave a comment

Problem
You want to build a docker image with a Redis server in it. When you launch it, you want it to function as a redis server.

Dockerfile, build, run

Dockerfile:

# Redis
#
# VERSION       0.1

# use the ubuntu base image provided by dotCloud
FROM ubuntu

#MAINTAINER Jabba Laci, jabba.laci@gmail.com

# make sure the package repository is up to date
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update

# install redis
RUN apt-get install -y redis-server

# Launch redis-server when launching the container
ENTRYPOINT ["redis-server"]

# expose redis-server port
EXPOSE 6379

build:

$ docker build -t redis .

Here I suppose that the file Dockerfile is in the current dorectory.

run:

$ docker run -d -p 6379 redis

Run it in the background (-d) and expose its port 6379 to the host (-p).

Try it

docker ps will tell you the necessary port numbers:

$ docker ps
...PORTS...
...0.0.0.0:49163->6379/tcp...

Meaning: the port 49163 on the host is redirected to the container’s port 6379. That is, if we want to connect to the redis-server in the container, we can do it through the host’s port 49163.

Of course, in your case it will be something else instead of port number 49163…

Test code:

>>> import redis
>>> r = redis.Redis('localhost', 49163)
>>> r.info()
{'pubsub_channels': 0, 'aof_enabled': 0, 'bgrewriteaof_in_progress': 0, 'connected_slaves': 0, 'uptime_in_days': 0, 'multiplexing_api': 'epoll', 'lru_clock': 558312, 'last_save_time': 1389703273, 'redis_version': '2.2.12', 'redis_git_sha1': 0, 'loading': 0, 'connected_clients': 1, 'keyspace_misses': 0, 'used_memory': 798784, 'vm_enabled': 0, 'used_cpu_user_children': 0.0, 'role': 'master', 'total_commands_processed': 0, 'used_memory_rss': 1662976, 'total_connections_received': 1, 'pubsub_patterns': 0, 'used_cpu_sys': 0.03, 'used_memory_human': '780.06K', 'used_cpu_sys_children': 0.0, 'blocked_clients': 0, 'used_cpu_user': 0.02, 'use_tcmalloc': 0, 'client_biggest_input_buf': 0, 'arch_bits': 64, 'redis_git_dirty': 0, 'expired_keys': 0, 'hash_max_zipmap_entries': 512, 'evicted_keys': 0, 'bgsave_in_progress': 0, 'client_longest_output_list': 0, 'hash_max_zipmap_value': 64, 'process_id': 1, 'uptime_in_seconds': 167, 'changes_since_last_save': 0, 'mem_fragmentation_ratio': 2.08, 'keyspace_hits': 0}
>>> # r.info() worked, so it's OK
... 
>>> r.set('Jabba', 'the Hutt')
True
>>> r.get('Jabba')
'the Hutt'
>>>
Categories: docker, python Tags: ,

What is my user agent?

January 13, 2014 1 comment

Exercise
Figure out the user agent of your browser. But! You are not allowed to visit http://whatsmyuseragent.com/ or any similar service :)

Solution
It’s time to discover netcat, the “Swiss-army knife for TCP/IP”. In a terminal launch nc and start listening on a port:

$ nc -l 8080

Visit http://localhost:8080 . Switch back to the terminal and you will see something similar:

GET / HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Categories: ubuntu Tags: ,