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 / shallow-vs-deep-copy.py
Last active December 28, 2015 08:19
Demonstrating the differences between deep and shallow copy in Python
# no copy
a = {1:'a', 2:'b', 3:{4:'c', 5:'d'}}
b = a
b[1] = 'lol'
print(a[1])
b[3][4] = 'haha'
print(a[3][4])
# shallow copy
c = {1:'a', 2:'b', 3:{4:'c', 5:'d'}}
@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
// "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');
## Directory structure:
## dir
## |-- gen_runes.py
## |-- graphics.py
## |-- PyGif.py
## +-- runes.py
## Put submissions in the same directory as this file.
## Make sure there are no other .py files besides
## the submissions and the whitelisted files
@yangshun
yangshun / Gulpfile.js
Created August 11, 2016 13:00
Static web server with styles watching
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var webserver = require('gulp-webserver');
gulp.task('sass', function () {
return gulp.src('./sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'));
@yangshun
yangshun / media-rename.sh
Created October 2, 2016 07:48
Rename .webm files to .mp4
#/usr/bin/sh
for f in *.webm; do
mv -- "$f" "${f%.webm}.mp4"
done

What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would

// Name animater
var name = 'Yang.Shun.Tay.';
setInterval(function () {
name = name.substring(1) + name.charAt(0);
var flags = (1 << 0) | (1 << 1);
MtpApiManager.invokeApi('account.updateProfile', {
flags: flags,
first_name: name,
last_name: ''
@yangshun
yangshun / checlist.md
Created February 22, 2017 16:57 — forked from xdite/checlist.md

Security is Hard

Massive Assignment

  • watch for ActiveRecord Relation, like has_many, has_many :through
  • watch for user_roles, `group_users
  • UPDATE action

Admin