Month: February 2013

Start of New Project – Raspberry Pi

Image

I have finally decided to set up a blog to record down my journey with Raspberry Pi. It has been almost 2 weeks since I laid my hand on Raspberry Pi (R-Pi). I have never used Linux before. To me, it is a stranger Penguin which is just another operating system like Window or Mac. I never knew this penguin could offer so much to the programmers and it is absolutely open source and free.

Well I love free stuffs, and therefore I shall not miss this opportunity to learn and gain invaluable and FREE knowledge available on the giant database, Internet.

I just watched “Social Network” yesterday (24th February 2013) and I felt a bit demoralized. I am about Mark’s age and I can’t even set up a WordPress. All I know is how to use Facebook (perhaps, not even to the full extent. Yeah right, I can’t use Facebook codes to write an app, can I?)

So here I am, once again, determined to do something useful and meaningful. To be frank, I have been through such motivated state for a few times over the years. However the determination would often die out soon enough. Lack of time, lack of resource, and no one to share the joy of achievement!

But I feel that I should really make good use of this opportunity to train myself through this 6 months (22 weeks to be exact) Industrial Attachment. Well 6 weeks have passed and how much can I recall? It does not matter because the most important thing is the present and the future.

Perhaps, I could include my other interests (arts, crafts, and movie) and some other stuffs like search engine optimisation in the future!

Let’s do it!

Killer Web Development Walkthrough 3

 An App for a Pitch

 

Let’s move on to the next section of Killer Web Development. We are going to create an application from the command line, and not through the web2py interface.

 

1. Creating a Pitch App

 

Creating the pitch app confused me a bit because I didn’t install web2py following his tutorial, remember? So I have no idea on where is my web2py.py file located.

 

$ cd /your/web2py/folder  # on Windows use backslashes

$ ./web2py.py -S pitch   # web2py.exe on Windows and web2py.app on OS X

I spent some time searching for “how to find a file on Linux” and finally I found some clues of using “find”.

 

$find / -name 'web2py.py'

It searched for a while and found its directory – /home/www-data/web2py/web2py.py

 

So I typed in

cd /home/www-data/web2py

./web2py.py -S pitch   (no idea what is -S, couldn’t find it on web)

Now it is time for Mercurial.

 

“In the terminal go to the directory of the pitch app; create a repository; then create a .hgignore-file; add files to the repository and make your initial commit:

$ cd applications/pitch

$ gedit .hgignore

Line 1 is misleading because it should be the complete directory.

For my case:

 

$ cd /home/www-data/web2py/applications/pitch

 

Then at $ /home/www-data/web2py/applications/pitch $ type in
gedit .hgignore

A gedit file will be created. I typed in as instructed but realized that it could not be saved. Yes, I am not the super user!

So, I should type in sudo gedit .hgignore at the terminal. Now, another gedit file is created but without the index 1 2 3 etc at the front when the codes are typed in. The file is saved. Interestingly, this reminds me of Chemistry! Hg is mercury periodic symbol.

 

Again, at the next few command in the terminal, “sudo” has to be included at the front;

 

sudo hg init

sudo hg add .

sudo hg commit -m”Initial commit”

–                    no username supplied. Well seems like the .hgrc file in the previous section comes to use here? I saved it in home/www-data/web2py/applications/pitch (since it says save in home directory).

–                    still the same though. May be I should save it with the web2py pitch file.

–                    Could not save the file as I do not have the permission to save the file in that directory.

–                    Try to save in /home/ – no permission too

 

Found this under the comment: Hg Init

More things to read up here!

 

So in the end, I use the terminal to open up a new file.

 

cd /home

sudo gedit .hgrc

 

I typed in the username and such and save it.

 

Now, try out the hg commit. It is still the same. Well then, till tomorrow!

Killer Web Development Walkthrough 2

Still on the Killer Web Development tutorial. Step 2 walkthrough:

I installed :

  • the text editor gedit
  • the web browser Firefox with the Firebug-extension
  • the version control system Mercurial

I actually installed them on my Raspberry Pi as well as Window XP.

Start off with Window XP:

Gedit : download from here  (thanks to firebug!)

Python : I chose python 2.7.3 for my Window XP

Didnt manage to set the path properly I guess, because it didnt show me the path when I typed “python” in command prompt.

Firefox

Firebug

Firebug is one awesome Firefox extension!! it is like a recce bug sent off to a destination before I’m going there. Well, not exactly but I can check out the destination before I click on a button! Fights off malicious links! It is able to analyze websites too. Have not try it out though but surely helpful for my site analytic.

Press F12 will toggle to firebug window and pressing Ctrl + shift + C will be in the bug mode!

Mercurial: not really sure what it is used for though.

Next, on my Raspberry Pi Linux system.

Gedit: sudo apt-get install gedit

Python: already installed

Firefox: no such thing in Debian system!

Instead, it is called Iceweasel. Haha, funny huh?

sudo apt-get install iceweasel

Firebug: sudo apt get install iceweasel-firebug

(Not too sure if just the last one will work.)

Mercurial: sudo apt-get install mercurial

I just followed blindly to set up the mercurial text file (“first time setup”) without knowing what is the purpose though.

I skipped the Cygwin section.

Killer Web Development Walkthrough 1

1. Introduction

 I have somehow came across an awesome website called “Killer Web Development” (http://killer-web-development.com/). It is an online tutorial written by Marco Laspe, all about how to create real world web applications using web2py, an open source web development tool, and other stuffs related such as Python.

 He said, “The only prerequisites for this book are your enthusiasm and that you have basic knowledge how to use your computer.” Yes, I do! And I hope the enthusiasm will grow! 🙂 The problems that I am having is the unfamiliarity with Linux OS and Python language. Even though I did a project on Android and Python last year, I could not recall how the interface looks like. Opps, this sounds ridiculous.

1.1 Introduction to web2py

Web2py is a rather new tool developed by Massimo Di Pierro in 2008. I tried it a few days ago when I was following another tutorial on creating a web application to control the lighting at home using R-Pi (http://www.instructables.com/id/Raspberry-Pi-GPIO-home-automation/). I will recall that on my blog when I have time. It was quite fun following though the steps in instructables.com and I learnt a lot!

Perhaps, lets start on the Killer Web Development! (mostly based on the tutorial and my own side notes)

1.2 Start your Engine

The first step was easy – get the web2py on your computer! (http://killer-web-development.com/section/1/3)

I did not follow the first few steps as I have gotten my web2py through this method:

  1. On R-Pi system, start the terminal and log in.

  2. sudo su

  3. wget http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh
    chmod +x setup-web2py-ubuntu.sh

    ./setup-web2py-ubuntu.sh

***

sudo su – is to set the user mode to superuser whom is capable to do anything as the root user.

wget – which I observed, is to download something from the internet directly

chmod +x – is to grant execute access

./ – is to run a certain shell script?

During the installation, it is important to include the email and password, so that I can log into the server.

Then I could access web2py server at https://10.0.0.192 (my domain IP) , which will show a web2py default home index page. HTTPS is particularly important because the server is secured. I think there shouldn’t be a problem if download from the website manually (http://web2py.com/examples/default/download), unzip it and run it. The only thing to mind is the IP address (which I spent quite sometime to figure out for my R-Pi last week) and the port number. I am wondering why is it 8000 instead of 8080.

8000

UDP

iRDMI (Intel Remote Desktop Management Interface)[86]—sometimes erroneously used instead of port 8080

Official

8000

TCP

iRDMI (Intel Remote Desktop Management Interface)[86]—sometimes erroneously used instead of port 8080

Official

8000

TCP

Commonly used for internet radio streams such as those using SHOUTcast

Unofficial

8000

TCP

FreemakeVideoCapture service a part of Freemake Video Downloader [87]

Unofficial

8080

TCP

HTTP alternate (http_alt)—commonly used for Web proxy and caching server, or for running a Web server as a non-root user

Official

8080

TCP

Apache Tomcat

Unofficial

8080

UDP

FilePhile Master/Relay

Unofficial

 (source : wikipedia http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers)

Posted it as a question to Mr Laspe and wonder if he will reply :O .

Image

Next is to log into the Administrative Interface using my password. Here you could see some of the applications that I have created for the past few days. I just followed through the steps on the rest of the section.

Image

The interesting thing I learnt is the format of displaying the text.

return dict(message=T(‘Hello World. I\’m John. How are you?’))”

There is a complete Application Programming Interface (API) of web2py which can be found here: http://web2py.com/book/default/chapter/04#API

T” is the internationalization (i18n), which confused me for a while but after some readings, I somehow understand what it is for. It basically structures application in a way that makes it possible for them to localized. So cool!

So, “T” means “language translator”. Which if it contains message bundle for certain language, it is able to be translated. Awesome huh?

dict” means dictionary! Read more here (http://docs.python.org/2/tutorial/datastructures.html#dictionaries) but I do not quite understand.

Then it is almost the same as normal html editor, which I am not too familiar with. Also, “Notice the Backslash (\) behind the I – this is important because Python uses ticks to encapsulate Strings.” Then Ctrl+S to save.

(Hmm, I wonder what have I learnt in my study years! *rant rant*)

1.3 Deploying Your First App

Moving to next section – Deploying the web application. Yes, the word “deploy” confused me but all the answers are on Google.com

To install, test and implement a computer system or application” is the best answer I got from http://www.webopedia.com/TERM/D/deploy.html.

There are a few ways to deploy our web application which includes fluxflex.com ( I have not try it), Google’s App Engine, Pythonanywhere and etc (http://web2py.com/books/default/chapter/29/13).

It is my first time knowing Google’s App Engine, sounds cool. I should explore it when I am more advanced in this field.

So the tutorial guides us through how to deploy using http://pythonanywhere.com. I signed up for free account and got locked out once because I forgot the password (I think I mistyped it). I deleted the new application, log out, log in, and recreate a new application (choose web2py format and upload the w2p file). Then at http://yvonnezoe.pythonanywhere.com my website is online! Well it looks the same as https://10.0.0.192.com/first just that this is live and everyone could see it rather than just on my server. Awesome, I found another hosting!

1.4 Conclusion

Oh man! I found another interesting site called Diaspora! Check it out here: https://joindiaspora.com/. Perhaps with my little determination and some encouragement from all around the world (from you, reading this), I can be an older version of Mark Zuckerberg. Laugh. Okay, KIV but no Diaspora during working hour! (in fact, no blogging during working hour, but i’m treating this as a log book and not crapping!)

Okay, till next post! 🙂

– Zoe –