Wednesday, September 16, 2015

ipython && tmux - saving history to a file


I had an ipython console open inside a tmux split window and I needed to save the history to a file.
Since I can't copy & paste the data from the screen (I was in the middle of a session, so the next time I would configure it correctly using this).

So I found a quicker way, Roberto Z wrote in his comment that in order to save the session's history you can use readline package:

import readline

This works like a charm in Ubuntu.

- Tal Kain

Wednesday, September 9, 2015

Linux: iptables: Removing a collection of iptables rules at once

Here is a small trick for removing several iptables rules at once,

Let's assume we would like to add some rules:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
I can use the comment match and add a comment to this line:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE -m comment --comment "SOME_COMMENT"

Now, cleaning all the relevant rules in a simple command would be:

# iptables-save | grep -v SOME_COMMENT | iptables-restore

 Probably not the best way to do it, but it's simple and fast.

Have fun,
-Tal Kain

Wednesday, September 2, 2015

Installing NVIDIA CUDA on an Amazon Web Services (AWS) machine (Ubuntu 14.04)

Disclaimer: I wrote this post several months ago and did not publish it for unknown reason, I assume that the information below is still relevant and correct.

While trying to install the machine, I started my research by reading Traun Leyden's great blog post: (you should too)

Amazon offers two types of machines that includes GPUs (
High-performance NVIDIA GPUs, each with 1,536 CUDA cores and 4GB of video memory
While writing this post, I used the g2.2xlarge machine, but you can also use the 8xlarge.

This will be quick and simple:

1. Make sure you are fully up-to-date
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
 When prompted, choose the "install maintainer package...."

2. Reboot the machine (so it will load the new kernel)
3. Install the kernel's header files
sudo apt-get install -y linux-image-extra-virtual linux-headers-`uname -r`
3. Configure the xorg-edgers PPA

sudo add-apt-repository ppa:xorg-edgers/ppa
sudo apt-get update
4. Install the NVIDIA's CUDA repository package
wget -O ${OUTPUT_PATH}
dpkg -i ${OUTPUT_PATH}

 5. Update the package manager and install CUDA
sudo apt-get update
sudo apt-get install cuda
6. Make sure everything is installed as expected:
sudo nvidia-smi -a

7. You can also compile and run a sample to make sure everything is ready:
cd /usr/local/cuda/samples/1_Utilities/deviceQuery

That's all!

- Tal Kain