Showing posts with label English. Show all posts
Showing posts with label English. Show all posts

Jul 12, 2013

CDP device discovery in python

Today, I wrote a small python script to discover Ubiquiti Nanostation devices on the network using pacpy and dpkt. Since it is listening CDP packets, I guess it can also discover other kinds of devices, though not tested.

Jun 20, 2013

Simple Data Compression Algorithms in Common Lisp

Common Lisp implementation of some data compression algorithms — Run-Length, Huffman, and Shannon–Fano Encodings — that I have written during my graduate course "Data Compression".

Internet connection sharing using iptables

Scenario ― I have several virtualbox GUEST machines, using an internal network on my PC. Now, I wanted to share host machine's internet connection to guest machines. I searched on the web how to do it using iptables. Most of the solutions seem too complex. Here is a working simple solution (found on centos documentation)

On Host Machine — type these commands in Terminal.

thura @ ~ $ sudo iptables -A FORWARD -i vboxnet0 -j ACCEPT
thura @ ~ $ sudo iptables -A FORWARD -o eth1 -j ACCEPT
thura @ ~ $ sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

That's it. Now you can access the external network of host machine from guest machines. To access Internet, you may need to edit /etc/resolve.conf in your guest machine.
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8

Jun 19, 2013

if_nametoindex, if_indextoname functions for python using ctypes


I needed to use if_nametoindex, if_indextoname functions for one of my packet capturing programs. So, here is my python wrapper for those functions using ctypes.


PS: You will need this only for python2.x. Those functions are available in socket module starting since python 3.3.

Jan 13, 2012

tic-tac-toe AI with two-ply minmax in scheme

Today, while I am reorganizing my old programming source code files, I stumbled upon this old gem —  an implementation of tic-tac-toe AI using two-ply min-max in scheme — which is my project for AI course in university.

Although it was only a half and a year ago, I have already forgot how it works. Besides at that time, I wrote it using plt-scheme, which has become racket now. So, I decided to find out whether the program still works under racket and went through this unbearable pang of downloading racket — a familiar emotion for Internet users inside Myanmar. After waiting for a few hours, I was ready to animate my old friend.



Yeah, it still works, and as far as I tested, the AI is unbeatable. Since this kind of projects are common in university AI courses, I decided to post it online to help some pour souls trying to meet his assignment deadline — that I was once.

Please, note that the evaluation function is too complex and poorly written that I even myself had a hard time understanding. So, you might want to rework that one.

To try out this program, just install racket & run.
sudo apt-get install racket
racket ttc.scm

Dec 19, 2011

Reading comics books & mangas in Ubuntu

Normally, comic books & manags are shared on the net in archive formats, like zip or rar, which contain (jpeg, png) images. Reading those images with an image viewer is the most irksome reading experience you can ever have. So, normally you may want to convert those images into a common document format, like pdf.

Since evince is the default and most widely used document reader in Ubuntu, there are two ways to convert those piles of images into evince-readable format.

The first one is to use our favourite ImageMagick's convert command. Go to the directory which contains those images in terminal, and run this command, which will produce a comic-book.pdf with jpg files in current directory.
convert *.jpg comic-book.pdf

If you have downloaded lots of comics books and you might find it tedious to go into each book's folder and run the above command. Rest assured, you don't need to. You can use for loop in bash to automate this.

In the above example, we have 3 series of Rurouni Kenshin mangas in current folder. After runing the command, we have 3 pdf files with corresponding names.

An alternative way is to use cbz format, which is also supported by evince reader.

7z a comic-book.cbz *.{jpg,png}
This command will produce a comic-book.cbz with jpg or png images in current directory.

for file in *;do 7z a "$file".cbz "$file"/*.png ;done
This command will read png images in each directory of current folder, and produce cbz files with corresponding names.

Dec 7, 2011

Repair GRUB without using LiveCD

  1. Search root disk.
    grub> search -f /vmlinuz -s root

  2. Set root disk.
    grub> root ($root)

  3. Use these commands to find out root disk's information.
    grub> ls -l ($root)

  4. Set linux kernel. There are three ways to do it.

    1. Change the red number with your root disk number. If your root disk is (hd0, msdos1), then use /dev/sda1.
      grub> linux /vmlinuz root=/dev/sda1
    2. Change red text with your disk label, which can get by using ls -l ($root).
      grub> linux /vmlinuz root=LABEL=LABEL
    3. Change red text with your disk uuid, which can also get by using ls ($root).
      grub> linux /vmlinuz root=UUID=UUID
  5. Set ramdisk.
    grub> initrd /initrd.img

  6. Now, you can boot your system.
    grub> boot

  7. When you are logged in, type this command from terminal to fix your grub menu.
    $ sudo update-grub

Setting up Huawei c8600 mobile phone as modem on Ubuntu

Although I have tested only on ubuntu 10.10 with Huawei C8600, it might also work for Huawei C8500 and other Ubuntu versions.

1) Connect your Huawei c8600 mobile phone to your computer.

2) Open Terminal. Make sure your device is detected. Type "lsusb".



3) Load Modem with VendorID (12d1 for Huawei) and ProductID you get above. Type "sudo modprobe usbserial vendor=0x12d1 product=0xYourProductIDHere".




4) It takes a while for the network manager to detect your newly acquired modem. Sit back and relax. After several seconds, you should see CDMA Mobile Broadband Connection in your connections. Select and click on it.




6) Configure the wizard dialogs according to your provider settings. For MPT EVDO CMDA Broadband Internet, follow these steps.





7) That's it. ;)

Feb 7, 2011

How to install & use Masterpiece Uni Sans on Ubuntu

Why?
  • Being linux-native (using pango to render), it is slightly faster to render than other fonts.
  • All other unicode fonts except padauk have some (minor) rendering problems on linux. MasterPiece Uni Sans can render properly and look better than padauk.
Steps

1) Download and install the font ttf-masterpiece_0.6-0ubuntu1_all.deb.

2) Download and install the patched pango module. This module is patched, meaning it is different from the original module from Ko Tin Myo Htet (prahita). The original module will not render other unicode fonts like myanmar3, padauk correctly, making burmese text in some sites like mitp scrambled in firefox. If you have previously installed it before, you need to reinstall this file. For other distros, apply this patch, build and install from source.

3) Create a file, ".blacklist-mymr-fonts", in your home directory and put the burmese font names you don't want to render with this module (one font per line).  For example,
echo -e "Myanmar3\nPadauk\nZawgyi-One" > .blacklist-mymr-fonts

Now, you can use MasterPiece Uni Sans in all gtk+ applications. You cannot use it in openoffice, since openoffice doesn't use pango. If certain burmese fonts are not rendering properly, don't forget to put their font names in aforesaid ".blacklist-mymr-fonts".

Feb 5, 2011

Type Burmese in GNU/Linux Using IBus

1) Install ibus and ibus-table. For most distros, they are already installed (or) available in the repositories.

2) Download, extract this file.
tar xvzf ibus-myanmar.tar.gz

3) Copy database and icon files to corresponding ibus-table directories.
sudo cp mm-*.db /usr/share/ibus-table/tables/
sudo cp *.svg /usr/share/ibus-table/icons
4) Start IBus daemon. ( System > Preferences > Input Method > Enable and use IBus. )

5) Now, add our Burmese input methods in IBus Preferences under Input Method.


6) Use Control+Space to switch on/off IBus (to type Burmese). Left Shift can be used to toggle between English and Burmese.


Issues

To type third level keys in Zawgyi Layout, type ` first, and then type corresponding key (with or without Shift key). Currently, a popup is shown typing third level keys. There is no way to disable it yet. I have already filed a bug report.