Skip to content

Instantly share code, notes, and snippets.

View jaychsu's full-sized avatar

Jyun Hong Su jaychsu

View GitHub Profile
@jaychsu
jaychsu / demo.zsh
Last active March 19, 2020 13:51
Pass parameters in zsh
# https://stackoverflow.com/questions/42655304/how-do-i-check-if-a-variable-is-set-in-zsh
test() {
test2 $@
test3 $@
}
test2() {
if [[ $# -eq 0 ]]; then
echo 'no params'
@jaychsu
jaychsu / entry.json
Last active February 11, 2020 08:32
{
"swagger": "2.0",
"info": {
"description": "Entry Task",
"version": "2.4.12",
"title": "Swagger Generator",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "Jaych Su"
},
@jaychsu
jaychsu / dom-loaded-test.html
Created December 15, 2019 15:20 — forked from passcod/dom-loaded-test.html
onload, readyState, and DOMContentLoaded
<!DOCTYPE html>
<html>
<head>
<script>
window.onload = function () {
console.log(''+(+new Date)+': Onload fired');
};
document.onreadystatechange = function () {
console.log(''+(+new Date)+': Ready state changed');
@jaychsu
jaychsu / native jQuery methods.js
Created September 9, 2019 17:34 — forked from jochemstoel/native jQuery methods.js
Vanilla implementations of commonly used jQuery methods.
/**
* Convenient shortcut
*/
Object.defineProperty(window, 'define', {
value: (property, ...meta) => meta.length == 2 ? Object.defineProperty(meta[0], property, meta[1]) : Object.defineProperty(window, property, meta[0]),
writable: false,
enumerable: true
})
@jaychsu
jaychsu / weak-map.js
Created April 16, 2019 01:51 — forked from Gozala/weak-map.js
Harmony WeakMap shim for ES5
/* vim:set ts=2 sw=2 sts=2 expandtab */
/*jshint asi: true undef: true es5: true node: true devel: true
forin: false latedef: false */
/*global define: true */
if (typeof(WeakMap) === 'undefined') WeakMap = (function(global) {
"use strict";
function defineNamespace(object, namespace) {
@jaychsu
jaychsu / System Design.md
Created November 9, 2017 04:17 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@jaychsu
jaychsu / latency.txt
Created October 17, 2017 22:19 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@jaychsu
jaychsu / color.less
Last active July 17, 2017 17:52
generate colorful class in `LESS` by given color set
@color-class-prefix: chosen-color-;
@color-list:
#ffc4c6,
#fdeddf,
#fff6c3,
#cdffbe,
#bdf7ef,
#cce7fb,
#dacefc,
#fbc9f1,
@jaychsu
jaychsu / command-with-short-and-long-param.sh
Last active October 25, 2017 07:59
Collections to show how create shell command
#!/bin/bash
start() {
echo "Starting vnc server with $resolution on Display $display"
#your execute command here mine is below
#vncserver :$display -geometry $resolution
}
stop() {
echo "Killing vncserver on display $display"
#vncserver -kill :$display
@jaychsu
jaychsu / uri.js
Created May 8, 2017 05:04 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"