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 / 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() {
@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 / arrayToCSV.js
Last active January 18, 2021 15:22
Converts a 2D array into a CSV file
function arrayToCSV (twoDiArray) {
// Modified from: http://stackoverflow.com/questions/17836273/
// export-javascript-data-to-csv-file-without-server-interaction
var csvRows = [];
for (var i = 0; i < twoDiArray.length; ++i) {
for (var j = 0; j < twoDiArray[i].length; ++j) {
twoDiArray[i][j] = '\"' + twoDiArray[i][j] + '\"'; // Handle elements that contain commas
}
csvRows.push(twoDiArray[i].join(','));
}
/*!
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.
*/
// 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 () {
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
@yangshun
yangshun / coursera-answers.js
Last active April 6, 2018 12:59
For sharing your Coursera quiz answers with your friends
// Steps to share Coursera Quiz answers
// =====
// 1. Open the web developer console. In Chrome, press ctrl/cmd + shift + J, in Firefox, press ctrl/cmd + shift + K
// 2. Copy the following code below and paste it in the console. Press enter.
// 3. Your answers will be printed out and you can share it with other people (:
//
(function () {
var answer = '\n';
@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
@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 / python-sort-stability.py
Last active July 11, 2023 22:33
Sort then reverse vs Sort(reverse=True)
# 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()