Skip to content

Instantly share code, notes, and snippets.

View yangshun's full-sized avatar
😎
Ruining websites since 2013

Yangshun Tay yangshun

😎
Ruining websites since 2013
View GitHub Profile
@yangshun
yangshun / DailyJS Tags Sorter
Created February 24, 2014 06:56
This snippet of code can be used to sort the posts within each tag category on the DailyJS site: http://dailyjs.com/tags.html
(function() {
$('.posts').each(function() {
var $postsInCat = $(this).children();
var $sortedCat = $postsInCat.sort(function(a, b) {
var dateA = new Date($(a).children('div').html());
var dateB = new Date($(b).children('div').html());
return dateA < dateB ? 1 : -1;
});
$(this).html('').html($sortedCat);
});
@yangshun
yangshun / Python Variable Scope Examples
Last active August 29, 2015 13:57
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():
@yangshun
yangshun / nus-timetabledatagenerator.js
Created June 30, 2014 04:44
Creating nus_timetable_data.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'];
@yangshun
yangshun / scope-example.py
Created November 26, 2014 03:51
Demonstrate local, nonlocal, and global scope of variables
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"
@yangshun
yangshun / cs1020-grading.sh
Last active August 29, 2015 14:13
CS1020 Codes Autograder
#!/bin/bash
# Assumes a directory structure of:
# dir
# |-- skeleton
# | |-- testFile.java
# | +-- grade.sh (this file)
# |
# +-- testdata
# |-- input
Blackbox testing:
Test background loads ok and is scrollable
Still scrollable with game objects.
Test implementation of buttons
Save, load
Save/load empty screen
Save/load one object (try different types)
Save/load one object of each type
Save/load with many objects
// Hack for Kolor Game
// 1. Play the game at http://kolor.moro.es
// 2. Before clicking on "Start!", open up the JavaScript console and paste the following snippet of code.
// 3. WIN.
// Change the value for INTERVAL to have a faster refresh rate.
// Set AUTOPLAY to true to let the game play on its own, you lazy bum.
(function () {
/*!
jQuery.touchScrollBuster v0.0.1
Tay Yang Shun https://github.com/yangshun
The MIT License (MIT)
Copyright (c) 2015
$(el).touchScrollBuster() will prevent parent containers from scrolling
when the child container is at the top or at the bottom.
*/
@yangshun
yangshun / .eslintrc
Created October 22, 2015 03:44
An eslint configuration that I adhere to
{
"parser": "babel-eslint",
"ecmaFeatures": {
"jsx": true,
"arrowFunctions": true,
"blockBindings": true,
"generators": true
},
"rules": {
"accessor-pairs": 0,
@yangshun
yangshun / Enhance.js
Created November 1, 2015 13:49 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {