Skip to content

Instantly share code, notes, and snippets.

@nalsi
nalsi / foaf.rdf
Created December 9, 2012 16:58
## My FOAF file
## Creator: Kai Li
## Time: 12/9/2012
## Description: My FOAF file
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rrdf="http://rdfs.org/resume-rdf/"
@nalsi
nalsi / MMooc1.py
Created November 26, 2012 19:50
Multiple tasks for Lesson 1 of Mechanical Mooc
# Kai Li <--- My name
# hello_world.py <--- Name of the file
# 10/15/2012 <--- Date
# Print the pattern to the screen.
a = " | | "
b = "--------"
print a
print b
print a
@nalsi
nalsi / hello_world.py
Created November 26, 2012 19:48
Print "Hello, world!" to the screen
# This is Kai Li's first script for Mechanical MOOC lesson.
# Kai Li <--- My name
# hello_world.py <--- Name of the file
# 10/15/2012 <--- Date
# print "Hello, world!" to the screen
x = 'Hello, world!'
print x
@nalsi
nalsi / matrix_print.py
Created November 26, 2012 19:45
Print a matrix of numbers from 1*1 to 7*7
## Creator: Kai Li
## Time: 10/18/2012
## Task: Print a matrix of numbers from 1*1 to 7*7.
## Warning: It's not functioning properly, in that after everyline, there is an unexpected "None".
def nal(n):
i = 1
while i <= 7:
print n*i, '\t',
i = i + 1
@nalsi
nalsi / ospath_walk.py
Created November 26, 2012 19:32
Trace all the folders and the number of files in these folders in a given URL
## Creator: Kai Li
## time: 11/26/2012
## Task: Trace all the folders and the number of files in these folders in a given URL.
import os.path as os
def myvisit(a, dir, files):
print dir, ": %d files" % len(files)
os.walk('c:/python27', myvisit, None)
@nalsi
nalsi / property.py
Created November 26, 2012 19:27
Getting properties of all the files in a given folder
## Creator: Kai Li
## Time: 11/26/2012
## Task: Getting properties of all the files in a given folder.
import os
import os.path
import time
for f in os.listdir("c:\python27"):
print "File :", os.path.basename(f)
@nalsi
nalsi / gist:4150093
Created November 26, 2012 19:26
Fetching Wikipedia article using Python's "urllib2" module
## Creator: Kai Li
## Time: 11/26/2012
## Task: Fetching Wikipedia article using Python's "urllib2" module
import urllib2
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
req = opener.open("http://en.wikipedia.org/wiki/Betelgeuse")