Skip to content

Instantly share code, notes, and snippets.

View tennisonchan's full-sized avatar

Tennison Chan tennisonchan

  • Truewind
  • San Francisco
View GitHub Profile
#!/bin/sh
INTERVAL=2
if [ -n $2 ]
then
INTERVAL=$2
fi
while :;
do
@tennisonchan
tennisonchan / dummy.json
Last active November 4, 2017 15:13
@include *://localhost:8000/*;
{
"gists": [
{
"id": "69901fd5fa48cb0d03f5f3bcf48c9f63",
"include": "*://localhost:8000/*",
"files": [
{
"name": "hexo-demo",
"ext": "css",
"url": "https://cdn.rawgit.com/tennisonchan/69901fd5fa48cb0d03f5f3bcf48c9f63/raw/b71ce90920ded75b477513de11baafd0ed6aed6a/hexo-demo.css"
@tennisonchan
tennisonchan / covering_indexes.sql
Created October 8, 2017 09:51
Tests between SQL commands with and without covering indexes
SET SERVEROUTPUT ON
DECLARE
v_ts TIMESTAMP;
v_repeat CONSTANT NUMBER := 100000;
BEGIN
v_ts := SYSTIMESTAMP;
FOR i IN 1..v_repeat LOOP
FOR rec IN (
-- Worst query: Memory overhead AND table access
@tennisonchan
tennisonchan / mySetInterval.js
Last active August 8, 2017 17:30
Implement mySetInterval() and myClearInterval() as functions that behave exactly like setInterval() and clearInterval().
/*
Prompt: Implement mySetInterval() and myClearInterval() as functions that behave exactly like setInterval() and clearInterval(). Obviously, you’re not allowed to use setInterval() in your implementation, but everything else is fair game.
Time: This shouldn’t take too long - please don’t spend more than an hour working on it.
Rules: You may consult MDN for documentation, but you may not use any other resources.
Goals: We’re looking for clean code and quick implementation, so please send in your solution as soon as you finish.
*/
// ### MDN setInterval documentation
#!/usr/bin/env bash
# 'Wi-Fi' or 'Ethernet' or 'Display Ethernet'
INTERFACE=Wi-Fi
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
@tennisonchan
tennisonchan / SAFE_INTEGER.js
Created June 17, 2017 15:03
MAX_SAFE_INTEGER and MIN_SAFE_INTEGER
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
// Following IEEE754 [Double-precision floating-point format](https://en.wikipedia.org/wiki/Double-precision_floating-point_format)
// Not Support in IE
Number.MAX_SAFE_INTEGER // 9007199254740991
Number.MIN_SAFE_INTEGER // -9007199254740991
// Fun fact
Number.MAX_SAFE_INTEGER + 1 == Number.MAX_SAFE_INTEGER + 2 // => true

Keybase proof

I hereby claim:

  • I am tennisonchan on github.
  • I am tennisonchan (https://keybase.io/tennisonchan) on keybase.
  • I have a public key whose fingerprint is 2451 8B43 67F4 F4D6 2ED7 33DB 7C4E 1A7D 7B9F D219

To claim this, I am signing this object:

let randomArray = (len=10, max=100) => [...new Array(len)].map(() => Math.floor(Math.random() * max))
let randomArrayOld = function(len, max) {
return Array.apply(null, Array(len)).map(function() {
return Math.floor(Math.random() * max);
});
}
let normalArray = (len=10) => [...new Array(len)].map((a,i) => i);
@tennisonchan
tennisonchan / binary_of_negative_number.js
Last active June 9, 2017 20:42
Binary of a negative number
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
(-3 >>> 0).toString(2)
// 11111111111111111111111111111101 => -3
(-9 >>> 2).toString(2)
// 00111111111111111111111111111101 => 1073741821
(-9 >> 2).toString(2)
// 11111111111111111111111111111101 => -3
@tennisonchan
tennisonchan / StrangerThingsJS.md
Last active April 4, 2017 21:30
StrangeThingsJS

Scope

Lexical Scope

Hoist