View shallow-vs-deep-copy.py
# no copy | |
a = {1:'a', 2:'b', 3:{4:'c', 5:'d'}} | |
b = a | |
b[1] = 'lol' | |
print(a[1]) | |
b[3][4] = 'haha' | |
print(a[3][4]) | |
# shallow copy | |
c = {1:'a', 2:'b', 3:{4:'c', 5:'d'}} |
View MFCC.py
import random | |
import numpy as np | |
import numpy.linalg as la | |
import matplotlib.pyplot as plt | |
import time | |
import os | |
from math import * | |
from numpy import append, zeros | |
from scipy.io import wavfile |
View Python Variable Scope Examples
a = 1 | |
def foo(): | |
print(a) # Prints 1. Accesses the variable a outside its own scope. | |
foo() | |
print(a) # Prints 1. a not modified. | |
b = 2 | |
def bar(): |
View youtube-vimeo-url-parser.js
function parseVideo (url) { | |
// - Supported YouTube URL formats: | |
// - http://www.youtube.com/watch?v=My2FRPA3Gf8 | |
// - http://youtu.be/My2FRPA3Gf8 | |
// - https://youtube.googleapis.com/v/My2FRPA3Gf8 | |
// - Supported Vimeo URL formats: | |
// - http://vimeo.com/25451551 | |
// - http://player.vimeo.com/video/25451551 | |
// - Also supports relative URLs: | |
// - //player.vimeo.com/video/25451551 |
View nus-timetabledatagenerator.js
var fs = require('fs'); | |
var data = JSON.parse(fs.readFileSync('modules.json')); | |
var lessonTypes = ['DESIGN LECTURE', 'LABORATORY', 'LECTURE', 'PACKAGED LECTURE', | |
'PACKAGED TUTORIAL', 'RECITATION', 'SECTIONAL TEACHING', | |
'SEMINAR-STYLE MODULE CLASS', 'TUTORIAL', 'TUTORIAL TYPE 2', | |
'TUTORIAL TYPE 3']; | |
var weeks = ['EVERY WEEK', 'ODD WEEKS', 'EVEN WEEKS']; | |
var days = ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY']; |
View projection-points-set.py
# Replace section 1.1 of Assignment 3 with the following lines of code | |
# Final result looks something like this: http://imgur.com/nVCFDPh | |
def pts_set_2(): | |
def create_intermediate_points(pt1, pt2, granularity): | |
new_pts = [] | |
vector = np.array([(x[0] - x[1]) for x in zip(pt1, pt2)]) | |
return [(np.array(pt2) + (vector * (float(i)/granularity))) for i in range(1, granularity)] |
View python-sort-stability.py
# We want to sort a list by its second element in descending order. | |
# The example illustrates the difference in the results of different | |
# process of sorting in descending order. | |
# Sort in ascending order, then use list reverse | |
>>> a = [('A', 1), ('C', 5), ('A', 2), ('B', 3), ('B', 5)] | |
>>> a.sort(key=lambda x: x[1]) | |
>>> print(a) | |
[('A', 1), ('A', 2), ('B', 3), ('C', 5), ('B', 5)] | |
>>> a.reverse() |
View scope-example.py
def scope_test(): | |
def do_local(): | |
spam = "local spam" | |
def do_nonlocal(): | |
nonlocal spam | |
spam = "nonlocal spam" | |
def do_global(): | |
global spam | |
spam = "global spam" | |
spam = "test spam" |
View cs1020-grading.sh
#!/bin/bash | |
# Assumes a directory structure of: | |
# dir | |
# |-- skeleton | |
# | |-- testFile.java | |
# | +-- grade.sh (this file) | |
# | | |
# +-- testdata | |
# |-- input |
OlderNewer