Nugroho's blog.: internet
Showing posts with label internet. Show all posts
Showing posts with label internet. Show all posts

Tuesday, November 13, 2012

Moving to HTML5

After years fighting the slow loading flash without alternative software, I begin to think seriously about moving to HTML5 coding. Altough it ain't true software for me, it provide what I need mostly: animation.

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

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.

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

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

Displaying Calculation Output of Python Script to Web Page using Python-based Web Server

It'll be convenient if we could displaying output from our Python code to web page.

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, HTTPServer
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()

Access it using web browser in localhost:8080 from your computer running code above, or :8080 and get this


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


The simplest way is by update broadcom driver and firmware using OpenSuSE repository. (I think it just enough to upgrade firmware only)

The hard way is compile using STA driver obtained from Broadcom site.

and .......... yes, the wifi is succesfully on. Hm, how can we life without wifi?

Posted by ShoZu

Configuring Broadcom Wifi on my tx2510 (2500) within OpenSuSE 11.1 64 bit linux


The simplest way is by update broadcom driver and firmware using OpenSuSE repository. (I think it just enough to upgrade firmware only)

The hard way is compile using STA driver obtained from Broadcom site.

and .......... yes, the wifi is succesfully on. Hm, how can we life without wifi?

Posted by ShoZu

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.

Posted by ShoZu

Thursday, November 27, 2008

Hore

Finally, I'm able to conquer Telkomsel Flash+W960i+OpenSuSE10.3
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)