This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
look-and-say-sequence by Jaeho Lee, | |
public domain | |
1 => [[1, 1]] | |
11 => [[1, 2]] | |
21 => [[2, 1], [1, 1]] | |
1211 | |
111221 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES5 lte | |
try { | |
var a = { | |
c:1, b: (function b() { return this.c }).bind(a) | |
}; | |
} catch(e) { console.warn(e); } | |
// ES2015 | |
try { | |
let a = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function can be impure in JS context... | |
function sum(arr) { | |
var z = 0; | |
for (var i=0;i<arr.length;i++) { | |
z += arr[i]; | |
} | |
return z; | |
} | |
// sec 1: valueOf() impureness |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ReactDOM from 'react'; | |
// render without using JSX | |
export function jsRender(Component, data={}, targetElement, callback=null) { | |
ReactDOM.render(<Component {...data} />, targetElement, callback) | |
} | |
// Render after specific element. | |
export function wrappedRenderCreator( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pp(givenNth/*: int*/, curNth = 0/*: int*/, dir = 1 /* { 1 | -1 } */, result = 0/*: int*/) { | |
// console.log(arguments[1], arguments[2], arguments[3]); | |
'use strict'; | |
if (givenNth === curNth) { | |
return result; | |
} else { | |
return pp(givenNth, curNth + 1, isTurnAround(curNth + 1) * dir, result + dir); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// % | |
function mod(num, by) { | |
var tmp_num = num; | |
while (tmp_num - by >= 0) { | |
tmp_num -= by | |
} | |
return tmp_num; | |
} | |
function fizzbuzzMod (limit) { |