View math.sqrt.bsearch.py
def sqrt_binary(num): | |
if num > 1: | |
low = 1 | |
high = num | |
else : | |
low = num | |
high = 1 | |
mid = float(low) + float((high - low) / 2) | |
while abs(mid ** 2 - num) > 0.000001: | |
if mid ** 2 < num: |
View bitwise.basic.js
// right shift of 0 makes the num unsigned: https://stackoverflow.com/questions/9939760/how-do-i-convert-an-integer-to-binary-in-javascript | |
const numToBinary(num) => (n >>> 0).toString(2); | |
const lowBit = (n) => n & -n; // returns the sub-number which is the last 1 in binary of the original number | |
// low Bit operation is used in "Binary indexed Trees" | |
// https://zh.wikipedia.org/zh-hans/%E6%A0%91%E7%8A%B6%E6%95%B0%E7%BB%84 |
View node-rename-dir-files.js
const fs = require('fs'); | |
function addSchemaName(basePath) { | |
const result = fs.readdirSync(basePath); | |
// console.log(result); | |
result.forEach((path) => { | |
if (path.startsWith('_') || path.endsWith('Schema.js')) { return; } | |
if (path.endsWith('.js')) { | |
const prefix = path.split('.')[0]; |
View jsBasic.bindRight.js
Function.prototype.bindRight = function (context, ...firstArgs) { | |
return (...secArgs) => { | |
return this.apply(null, [...secArgs.reverse(), ...firstArgs.reverse()]); | |
}; | |
}; | |
function add(x, y, z) { | |
return 100 * x + 10 * y + z; | |
} |
View algorithm.backpack.js
function max(a, b) { | |
return (a > b) ? a : b; | |
} | |
function knapsackRecur(capacity, size, value, n) { | |
if (n == 0 || capacity == 0) { | |
return 0; | |
} | |
if (size[n - 1] > capacity) { | |
return knapsack(capacity, size, value, n - 1); |
View jsPatterns.recur.trampoline.html
<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/> |
View algorithm.DS.HashTable.js
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) { |
View algorithm.DS.doubly-linklist.js
function Node(element) { | |
this.element = element; | |
this.next = null; | |
this.previous = null; | |
} | |
function LList() { | |
this.head = new Node("head"); | |
this.find = find; | |
this.insert = insert; |
View algorithm.DS.stack-arr-noPushPop-impl.js
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; |
View str_flipDown.js
(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) { |
NewerOlder