Wednesday, March 12, 2014

Install and Run Python in Aptana

Aptana studio is open-source web development IDE, can be downloaded from:
When you create a Pydev project, you may find python interpreter not found.
1) To install  python interpreter:
2)Then start Aptana, go to Aptana window menu, select preferences, select interpreter - python
under Pydev in left menu, then go to right menu, click new, browse python.ext for Python executable, for example C:\python33\python.exe
click apply
3) restart Aptana,
Click new Pydev project using python interpreter we just created
 create new python file,
print("Hello, World!")
click run,  in the first time, there may popup one dialog, select python -run in first choice
Video: Install and Run Python in Aptana

Tuesday, March 11, 2014

Load json data and json url in Python 3.3

Load json data in Python 3.3 a little from Python 2.7
Here I gave two examples using Json data from an array and from url. load json data from an array in Python3.3

 import json
data = [ { 'a':'A', 'b':(2, 4), 'c':3.0 } ]
data_string = json.dumps(data)

data_load = json.loads(data_string)

 [{"a": "A", "b": [2, 4], "c": 3.0}]
[{'a': 'A', 'c': 3.0, 'b': [2, 4]}]

Reference:, load json data from url (earthquake data)
#past 30days M4.5 earthquake

import urllib.request
import json

geourl = ""
response = urllib.request.urlopen(geourl)
content =
data = json.loads(content.decode("utf8"))

Video:Load json data in Python 3.3


Monday, March 10, 2014

Fork or clone a repository in Gist or Github

GitHub is a web-based hosting service using
 the Git revision control system

Gist is a simple way to share snippets and pastes with others

For the following examples, first sign in my Github account

Example 1   fork  Gist repository in other users:
Go to the  gist I want to fork, example
at right top, click  fork
Now it is cloned to my account
Now in gist, click user name still in gist. Switch back to Github,
click github  at the top right menu,
now back to github, click use name, now you can see you gitnub repository, not gist,

Example 2:  fork a github (not gist) repository, for example
click fork at right top, then it will be shown in my github (in gist)
Note: it is shown  under repositories, not contribution
Video: Fork or clone a repository in Gist or Github

Saturday, March 1, 2014

JSON Examples in PHP

JSON: JavaScript Object Notation.  
JSON is smaller than XML and easy to parse.
JSON format:
a name followed by colon, followed by a value, such as
i.e fruit = "apple"
JSON object using curly bracket
var  temp={"fruit":"apple", "juice":"orange"}
To access JSON object value:
temp.fruit, temp.juice
JSON array using square bracket:
var JSONarray= {
{"fruit":"apple", "juice":"orange"},
{"fruit":"banana", "juice":"watermelon"}

To access the value  apple in array[0].fruit
Example 1: convert.php - Convert PHP associative array to javascript associative array

 //Example 1: Convert PHP associative array to javascript associative array
$arr = array('price' => 2, 'high' => 3, 'low' => 1);
echo json_encode($arr);
    var quote=<?php echo json_encode($arr); ?>;

Example 2: jQuery Ajax Jason example in PHP form
       <title>jQuery Ajax Jason example</title>
    <script type="text/javascript" src=""></script>
     <script type="text/javascript">
     $(document).ready(function() {


            url: "post.php",
            type: "POST",
            data: {
                message: $("#message").val(),
                firstName: $("#firstName").val(),
                lastName: $("#lastName").val(),
                email: $("#email").val()
            dataType: "JSON",
            success: function (jsonStr) {


    <h1>jQuery Ajax Jason example</h1>
    <div id="result"></div>
        <form name="contact" id="contact" method="post">
         Message : <textarea name="message" id="message"></textarea><br/>
         firstName : <input type="text" name="firstName" id="firstName"/><br/>
         lastName : <input type="text" name="lastName" id="lastName"/><br/>
         email : <input type="text" name="email" id="email"/><br/>
        <input type="button" value="Submit" name="submit" id="submit"/>


    $message      = $_POST["message"];
    $firstName   = $_POST["firstName"];
    $lastName    = $_POST["lastName"];
    $email       = $_POST["email"];
        $data = array(
            "User message"     => $message,
            "User firstName"  => $firstName,
            "User lastName"   => $lastName,
            "User email"      => $email
        echo json_encode($data);
Video: JSON Examples in PHP