Skip to content

Instantly share code, notes, and snippets.

View Williammer's full-sized avatar

William He Williammer

View GitHub Profile
@Williammer
Williammer / algorithm.1.bubblesort.js
Last active June 25, 2016 03:16
sort algorithms: bubbleSort: bubble swap each adjacent item pair one step for each loop -> until length N-1 loop for worst case. ||| selectionSort: find min item from first pos to the last. 外层为pos遍历,内层遍历pos后的元素,找到最小的与pos当前元素交换。||| insertSort: 最外层n遍历,内层与之前所有元素比较,并和较大的交换。 ||| shellSort: A better way of insertSort, 最外层遍历所有gaps,次外层以gap遍历数组并比较交换各组元素。…
function bubblesort() {
var numElements = this.dataStore.length;
var temp;
for (var outer = numElements; outer >= 2; --outer) {
for (var inner = 0; inner <= outer - 1; ++inner) {
if (this.dataStore[inner] > this.dataStore[inner + 1]) {
temp = this.dataStore[inner];
this.dataStore[inner] = this.dataStore[inner + 1];
this.dataStore[inner + 1] = temp;
}
@Williammer
Williammer / algorithm.DS.Graphs.DeepFirstSearch.js
Last active June 5, 2016 04:57
Graphic related algorithm
function cat() {
var head = _.first(arguments);
if (existy(head))
return head.concat.apply(head, _.rest(arguments));
else
return [];
}
function construct(head, tail) {
return cat([head], _.toArray(tail));
@Williammer
Williammer / jsPatterns.recur.trampoline.html
Last active May 31, 2016 15:37
jsPatterns.recur.trampoline.js
<h1 class="index_title">
About Me
</h1>
<br/>
<p class="selfy">
Hi there, my name is William He or Weinan He in Chinese. I'm currently living in Hong Kong and working at <a target="_blank" href="https://www.accedo.tv/">Accedo</a> as the Software Developer.
<br/>
<br/> My current job is to develop cool Web TV applications, which is one type of web application, with the amazing javaScript. I love to explore and learn more about the web technology world and develop some useful applications in my spare time!
<br/>
@Williammer
Williammer / algorithm.DS.HashTable.js
Last active May 22, 2016 13:53
HashTable in js, with simple Hash and the better Horner's hash method.
function HashTable() {
this.table = new Array(137);
this.simpleHash = simpleHash;
this.betterHash = betterHash;
this.showDistro = showDistro;
this.put = put;
this.get = get;
}
/*function put(data) {
@Williammer
Williammer / algorithm.DS.doubly-linklist.js
Last active May 15, 2016 14:31
LinkList implementations.
@Williammer
Williammer / algorithm.DS.stack-arr-noPushPop-impl.js
Last active May 15, 2016 06:16
Stack data structure in javaScript.
function Stack() {
// this._size = 0;
// this._storage = {};
this._storage = []; // array could be more performant due to array browser optimize
}
Stack.prototype.push = function (data) {
// var size = ++this._size;
var len = this._storage.length;
this._storage[len] = data;
@Williammer
Williammer / reduce-reorganize-entry.js
Last active May 9, 2016 15:47
Functional programming - reduce [iterate, mutate inside and outside] - sample cases
var fs = require('fs')
var out = fs.readFileSync('src.txt', 'utf8')
.trim().split('\n')
.reduce(function (acc, cur) {
var curArr = cur.split(' ');
if (typeof acc[curArr[0]] !== 'object') {
acc[curArr[0]] = [];
}
@Williammer
Williammer / str_flipDown.js
Last active May 9, 2016 15:42
Flip the strings down.
(function () {
function flip() {
var result = flipString(document.f.original.value.toLowerCase());
document.f.flipped.value = result;
}
function flipString(aString) {
var last = aString.length - 1;
var result = new Array(aString.length)
for (var i = last; i >= 0; --i) {
@Williammer
Williammer / silicon-valley-tricky.c
Last active April 29, 2016 16:46
silicon-valley-tricky.c
#include <stdio.h>
#include <stdlib.h>
typedef unsigned long u64;
/* Start here */
typedef void enc_cfg_t;
typedef int enc_cfg2_t;
typedef __int128_t dcf_t;