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 / 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';
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 / 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(','));
}
@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() {
// "body-parser": "^1.4.3",
// "express": "^4.4.5",
// "request": "^2.67.0"
var fs = require('fs');
var path = require('path');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var http = require('http');
@yangshun
yangshun / country-code.js
Created December 29, 2015 05:49
Country Code Scraper
// From http://www.science.co.il/International/Country-codes.asp
var data = {};
var trs = document.querySelectorAll('table.sortable tbody tr');
for (var i = 0; i < trs.length; i++) {
var item = trs[i];
var tds = item.querySelectorAll('td');
data[tds[2].textContent] = {
name: tds[0].textContent,
@yangshun
yangshun / fix-wordpress-permissions.sh
Created January 21, 2016 16:41 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory