Nugroho's blog.

Saturday, December 24, 2011

SSH Tunnelling Firefox on Oneiric Ocelot behind Virtual Box's NAT

I have Ubuntu 11.10 guest installation on my VBox on OS X Lion host. What the point of it? Yeah, first I want to create isolated environment that won't bring the headache if it destroyed. Second, I want to break that isolated environment so it can reach the world wide.



For start, I begin with ssh tunneling. I used ssh connection to tunnel firefox's data. It look like firefox isn't connect through NAT but through my ssh server instead.

To be able to do this. I have to have access to some server outside via ssh. Fortunately, now free shell access is widely available, just google for it and subscribe.

To make connection through ssh for tunneling use this command

ssh -ND 7777 yourusername@shellserver.com 

It will bring a prompt ask for password and then nothing, that N means, it will not bring interactive shell

On firefox side, open edit, preferences, advanced, network, setting
Choose manual configuration and type on SOCKS host: localhost port 7777

Now firefox's connection have been tunnelled.

Friday, December 23, 2011

Automounting Shared Folder on Ubuntu 11.10 Oneiric Ocelot as Guest in OS X Lion VirtualBox

My Ubuntu 11.10 Oneiric Ocelot on virtual box have shared folder with host OS X Lion named 'vbox'. I used to typing command after login to mount that folder to my home directory. I mount it to falder named 'vbox' too using this command

$sudo mount -t vboxsf vbox vbox.  

However, at old time, I used to auto mount other partition that refused to automount (usually ntfs or other linux distros partition) at login by editing /etc/fstab



(using vi, press k to scrolldown and press i or a to edit the last line)
aravir@aravir-VirtualBox:~$ sudo vi /etc/fstab

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda1 during installation
UUID=3c8759e3-314b-4e42-a39e-efe9c18a130c / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=1b64eb34-42af-4ada-8bf1-0273d572cdb6 none swap sw 0 0
#virtualbox shared folder
vbox /home/aravir/vbox vboxsf auto 0 0

press :wq! to save and quit vi session


Restart the machine. 


After the machine is back, well, there is no sign that my tweak above worked. Curious, I want to take a peek of what kind and what are already mounted by system.


aravir@aravir-VirtualBox:~$ mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro,commit=0)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
vbox on /home/aravir/vbox type vboxsf (rw)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
vbox on /media/sf_vbox type vboxsf (rw,gid=1001)
gvfs-fuse-daemon on /home/aravir/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=aravir)
aravir@aravir-VirtualBox:~$
It's like the vbox is successfully mounted TWO times, however:
  • vbox did mount on /home/aravir/vbox but it's no file at all 
  • vbox mounted on /media/sf_vbox but only root have access to it 
So the last resort is playing with rc.local
aravir@aravir-VirtualBox:~$ sudo vi /etc/rc.local 

add this line before exit 0 

mount -t vboxsf vbox /home/aravir/vbox 

so the /etc/rc.local become like this
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
mount -t vboxsf vbox /home/aravir/vbox
exit 0
Restart the machine and voila, its success

Thursday, December 22, 2011

Lagu dengan Ketukan Nada Ganjil

Saat terbaring kaku karena obat tidur dosis super, aku buka iTunes dan memainkan keseluruhan koleksi  lagu-lagu secara shuffle. Enak sekali tidur tanpa bisa bergerak sambil diiringi lagu-lagu yang kadang sangat sering kuputar, kadang ada yang sudah lama tidak kuputar, bahkan lupa kalu pernah punya lagu itu.

Saat lagu "Tidurlah-tidur"nya Katon selesai, mulailah ketenangan tidurku terusik ketika "Under A Glass Moon"-nya Dream Theather mulai dimainkan oleh si Apple Mac. Lagu ini memiliki ketukan-ketukan yang berganti-ganti. Awalnya 6/4, sudah aneh, coba anggukkan kepala mengikuti nada-nadanya, anda akan dipaksa menganggukkan kepala saat seharusya anggukkan anda masih di atas. Saat melodi, hm , anda sakti kalo tahu itu birama berapa. Banyak lagu-lagu Dream Theather yang memiliki karakter seperti ini



Di "Metropolis", coba anggukkan kepala mengikuti ketukan di section 3, pasti anda akan dipaksa menghentikan kepala sejenak untuk mensinkronkan anggukkan kepala anda dengan musik. Itu di bagian saat ada bait "I was told there's a miracle for each day that I try, I was told there's new love is born for each one that's die, I was told there'll be no one to call on when I feel alone and afraid, I was told if You dream of the next world, you'll find yourself swimming in the lake of fire..."

Saat bagian melodi pun, sudah menjadi ciri khas DT, biramanya kebanyakan ganjil dan meloncat-loncat. Saat-saat awal mendengarkan lagu-lagu Dream Theater, aku sudah langsung berpikir "aku tidak akan mencoba memainkan lagu-lagu ini" Bukan karena tidak suka, tapi terlalu rumit untuk sebuah band jazz-latin-bossa, hehehe

Lagu-lagu yang memiliki birama tidak lazim sangat banyak.

Steve Vai, gitaris, mempunyai lagu-lagu seperti Incantation dengan birama 5/4, bayangkan gimana otak drummernya. Bagian melodi akustik di "Freak Show Excess" juga memiliki birama ganjil.

Naif punya lagu "Elton John" dengan birama 14/16 di bait awal

Beatless di lagu pertama side B album The Best of, birama 5/4

Dan yang paling sering kita dengar tahun lalu sebagai theme song di ISL adalah Damage Control, dari album solo John Petrucci (Gitaris Dream Theater). Lagu ini memang terkesan sporty dan heavy saat intro awal yang hanya dibawakan dengan gitar. Belum tampak keganjilan ketukannya, namun begitu drum dan bass masuk, coba anggukkan kepala anda, pasti beberapa saat kemudian anda akan dipaksa mensinkronkan kembali anggukan kepala anda dengan ketukan lagu, hehehe.

Obat Tidur Dosis Super

Saat ini aku susah bergerak, bahkan untuk batuk pun susah karena perut terasa kram. Bukan karena terkena penyakit tertentu, melainkan karena obat tertentu.

Tiga hari ini, tenggorokan terasa panas, bukan seperti batuk pilek biasa. Setelah periksa ke bidan desa, ternyata tenggorokanku ada semacam sariawan!!! Difteri, hm, sudah hampir dua tahun tidak mengalami lagi, bukannya ingin sakit sih, cuma gak bisa lupa sakit yang dua tahun lalu, suaraku sampe berubah jadi pecah kayak robot. Kalo bisa diatur agar suaranya bisa suara prime-tertz-quin sih tidak masalah, :(



"Suntik mas?" (waduh...)
"Hehehe..."
"Ok"

Bidan ambil alat suntik dan mencobloskan jarumnya ke ampul obat putih bening, seperempat dari isi keseluruhan alat suntik. Setidaknya yang disuntikkan tidak banyak, pikirku. Eh, tapi kok obatnya aneh?

"Bu, kok obatnya bening. Kayaknya dulu warnanya merah deh"
"Memang, lha ini yang merah" bu bidan mencobloskan jarum lagi ke ampul merah. Sekarang sudah setengah alat suntik terisi cairan, deg...deg..deg.
"Pernah alergi obat Mas?"Aku cuma bisa geleng, mulutku gak bisa kupercaya untuk mengeluarkan sepatah kata tanpa bergetar.

"Kalo gitu tak tambahkan ini" Sekarang alat suntik sudah berisi PENUH cairan obat yang akan disuntikkan ke tubuhKU..., duh gusti...

"AAAOOOUUUWWW..."

"Walah, sudah bolak balik ke sini berpuluh tahun kok ya masih sama gayanya"

"AAUUWWW..."

Semenit kemudian barulah dicabut. Aku cemberut.

Beberapa menit kemudian
"Nah, yang ini diminum kalo diare, 2 buah pil, jika dan hanya jika diare lho. Kalo nggak diare nggak usah di minum. Yang putih kecil ini untuk pilek tiga kali sehari , tapi minumnya besok, soalnya di suntikkan tadi sudah ada. Nah kalo yang untuk pusing bisa disimpan untuk suatu saat kalo pusing lagi, tiga kali sehari, kalo sudah tidak pusing hentikan minumnya, yang ini antibiotik....blablabla..."

Begitulah aku diberi obat 11 macam pil yang fungsinya macam-macam, dari diare, pusing, pilek, demam, sariawan ditenggorokan sampai jamur di usus. Hm, setidaknya aku masih tahan tidak pingsan mendengarnya, kalau pil sih, kecil... Suntikan? No Way...

Malamnya langsung minum obat, tidak ada masalah

Dini hari. Terbangun, keringat dingin yang melimpah tanda sembuh, mau merubah posisi tidur, eh loh? Kok badanku kaku? Coba menengokkan kepala, tidak bisa. Kupaksa bangun dengan cara normal, YA AMPUN, perutku rasanya seperti baru sit-up tujuhratus tujuhpuluh tujuh kali, njarem (ngilu). Pasrah, tidur lagi dengan posisi yang sama, obat tidurnya masih berpengaruh kuat.

Subuh terbangun lagi, mau menggeser kaki pun rasanya seperti habis lari marathon tanpa pemanasan. Kupaksa bangun sambil teriak-teriak, rasanya seluruh tubuhku habis digebuki orang (hm, mungkin rasanya gitu, gak pernah digebuki orang), tetap kupaksa bangun, ingin pipis.

Jalanku seperti robot, tangan kanan membantu mengangkat kaki kanan, yang kiri juga sama. Dekat kamar mandi ketemu Anggun

"Mas, kenapa"
"Gak tahu, kaku semua. Apa memang obatnya berpengaruh seperti ini?"
"Harusnya enggak, mana obatnya, tak lihatnya" Anggun juga bidan
"(nggremeng) hm, ni obat pilek ada CTM-nya, antibiotiknya ok, demakolin, loh, ini kan ada CTM-nya juga? wah ni harus diminum salah satu tok, nah kalo yang ini gak papa terus yang...."

....

"Wah, ini sampeyan dapat dua jenis pil yang ada obat penenangnya, efeknya sampeyan seperti dibius, efek sampingnya bisa kayak saya dulu, leher kaku, eh kalo sampeyan sekujur tubuh kaku, hehehe..."

Duh, dan beginilah, untuk batuk saja malah lebih susah dari sebelum diobati. Mungkin maksudnya memberi efek jera agar tidak bisa batuk, tapi... Setidaknya demam dan pilek sudah hilang, walau masih terbujur kaku.

Monday, December 19, 2011

Python-based Web Page to Compute Function with User Input Flexible Function

This is improved from my python-based web based to display function. In this version, users have ability to input a function and then display it with it value for given variable to python-based web page.

The code below will get input from users (if no input, the default value is sin(x)), parsed it to function python understand, and then eval it for given variable (in this code, x=10). After computed, it's inserted to template that resembling html code. Thus, since it's displayed in html style, we could add our customization (background, css, etc)



Here's the code


#!/usr/bin/python
# -*- coding: utf-8 -*-
import BaseHTTPServer, urllib, re
import sys,parser
from math import *

class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
    template = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>%s</title>
        </head><body><h1>%s</h1><pre>%s</pre>Function<form action="" method="POST"
        class="editor"><div><textarea name="text">%s</textarea><input type="submit"
        value="Compute"></div></form></body></html>"""
    
    def escape_html(self, text):
        """Replace special HTML characters with HTML entities"""
        return text.replace(
                            "&", "&amp;").replace(">", "&gt;").replace("<", "&lt;")
    
    def link_repl(self, match):
        """Return HTML for link"""
        title = match.group(1)
        if title in self.server.pages:
            return u"""<a href="%s">%s</a>""" % (title, title)
        return u"""%s<a href="%s">?</a>""" % (title, title)
    
    def do_HEAD(self):
        """Send response headers"""
        self.send_response(200)
        self.send_header("content-type", "text/html;charset=utf-8")
        self.end_headers()
    
    def do_GET(self):
        """Send page text"""
        self.do_HEAD()
        page = self.escape_html(urllib.unquote(self.path.strip('/')))
        text = self.escape_html(self.server.pages.get(page, "sin(x)"))
        parsed = re.sub(r"\[\[([^]]+)\]\]", self.link_repl, text)
        #hitung fungsi
        fungsi=parser.expr(parsed).compile()
        x = 10
        y = eval(fungsi)
        tout = 'The value of  ',parsed, ' on x = ',x,' is ',y
        tout = str(tout)
        tout = re.sub(r",", "", tout)
        tout = re.sub(r"\'", "", tout)
        tout= tout[1:]
        tout= tout[:-1]
        self.wfile.write(self.template % (page, page, tout, text))
    
    def do_POST(self):
        """Save new page text and display it"""
        length = int(self.headers.getheader('content-length'))
        if length:
            text = self.rfile.read(length)
            page = self.escape_html(urllib.unquote(self.path.strip('/')))
            self.server.pages[page] = urllib.unquote_plus(text[5:])
        self.do_GET()

if __name__ == '__main__':
    server = BaseHTTPServer.HTTPServer(("", 8080), Handler)
    server.pages = {}
    server.serve_forever()

Here's the screenshot
From python

Sunday, December 18, 2011

User Input on Python during Runtime

Eventually, we want interactivity when executing Python script. We want user to give input for some variable. It'll useful for, lets call, application form where user have to input her/his name, age, etc. On math field, user will have flexibility to input the function and range of variable used to computation.



There is raw_input command and input command we can used.

raw_input command will translate all we type to string, while input command treat it as command

Here difference between the two

raw_input
x=raw_input('type anything \n')
print 'you typed ', x

Execute it
Nugrohos-MacBook-Pro:python nugroho$ python input.py 
type anything
a
you typed a
Nugrohos-MacBook-Pro:python nugroho$ python input.py
type anything
12
you typed 12
Nugrohos-MacBook-Pro:python nugroho$ python input.py
type anything
sin(x)+x**2
you typed sin(x)+x**2
Nugrohos-MacBook-Pro:python nugroho$

input
c='sin(x)+x**2'
me='Hello folks, Aravir here'
x=input('type anything \n')
print 'you typed ', x

Execute it
Nugrohos-MacBook-Pro:python nugroho$ python input.py 
type anything
a
Traceback (most recent call last):
File "input.py", line 3, in
x=input('type anything \n')
File "", line 1, in
NameError: name 'a' is not defined
Nugrohos-MacBook-Pro:python nugroho$ python input.py
type anything
12
you typed 12
Nugrohos-MacBook-Pro:python nugroho$ python input.py
type anything
sin(x)+x**2
Traceback (most recent call last):
File "input.py", line 3, in
x=input('type anything \n')
File "", line 1, in
NameError: name 'sin' is not defined
Nugrohos-MacBook-Pro:python nugroho$ python input.py
type anything
c
you typed sin(x)+x**2
Nugrohos-MacBook-Pro:python nugroho$ python input.py
type anything
me
you typed Hello folks, Aravir here
Nugrohos-MacBook-Pro:python nugroho$

Displaying Calculation Output of Python on Web (customizing)

After success displaying output using python based web, it's normal if we want to display the value of function with a range of variable.

The code below will create web page hosted by Python 2.7 BaseHttpServer module. The page contains list of value of function sin(x)+x**2 at -7<x<7



from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import sys,parser
from math import *
import numpy as np

class Handler(BaseHTTPRequestHandler):
def do_GET(self):
n=10
x1=-7
x2=7
y = 'sin(x)+x**2'
z = parser.expr(y).compile()

self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()

self.wfile.write("Hi Folks, Aravir here")
self.wfile.write("")
self.wfile.write("Hi Folks, Aravir here
")
self.wfile.write("
")
for i in (range(x1,x2)):
x=i
self.wfile.write("The value of ")
self.wfile.write(y )
self.wfile.write(" on x = " )
self.wfile.write(x)
self.wfile.write(" is " )
self.wfile.write(eval(z) )
self.wfile.write("
")

self.wfile.write("")

if __name__=="__main__":
try:
server = HTTPServer(("", 8080), Handler)
server.serve_forever()
except KeyboardInterrupt:
server.socket.close()


Here the result in Safari, Mac OS X Lion

From python
323f (5) amp (1) android (12) apple (7) arduino (18) art (1) assembler (21) astina (4) ATTiny (23) blackberry (4) camera (3) canon (2) cerita (2) computer (106) crazyness (11) debian (1) delphi (39) diary (286) flash (8) fortran (6) freebsd (6) google apps script (8) guitar (2) HTML5 (10) IFTTT (7) Instagram (7) internet (12) iOS (5) iPad (6) iPhone (5) java (1) javascript (1) keynote (2) LaTeX (6) lazarus (1) linux (29) lion (15) mac (28) macbook air (8) macbook pro (3) macOS (1) Math (3) mathematica (1) maverick (6) mazda (4) microcontroler (35) mountain lion (2) music (37) netbook (1) nugnux (6) os x (36) php (1) Physicist (29) Picture (3) programming (189) Python (109) S2 (13) software (7) Soliloquy (125) Ubuntu (5) unix (4) Video (8) wayang (3) yosemite (3)