Tuesday, November 13, 2012
Moving to HTML5
HTML5 support canvas, audio ad video tag, javascript. Need array data? No problem. If then else? OK.
So, begin...
Saturday, December 24, 2011
SSH Tunnelling Firefox on Oneiric Ocelot behind Virtual Box's NAT
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.
Monday, December 19, 2011
Python-based Web Page to Compute Function with User Input Flexible Function
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
From python |
Sunday, December 18, 2011
Displaying Calculation Output of Python on Web (customizing)
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 |
Displaying Calculation Output of Python Script to Web Page using Python-based Web Server
To convert calculation output of Python script to web page we need BaseHTTPServer, a Python-based web server. With it, we could write any python code and display it in no time. It has advantage in form of simplicity, we don't need php to convert our result or typing it to static html code, we just used python alone (it's possible to write html and php code on python though).
This code below will display python script calculating value of a function (sin(x)+x^2) to web page. As it behave as web server too, we don't need apache or other web server to broadcast it.
Here the code. It's written in Python 2.7 on Mac OS X Lion with numpy module and sys, parser and basehttpserver built in module.
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServerAccess it using web browser in localhost:8080 from your computer running code above, or
import sys,parser
from math import *
import numpy as np
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
n=10
x=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("
")
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("")
if __name__=="__main__":
try:
server = HTTPServer(("", 8080), Handler)
server.serve_forever()
except KeyboardInterrupt:
server.socket.close()
From python |
Sunday, December 11, 2011
Creating Django Apps on OS X Lion 10.7.2
As this is my first time using Django, I have to take care of some initial setup. Namely, I’ll need to auto-generate some code that establishes a Django project – a collection of settings for an instance of Django, including database configuration, Django-specific options and application-specific settings.
From the command line, cd into a directory where you’d like to store your code, I use my python directory,then run the following command:
django-admin.py startproject mysite
This will create a mysite directory in my python. Here tho result.
Nugrohos-MacBook-Pro:python nugroho$ pwd
/Users/nugroho/python
Nugrohos-MacBook-Pro:python nugroho$ ls
appender.py distribute-0.6.24.tar.gz graphy graphy.pyc
apprunner.py f.py graphy.py
Nugrohos-MacBook-Pro:python nugroho$ django-admin.py startproject mysite
Nugrohos-MacBook-Pro:python nugroho$ ls
appender.py distribute-0.6.24.tar.gz graphy graphy.pyc
apprunner.py f.py graphy.py mysite
Nugrohos-MacBook-Pro:python nugroho$ cd mysite/
Nugrohos-MacBook-Pro:mysite nugroho$ ls
__init__.py manage.py settings.py urls.py
Nugrohos-MacBook-Pro:mysite nugroho$
These files in mysite directory are:
__init__.py: An empty file that tells Python that this directory should be considered a Python package. (Read more about packages in the official Python docs if you're a Python beginner.)
manage.py: A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin.py and manage.py.
settings.py: Settings/configuration for this Django project. Django settings will tell you all about how settings work.
urls.py: The URL declarations for this Django project; a "table of contents" of your Django-powered site. You can read more about URLs in URL dispatcher.
To verify that it works do this
Nugrohos-MacBook-Pro:mysite nugroho$ python manage.py runserver
Validating models...
0 errors found
Django version 1.3.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Yup, it works…
Try to access http://127.0.0.1:8000 with your browser, :)
Here screenshot from Safari on my Lion
From Blogsy Photos |
If we want to show off on other computer, use command below. It will listen on all public IP's
Nugrohos-MacBook-Pro:mysite nugroho$ python manage.py runserver 0.0.0.0:8000
Validating models...
0 errors found
Django version 1.3.1, using settings 'mysite.settings'
Development server is running at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Here screenshot from my iPad
Django Python Module on OS X Lion 10.7.2
As python programmer, I wish I could build a web using it too. I used to use CMS based portal, but eventually I want python thing in my site. Fortunately, it can be done, using Django.
According it site, Django (https://www.djangoproject.com/) is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Developed by a fast-moving online-news operation, Django was designed to handle two challenges: the intensive deadlines of a newsroom and the stringent requirements of the experienced Web developers who wrote it. It lets you build high-performing, elegant Web applications quickly.
So I finally give it a try, it isn't hurt anyway, :). Installing Django in my Python 2.7 on my 13' Macbook Pro with OS X Lion 10.7.2 is fairly easy, using pip from pypi (pypi.python.org/). All I have to do is typing in terminal: pip install django. Of course, we need pip to be installed first.
Nugrohos-MacBook-Pro:python nugroho$ pip django
Usage: pip COMMAND [OPTIONS]
pip: error: No command by the name pip django
(maybe you meant "pip install django")
Nugrohos-MacBook-Pro:python nugroho$ pip install django
Downloading/unpacking django
Downloading Django-1.3.1.tar.gz (6.5Mb): 6.5Mb downloaded
Running setup.py egg_info for package django
Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from 644 to 755
changing mode of /Library/Frameworks/Python.framework/Versions/2.7/bin/django-admin.py to 755
Successfully installed django
Cleaning up...
Nugrohos-MacBook-Pro:python nugroho$python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print django.get_version()
1.3.1
>>> exit()
Nugrohos-MacBook-Pro:python nugroho$
That's it.
The Journey of Installing Matplotlib Python Module on OS X Lion
I need matplotlib to plot my python output when I am running my output function generator python code.
This post is a log of what I did to being able to install matplotlib 1.1.0 on python 2.7.2 on my Mac OS X Lion 10.7.2. Yet, it's unfinished job.
First, googling for matplotlib, sourceforge is official home fon it, but it's very slow, I coudn't even open download page with my sluggish connection. So, I searching other source.
Got it from kambing.ui.ac.id, it has pypi repositories, but when it opened, there is no package, just blank folder.
After further googling, I finally found http://pypi.python.org, pypi stand for python package index.
To be able to use pypi package, we have to install pip first, but before that install distribute using this command
curl http://python-distribute.org/distribute_setup.py | python
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
and then install matplotlib using pip, there is download activity, but got error at the end; must install numpy first, but it got error too as I didn't have GCC on my lion yet, aaarrrgghh... So, the hell of dependencies is begin...
So here I am, searching for 'light' GCC for my lion. I know I should install XCode 4 from Apple , it's free anyway, but I must face the fact that it's including 4.5GB download job, such a tedious job and wasting time; I just want to install 13 MB matplotlib.
I wish I can type the code below
pip install numpy
pip install matplotlib
(pray)
Tuesday, December 23, 2008
Configuring Broadcom Wifi on my tx2510 (2500) within OpenSuSE 11.1 64 bit linux
Configuring Broadcom Wifi on my tx2510 (2500) within OpenSuSE 11.1 64 bit linux
Saturday, November 29, 2008
Using Telkomsel Flash, W960i and OpenSuSE Linux
Attach your w960i to computer, make sure it is in "normal mode"
create file wvdial-flash.config in folder /etc (you must be login as root, or at least copy to /etc folder as root)
[Dialer Defaults]
Modem=/dev/ttyACM1
Baud=115200
Init1=ATZ
Init2=ATQ0 V¹E¹S0=0 &C¹&D2
Init3=
Phone=*99#
Username=internet
Ask Password=0
Dial Command=ATDT
Stupid Mode=1
Compuserve=0
Force Address
Idle Seconds=0
Dial Message1=
Dial Message2=
ISDN=0
Auto DNS=1
using wvdial (as root):
#wvdial --config /etc/wvdial-flash.config
if you got error, try to play 2nd line e.g Modem=/dev/ttyACM2 (it sometimes occur when i detach the phone and attach it again)
Enjoy.
My sky is high, blue, bright and silent.
Nugroho's (almost like junk) blog
By: Nugroho Adi Pramono