Sunday, April 15, 2012

Facebook is blocked in your office? Maybe this will help you a bit ;)

I think there aren't few of you who want to access your facebook page, but the page is being blocked by the server and you can't visit it.

Maybe this will give you a hint to backdoor the security!

First of all, you should know that every website has its own ip address, which will give you a unique identifier so your system will make sure that it visits the right page, even though there are two websites with the same name.

For example, Twitter's IP address is 199.59.150.39
If you hit http://199.59.150.39 to your address bar, then boom, twitter page will show up.

But that is not only it, this IP address will then be translated again to a 'human' number which is the true unique identifier.

How? First we translate the IP address to a sequence of binary numbers.
Twitter's IP address above will be translated to:

11000111 . 00111011 . 10010110 . 00100111
(Learn how to convert a number to binary)

And then, the dots exist in between will vanish and all sequences will be joined.

11000111001110111001011000100111

Guess what, this will also be the unique identifier if you convert it back again to the decimal number,
which will give us:

3342571047

Try to check it out!
hit http://3342571047 to your address bar.

Anyway, all of these conversions can be done in python within 2 lines.

#!/usr/bin/env python
# ip_trans.py


import sys
print 'http://%i' % int(''.join([bin(int(x)+256)[3:] for x in sys.argv[1].split('.')]),2)


And run the program with an ip address as the argument:

$ python ip_trans.py 199.59.150.39
http://3342571047

ipython-0.12 installation in Cygwin

ipython with numpy+scipy+matplotlib Installation Procedures: (as of April 2012)

1. Install some packages from cygwin setup.exe:
   * liblapack
   * fortran compilers and some fortran packages (best to download all related to fortran)
   * libgfortran
   * python packages
   * libpng
   * freetype2
   * c/c++ compilers
   * libboost

2. Install libffi (required for ipython)
   * Download libffi-3.0.11
   * Extract folder
   * Configure the installation
     ./configure
   * Install
     make install

3. Install ATLAS (Automatic Tuned Linear Algebra Software) (required for numpy+scipy)
   * caution: this installation may cause stress due to the installation time, which may take all day.
   * Download atlas-3.8.4
   * Extract folder
   * Make build folder (Installation procedure is written inside INSTALL.txt)
     mkdir cygwin_build
   * Configure (there is only 32-bit version)
     ../configure -b 32
   * Install
     make
     make check
     make ptcheck
     make time
     make install

4. Install nose (testing package for scipy+numpy)
   * Download nose-1.1.2
   * Extract folder
   * Build file
     python setup.py build
   * Install
     python setup.py install


5. Install numpy (required for matplotlib and for.... python programmer.)
   * Download numpy-1.6.1
   * Extract folder
   * Build file (I faced some bugs when doing this, if you also happen to face them, I'll try my best to help)
     python setup.py build
   * Install
     python setup.py install

6. Install scipy (required for.... python programmer.)
   * Download scipy-0.10.1
   * Extract folder
   * Build file
     python setup.py build (also some bugs here)
   * Install
     python setup.py install

7. Install matplotlib (required for ipython)
   * Download matplotlib-1.1.0
   * Extract folder
   * Copy the setup.cfg.template to setup.cfg
     cp setup.cfg.template setup.cfg
   * Uncomment line 70
     tkagg = False
   * Try to build the program
     python setup.py build
   * If there is an error saying unable to remap a dll file or such, we have to run the rebase command of cygwin, using CO\MMAND PROMPT:
     cd C\cygwin\bin
     ash
     PATH=. rebaseall -v

     ...wait until it finishes

   * Try to build the program once again
     python setup.py build
   * Look at the pkg_config, if it says it's not configured right for libffi package, put this in your .bashrc:
     export PKG_CONFIG_PATH=/usr/local/lib/pkconfig (after making sure that libffi.pc is here)
   * And also make sre that you satisfied all dependencies.
   * After the build succeed, install
     python setup.py install

8. FINALLY. Install ipython.
   * Download ipython-0.12
   * Extract folder
   * Build file
     python setup.py build (also some bugs here)
   * Install
     python setup.py install

9. Now that we finished all installations, let's run some tests.
   * open ipython
     ipython --pylab
   * show a sin(x) figure     
      x = arange(-5,5,0.1)
      y = sin(x)
      plot(x,y)
      savefig("sin_x.png")     
   * And that code should have shown you a figure of a beautiful sin(x) wave:



cygwin + ipython. a perfection.

I'm one of those programmer who just loves anything about Unix, but just feels weird about using Linux GUI hence stuck with Windows 7.

The most perfect tool for us is ofcourse, Cygwin.

However, there are some (many, actually) weaknesses in Cygwin such as sometime you have to manually figure out how to install some softwares manually, instead of just invoking sudo apt-get in a Linux system.

I recently just faced this problem when trying to install ipython with numpy+scipy+matplotlib in my system in Cygwin, and had to waste all-saturday to finally have it installed correctly.

Nevertheless, It was really worth the time.

Cygwin + Ipython. is. just. amazing.
 You can literally do anything you want since there are ridiculously many amazing python libraries that you can invoke anytime you want anything you need.

I seriously recommend to every python programmer who uses Cygwin out there.

Turning Python-nese

Just recently I'm in love with python language, not just because it fastens your software development milestone, it only also has brilliant developers who make this language more convenient to use. PyOpenCL and PyCUDA are only some simple examples. ipython is another amazing tool.

Check out the project here

Fresh graduate

Having been busy throughout the entire senior year of my undergrad, finally I got my bachelor degree of Computer Science. The new journey as a professional programmer has started! Looking forward into any kinds of job waiting ahead.