Skip to content

Instantly share code, notes, and snippets.

@guoguo12
guoguo12 / calculator.py
Last active August 29, 2015 14:18
Simple calculator for expressions containing positive integers, addition, subtraction, and parentheses.
def evaluateNext(tokens):
first = tokens.pop(0)
if first == '(':
inner = []
depth = 0
while not (tokens[0] == ')' and depth == 0):
if tokens[0] == '(':
depth += 1
if tokens[0] == ')':
depth -= 1
@guoguo12
guoguo12 / test_all.py
Created January 25, 2015 01:23
Python one-liner for compiling and executing all Java unit tests named "Test[Something].java" in the current directory.
import os
[os.system('javac ' + n[2:] + '; java ' + n[2:].strip('.java')) for n in os.popen('find -name "Test*.java"').read().split('\n') if n]
@guoguo12
guoguo12 / flappy_bird.js
Last active August 29, 2015 14:12
Simple Flappy Bird clone written using Khan Academy's programming platform. Live demo: https://www.khanacademy.org/computer-programming/new-program/5450142823219200.
// Simple Flappy Bird Clone
// Allen Guo <allenguo@berkeley.edu>
var SPAWN_INTERVAL = 15;
var GRAVITY = 1; // Accelerate toward bottom
var RECT_WIDTH = 50;
var RECT_VELOCITY = 10;
var PLAYER_X = 360;
@guoguo12
guoguo12 / todo.html
Last active August 20, 2023 10:58
Simple to-do list app made using AngularJS.
<!doctype html>
<html ng-app="toDoApp" ng-controller="toDoController">
<head>
<title>Tasks App</title>
<script src="angular.js"></script>
<style>
body {
color: #444;
font-size: 14px;
font-family: "Roboto", sans-serif;
@guoguo12
guoguo12 / friends.html
Last active August 29, 2015 14:09
AngularJS demo.
<!doctype html>
<html ng-app="friendsApp" ng-controller="friendsController">
<head>
<title>Friends</title>
<script src="angular.js"></script>
<style>
body {
color: #444;
font-size: 14px;
font-family: "Roboto", sans-serif;
@guoguo12
guoguo12 / handshakes.py
Created November 10, 2014 06:12
Simulation of Homework 10, Problem 5, Part d. For CS 70 at UC Berkeley (Fall 2014).
import itertools, random
class Person:
def __init__(self, righthanded):
self.righthanded = righthanded
self.shakes = []
def shake(self, partner):
if self.righthanded and partner.righthanded:
@guoguo12
guoguo12 / handshakes.txt
Created November 10, 2014 05:57
Output for simulation of Homework 10, Problem 5, Part d. For CS 70 at UC Berkeley (Fall 2014).
Running 20 trials
-----------------------------------------------------------------
Starting trial 0
20 right-handed people
19 left-handed people
Result: 0.745341614907
Expected: 0.736842105263
Percent error: 1.15350488021
-----------------------------------------------------------------
Starting trial 1
@guoguo12
guoguo12 / output.json
Created July 6, 2014 12:55
Output from script to find potential variations in HTML output from Billboard's servers.
{
"cache-control": "public, s-maxage=86400, max-age=300",
"content-encoding": "gzip",
"content-language": "en",
"content-length": "26452",
"content-type": "text/html; charset=utf-8",
"date": "Sun, 06 Jul 2014 12:52:17 GMT",
"etag": "\"1404615811-0+gzip\"",
"expires": "Sun, 19 Nov 1978 05:00:00 GMT",
"last-modified": "Sun, 06 Jul 2014 03:03:31 +0000",
@guoguo12
guoguo12 / edline_login.py
Created January 25, 2014 08:35
Demonstrates how to use Requests (http://docs.python-requests.org/en/latest/) to login to Edline (http://www.edline.net/).
import requests
HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36'}
LOGIN_URL = 'https://www.edline.net/InterstitialLogin.page'
LOGIN_POST_URL = 'https://www.edline.net/post/InterstitialLogin.page'
class Edline(object):
@guoguo12
guoguo12 / property_proposals_stats.py
Last active January 1, 2016 19:59
Python script for gathering data type statistics for proposed Wikidata properties. Requires manual input to clarify non-standard data types. Prints final data in CSV format to stdout, along with a list of the clarifications used. Note: this script is now being hosted at https://github.com/JohnFLewis/Wikidata/. This page will no longer receive up…
#!/usr/bin/env python
"""
property_proposals_stats.py: Tabulates and exports statistics for proposed Wikidata properties.
Dependencies:
* Python (2.x)
* Requests (http://docs.python-requests.org/en/latest/)
Instructions: