Saturday, November 9, 2013

Quick Sort

# -*- coding:utf-8 -*-
#!/usr/bin/python2
"""
===================================================
Merge Sort
Shijie Xu <xushijie520@gmail.com>
Created on Mon, Nov 9, 2013
===================================================
"""
L = [3, 5, 7, 8, 1, 9, 2, 4, 6, 123, 12, 19, 123123]

def QuickSort(m):
    if len(m) < 2:
        return m
    else:
        target = m.pop(0)
        L1 = []
        L2 = []
        for item in m:
            if item <= target:
                L1.append(item)
            else:
                L2.append(item)
        L1.append(target)
        L = QuickSort(L1) + QuickSort(L2)
        return L

result = QuickSort(L)
print result

Merge Sort

# -*- coding:utf-8 -*-
#!/usr/bin/python2
"""
=====================================================
Merge Sort
Shijie Xu <xushijie520@gmail.com>
Created on Mon, Nov 9, 2013
=====================================================
"""
L = [7, 10, 5, 8, 1, 3, 2, 4, 6, 9]
def merge(x, y):
    L = []
    while (len(x) > 0) and (len(y) > 0):
        if x[0] < y[0]:
            L.append(x[0])
            x.pop(0)
        else:
            L.append(y[0])
            y.pop(0)
    L += x if len(x) > 0 else y
    return L

def msort(m):
    if len(m) < 2:
        return m
    else:
        mid = len(m) // 2
        L1 = msort(m[:mid])
        L2 = msort(m[mid:])
        l_result = merge(L1, L2)
        return l_result

reuslt = msort(L)
print reuslt

Sunday, October 6, 2013

Seattle

This is a Learning Journal of the Seattle in CS program in New York University.

1) Local Test Mechanism
python repy.py restrictions.test <Your repy files> 
2) Login to the Seattle
  1. python seash.py
  2. !> loadkeys <username> # load the the key information of the user
  3. !> as <username> # login as the user
  4. <username>@ !>
3) Useful Instruction in Seattle
    a) browse 
        # Browse the available resources in the Seattle.
    b) on browsegood 
        # Use the resources which are working in good condition
    c) run <Your repy files in your local path>
        # Run the program
    d) show log
        # Show the result of what the program have executed
    e) list
        # List the information of the vessel that you own or control
4) Specific Functions & Variables in Seattle
   You can refer to the webpage:
        https://seattle.poly.edu/wiki/RepyApi#waitforconnlocaliplocalportfunction
    mycontext: It is a dictionary type provided for the global variables
        eg: mycontext['global_variables'] = 'This is a global varible'
    settimer(waittime, function, arg): Set a timer that when it expires will start a new thread to call a function with a set of arguments. The thread is charged to your problem when you set the timer instead of when the timer fires. This function returns a timer handle that may be used to cancel the timer before the thread is started.

Tuesday, August 27, 2013

Sublime Installation on Ubuntu

1. Download the Sublime Text for Linux version from the official website.
2. Extract the .bz2 format file to the location where you must can find.
3. Move the sublime folder to /opt/
sudo mv Sublime\ Text\ 2 /opt/
4. At some point you'd want to be able to call Sublime Text from the Terminal by just typing 'sublime'. To do that, we'll just create a symbolic link in '/usr/bin' like this:
sudo ln -s /opt/Sublime\ Text\ 2/sublime_text/ usr/bin/sublime
5. Create a launcher in Unity. To do this, we create a .desktop file in '/usr/share/applications/sublime.desktop'
Edit the config files below:
sudo sublime /usr/share/applications/sublime.desktop
paste the following content in the file:
[Desktop Entry]
Name=Sublime Text 2
# Only KDE 4 seems to use GenericName, so we reuse the KDE strings.
# From Ubuntu's language-pack-kde-XX-base packages, version 9.04-20090413.
GenericName=Text Editor

Exec=sublime
Terminal=false
Icon=/opt/Sublime Text 2/Icon/48x48/sublime_text.png
Type=Application
Categories=TextEditor;IDE;Development
X-Ayatana-Desktop-Shortcuts=NewWindow

[NewWindow Shortcut Group]
Name=New Window
Exec=sublime -n

TargetEnvironment=Unity

OK, you have installed the MOST powerful editor in the world....lol

Saturday, April 27, 2013

Greek and Roman Mythology on Coursera

Small tips:

  • Agamemnon is air, Archilles is the sun, Helen is the earth, Hector is the moon. But among the gods, Demeter is the liver, Dionysus is the spleen, and Apollo the bile.--<Metrodorus of Lampsacus>

Thursday, March 28, 2013

Ubuntu Apt Error

昨天装wps装毁了...结果apt update就error了,怎么修复呢?
如下:
sudo gedit /var/lib/dpkg/status
Delete the WPS-office block
然后一切似乎就科学了~
sudo apt-get update
sudo apt-get upgrade

Sunday, March 17, 2013

Some Nice Apps on My Galaxy Nexus~

First Recommendatory Series: Google's Apps
Such as Google Map and Google Calendar and so on, are daily application we use, here I want to recommend some wonderful and little software I love very much on my mobile phone.

1.Any.Do <@https://play.google.com/store/apps/details?id=com.anydo&feature=nav_result#?t=W251bGwsMSwyLDNd>
It is a task list, and can sync with Google Task. All my task relied on it to remind me to finish before the deadline. A more wonderful reason for using it is its smooth widget.
2.Good Morning<@https://play.google.com/store/apps/details?id=com.flywheelsoft.goodmorning&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5mbHl3aGVlbHNvZnQuZ29vZG1vcm5pbmciXQ..>
This is an alarm. The most powerful feature in it is that it can speak the weather and your calendar right out, when you need an alarm to call you up in the morning. Sometimes, you can set a math problem which only be solved can you be able to shutdown the annoying sound, in which case, you must be awake...
3.Battery Widget Reborn<@https://play.google.com/store/apps/details?id=net.hubalek.android.reborn.beta&feature=search_result#?t=W251bGwsMSwxLDEsIm5ldC5odWJhbGVrLmFuZHJvaWQucmVib3JuLmJldGEiXQ..>
The widget gives a nice notification on your status bar which included the battery remaining percentage. And when you slide down the status bar, you can set the information of your battery to display, such as the temperature and the volt or the time left to run out of charge or to get charged of the battery.
4.Power Toggles<@https://play.google.com/store/apps/details?id=com.painless.pc&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5wYWlubGVzcy5wYyJd>
While I am using the official version of android 4.2.2, so the status bar has no quick power toggles which is very convenient design in CyanogenMod's rom. And this app gives the even TWO lines of the quick toggles displayed in the slided status bar with at most 8 different toggles in each line. A nice additional feature is that it can also display the date or the remaining battery percentage or the version of your android in the status bar.
5.Full Screen Toggle<@Just Google it, since it not supplied in the Google Play>
Do you like the Navigation Bar at the bottom of your phone? For me, I don't. So thanks to this app, I can kill the navigation bar to make the screen look more larger and clean.
6.GN Full Screen Helper<@Just Google it, since it not supplied in the Google Play>
For the feature above, how can you return to previous page or call out the menu of something? Just install this application, and all problem will be thrown out of mind. In this fantastic app, a wonderful animation of the functions that navigation bar has will display when you touch the edge of the side of the screen
7.PGM2<@Just Google it, since it not supplied in the Google Play>
It is a gesture application which can totally free the function of the power button. And it has many other gestures which depends the need of the user herself.

Monday, February 25, 2013

My First Crawler

import urllib2
from pyquery import PyQuery as pq

url = "http://api.jquery.com/category/selectors/"
result = urllib2.urlopen(url).read().decode("utf8")
q = pq(result)
result_of_bookmarks = q('a[rel="bookmark"]')
bookmarks = result_of_bookmarks.map(lambda i, e: pq(e).text())
'''
for item in bookmarks:
    print item.encode('utf8')

'''

result_of_sumaries = q('div[class="entry-summary"]')
sumaries = result_of_sumaries.map(lambda i, e: pq(e).text())
'''
for item in sumaries:
    print item.encode('utf8')
'''
Query = {}
for i in range(len(bookmarks)):
    Query[bookmarks[i]] = sumaries[i]

Sunday, February 24, 2013

Ubuntu Sublime Python Env


1) Change Environment Path
Find the file named "Python.Sublime-build":
{
    "cmd": ["python", "-u", "$file"],
  "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Change the Python path to yours in the Environment like:
{
"cmd": ["/home/hiddenghost/pyenv/bin/python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}

2) Python Project Configuration Example
With the project name --> "*.sublime-project"
{
"folders":
    [
        {
            "path": "/home/hiddenghost/Documents/hiddenghost"
        }
    ],
    "build_systems":
    [
        {
       "name": "Run Tests",
        "env":
        {
        "PYTHONPATH": "/home/hiddenghost/pyenv/bin/python:/home/hiddenghost/pyenv/lib/python2.7/site-packages"
        },
       "working_dir": "/home/hiddenghost/Documents/hiddenghost",
       "cmd": ["/home/hiddenghost/pyenv/bin/python", "$file"],
       "selector": "source.python"
   }
    ]
}