Skip to content

Instantly share code, notes, and snippets.

View csyo's full-sized avatar

Shawn Chen csyo

  • Taipei, Taiwan
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
* {
box-sizing: border-box;
}
@csyo
csyo / getObjProp.js
Created August 10, 2017 04:33
Access object property without error
const getProp = (path, target) => {
try {
const paths = path.split('.');
const isProp = paths[1] in target;
if (paths.length === 2) {
return isProp ? target[paths[1]] : undefined;
}
return isProp ? getProp(paths.slice(1).join('.'), target[paths[1]]) : undefined;
} catch (error) {
return undefined;
@csyo
csyo / ydkjs-- async.md
Last active January 28, 2017 05:39
[Notes] YDKJS - ASYNC

Promises

  • Goal

Uninvert the inversion of control → instead of handling the continuation of out program to anther party, we could expect it to return us a capability to know when its task finishes, and decide what our code to do next.

What is a Promise

  1. Future Value
@csyo
csyo / workflowy_inline_img.js
Last active November 17, 2016 13:36
Workflowy.com Notes with Image Inline (snippet from https://blog.workflowy.com/2016/01/06/inline-images/)
function do_parseImg () {
if ($(this).nextAll('.content-img').length > 0) { return }
var url = $(this).text().split('\n').reduce(e => e.trim().match(/^\!\[.*\]\((.+)\)$/));
url && $(this).after('<div class="content-img"><img style="width:85%" src="' + url[1] + '"/></div>');
}
function parseImg () {
$('div.notes div.content').focusin(function () {
$(this).nextAll('.content-img').remove();
});