Skip to content

Instantly share code, notes, and snippets.

View w1shen's full-sized avatar

Walter Shen w1shen

  • LinkedIn
  • San Francisco
View GitHub Profile
@w1shen
w1shen / parasitic-combination-inheritance.js
Last active November 29, 2017 01:40
Parasitic Combination Inheritance
function obj(o) {
function F() {}
F.prototype = o;
return new F();
}
function inheritPrototype(sub, sup) {
var p = obj(sup.prototype);
p.constructor = sub;
sub.prototype = p;
@w1shen
w1shen / requirejs-backbone.js
Last active December 14, 2015 18:09
Using non-AMD compatible javascript module with the shim config of require.js.
requirejs.config({
paths: {
"underscore": "http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min",
"jquery": "http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min",
"backbone": "http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.10/backbone-min"
},
shim: {
// Using non-AMD compatible javascript module with the shim config of require.js.
"underscore": {
exports: "_"
@w1shen
w1shen / apply-syntaxhighlighter-dynamic-brush1.html
Last active December 14, 2015 18:19
Include the following code in front of the end head tag of your template file.
<!-- Syntax Highlighter Additions START -->
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<!-- Remove Vertical Scrollbar -->
<style type='text/css'>
.syntaxhighlighter {
overflow-y: hidden !important;
overflow-x: auto !important;
}
</style>
@w1shen
w1shen / apply-syntaxhighlighter-dynamic-brush2.html
Last active December 14, 2015 18:19
Include the following code in front of the end html tag of your template file.
<!-- Syntax Highlighter Additions START -->
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shAutoloader.js' type='text/javascript'/>
<script language='javascript' type='text/javascript'>
//<![CDATA[
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.config.bloggerMode = true;
function alexgorbatchev() {
var args = arguments;
@w1shen
w1shen / learn-async.js
Last active December 16, 2015 07:49
learn async.js
var assert = require("assert");
var async = require("async");
var fs = require("fs");
var files = ["node_modules/async/LICENSE", "node_modules/async/package.json"];
async.map(files, fs.stat, function(err, results) {
console.log("map: " + JSON.stringify(results));
});
@w1shen
w1shen / AtomicTest.java
Created April 17, 2013 05:45
atomic write: 25377ms, synchronized write: 56757ms, atomic read: 639ms, synchronized read: 56181ms, volatile read: 43ms, normal read: 640ms,
package pig.pigtest;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.Test;
public class AtomicTest {
private AtomicLong v1 = new AtomicLong(0);
private long v2 = 0;
public class ConcurrentStack<E> {
AtomicReference<Node<E>> head = new AtomicReference<Node<E>>();
public void push(E item) {
Node<E> newHead = new Node<E>(item);
Node<E> oldHead;
do {
oldHead = head.get();
newHead.next = oldHead;
<!doctype html>
<html>
<head>
<title>The HTML5 Outline</title>
<meta charset="utf-8">
</head>
<body>
<h1>I WANT YOU!</h1>
<div>
<h2>Backend Engineer</h2>
<!doctype html>
<html>
<head>
<title>The HTML5 Outline</title>
<meta charset="utf-8">
</head>
<body>
<h1>I WANT YOU!</h1>
<div>
<h2>Backend Engineer</h2>
<!doctype html>
<html>
<head>
<title>The HTML5 Outline</title>
<meta charset="utf-8">
</head>
<body>
<h1>I WANT YOU!</h1>
<article>
<h2>Backend Engineer</h2>