Skip to content

Instantly share code, notes, and snippets.

View sairion's full-sized avatar
⚛️

Jaeho Lee (Jay) sairion

⚛️
View GitHub Profile
@sairion
sairion / bitwise-hacks.js
Created February 28, 2017 07:42 — forked from leodutra/bitwise-hacks.js
Fast Int Math + Bitwise Hacks For JavaScript
// http://michalbe.blogspot.com.br/2013/03/javascript-less-known-parts-bitwise.html
// http://jsperf.com/bitwise-vs-math-object
// http://united-coders.com/christian-harms/results-for-game-for-forfeits-and-the-winner-is/
// https://mudcu.be/journal/2011/11/bitwise-gems-and-other-optimizations/
// https://dreaminginjavascript.wordpress.com/2009/02/09/bitwise-byte-foolish/
// http://jsperf.com/math-min-max-vs-ternary-vs-if/24
"use strict";
var PI = Math.PI;
  1. You can override constructor output by returning object type.
class A {
  constructor(){
    return new Number(0)
  }
}
console.log(new A == 0) // => true
function benchDedupe(inputSize = 10000000) {
var fixtureNumbers = Array.from({ length: inputSize }).map(() => (Math.random() * 10) | 0)
var fixtureStrings = fixtureNumbers.map(e => String(e))
var fixtureObjects = (function(){
var res = [];
for (var i = 0, rando; i < inputSize; i++) {
rando = (Math.random() * 6) | 0
switch(rando) {
case 0: res[i] = new Object(); break;
case 1: res[i] = res[(Math.random() * res.length) | 0]; break;

대학시절 ux를 공부하던 때, '모든 곳에 ui와 ux가 필요하다' 라는 생각으로 ui 디자인은 매우 중요한 일이 될 거라고 생각했었다. 정말 누구에게도 안 부끄러울 정도로 열심히 공부하기도 했고, 시중에 있는 책도 거의 다 읽어봤고. 그런데 지금 생각해보니 너무 기본적인 것부터 생각을 잘못했다는 걸 느낀다.

모든 곳에 ui와 ux가 필요할지는 모르지만 그것을 디자이너가 손으로 디자인해야 하는 일은 잘 없다. 모든 사람들이 옷을 입는다고 모든곳에 테일러가 필요하지 않은 것처럼. 복잡도가 높은 컨텐츠의 예산은 엄청나게 올라가기 때문에 사람들은 컨텐츠의 복잡도를 줄이는 전략을 택하지, 디자이너를 고용해서까지 컨텐츠 자체를 유지하려고 하지는 않는다. (디자이너들에 대한 비난처럼 될 지도 모르겠지만, 디자이너가 사실 할 수 있는 건 잘 정돈하는 것 정도다. 당연하게도 이것은 도움이 되지 않는다. 최고의 정리는 버리는 것이라고도 하지 않았나.)

결국 몇년이 지나, 수많은 웹사이트들은 인스타그램 계정과 페이스북 페이지가 되어버렸다. 나만해도 그게 더 편하다. 웹사이트들은 어렵게 물어물어 찾아가야 하니까. 웹사이트는 이제 정말 아무 것도 아닌 시대다. 불편하기로 치면 책이나 dvd를 보는 것보다 불편하다. 고밀도의 정보를 포함한 종류의 웹사이트가 아니라, 무언가에 대한 전시나 디스플레이를 위한 데스크탑향의 웹사이트라면 이게 존재해야 할 이유가 없다고 생각한다.

옛날에는 정말 병적일 정도로 열심히 마음에 드는 웹사이트들을 정리하고 북마킹하고 심지어 엑셀로 시트를 만들어서 분류까지 해 놨었다. 손을 떨면서 다 지워버렸는데, 아쉬움이 없다. 사실 그 중 1/4정도의 사이트들은 접속도 안되고, 호스트네임이 남아있으면 다행인 수준이었다. 나는 웹 개발자이고 웹이 가장 편하기에 거의 데스크탑 웹만 이용하는 사람이지만, 하여간 여러가지로 허무함을 느끼게 되는 순간이었다.

{// scoped
class A {
a () { return 1 }
}
// wraps existing function
function baseWrapApplier(theConstructor, appliyingKey, descriptor) {
if (theConstructor.prototype[appliyingKey]) {
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import Composer from 'react-native-message-composer';
import {
AppRegistry,
@sairion
sairion / look-and-say.js
Created October 20, 2016 05:18
Look and say sequence - JavaScript version
/*
look-and-say-sequence by Jaeho Lee,
public domain
1 => [[1, 1]]
11 => [[1, 2]]
21 => [[2, 1], [1, 1]]
1211
111221
*/
// Promise exception handling is actually handled by mulitple level - therfore you need to care about many things
new Promise((res, rej) => {
setTimeout(_ => {
// case 1) error outside of promise context
res('booom 2');
throw new Error('error 2'); // this won't get ignored like case 1 and have to be catched manually. Also this don't automatically goes to `onRejected` handler unlike case 1.
}, 3000);
// case 2)
// res('booom 1');
// throw new Error('error 1'); // This gets ignored because it is thrown after resolve function gets called.
function rgb2hsl(r, g, b){
r = r/255, g = g/255, b = b/255;
var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, v = max;
var d = max - min;
s = max == 0 ? 0 : d / max;
if(max == min){
h = 0; // achromatic
@sairion
sairion / non-hoisting-behavior-of-let.js
Created August 30, 2016 12:46
non-hoisting-behavior-of-let.js
// ES5 lte
try {
var a = {
c:1, b: (function b() { return this.c }).bind(a)
};
} catch(e) { console.warn(e); }
// ES2015
try {
let a = {