Skip to content

Instantly share code, notes, and snippets.

View tomchen's full-sized avatar
🐑
🐑🐑🐏🐑🐑🐑

Tom Chen tomchen

🐑
🐑🐑🐏🐑🐑🐑
View GitHub Profile
@tomchen
tomchen / umd-template.js
Created May 18, 2021 18:04
UMD Template
(function (root, factory) {
if (typeof define === "function" && define.amd) {
// AMD
define([], factory);
} else if (typeof module === "object" && module.exports) {
// Node
module.exports = factory();
} else {
// Browsers
root.logdf5e4y = factory();
@tomchen
tomchen / promise_play.js
Created January 19, 2021 15:47
Play with Promise
const makeQueryablePromise = (promise) => {
if (promise.isFulfilled) {
return promise
}
let isPending = true
let isRejected = false
let isFulfilled = false
const result = promise.then(
@tomchen
tomchen / c_data_types.md
Created January 4, 2021 15:17
C Data Types

C Data Types

Type Explanation Minimum size (bytes) Minimum range Format specifier
char Smallest addressable unit of the mach
@tomchen
tomchen / map_object_array_perf_comp.js
Last active January 3, 2021 00:38
JavaScript /Node.js `Map`, `Object`, `Array`'s `set`, `has`, `get`, `delete` methods performance / speed comparison
/*
Below is the result for the method 'set' of Map/Object/Array, when both keys and values are from 0 to 9999.
Method 'set' of Map x 3,983 ops/sec ±0.21% (94 runs sampled)
Method 'set' of Object x 6,265 ops/sec ±0.31% (96 runs sampled)
Method 'set' of Array x 35,736 ops/sec ±0.37% (93 runs sampled)
Fastest is Method 'set' of Array
Below is the result for the method 'has' (or similar) of Map/Object/Array, when both keys and values are from 0 to 9999.
Method 'has' of Map x 6,244 ops/sec ±1.33% (94 runs sampled)
Method 'in' of Object x 63,996 ops/sec ±0.27% (95 runs sampled)
@tomchen
tomchen / keybase.md
Created June 30, 2020 22:37
Keybase proof

Keybase proof

I hereby claim:

  • I am tomchen on github.
  • I am tomchenorg (https://keybase.io/tomchenorg) on keybase.
  • I have a public key whose fingerprint is C258 C4AF ECBC 1C27 A1F4 6CD5 3E37 9127 BF71 FD68

To claim this, I am signing this object:

@tomchen
tomchen / ES6_class_vs_ES5_function.js
Last active April 8, 2020 22:55
ES6 class vs ES5 constructor function
//ES6 class vs ES5 constructor function
// ES6 class
class MyClass {
// is executed upon instantiation, not to be used as a normal method
// proposal class properties
// https://babeljs.io/docs/en/babel-plugin-proposal-class-properties
// https://github.com/tc39/proposal-class-fields