Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / pythagoras-tree.rkt
Last active December 25, 2015 04:47
Draws a Pythagoras tree using Racket's turtle graphics library. Read the article at http://aguo.us/writings/pythagoras-tree.html.
#lang racket
; pythagoras-tree.rkt:
; Draws a Pythagoras tree using Racket's turtle graphics library.
; Run this program from the terminal with `racket pythagoras-tree.rkt`.
(require graphics/turtles) ; raco pkg install htdp-lib
(turtles #t)
(define (pythagoras-tree side) ; starting position: center of square, facing east
@guoguo12
guoguo12 / commonscat.diff
Created November 19, 2013 11:34
Diff for bug report for valhallasw/gerrit-patch-uploader.
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
new file mode 100755
index 0000000..064ba72
--- /dev/null
+++ b/scripts/commonscat.py
@@ -0,0 +1,631 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+With this tool you can add the template {{commonscat}} to categories.
@guoguo12
guoguo12 / remove_sources_tests.py
Created November 22, 2013 03:46
Tests for new method added to Wikimedia's pywikibot/core.
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Simple, crude tests for Claim's removeSources() method.
Tests are run on Wikidata's sandbox.
Allen Guo <Guoguo12@gmail.com>
November 2013
"""