Skip to content

Instantly share code, notes, and snippets.

View max8hine's full-sized avatar
🎯
Focusing

Max Ma max8hine

🎯
Focusing
View GitHub Profile
@max8hine
max8hine / nested_promise.js
Created September 6, 2018 11:46
nested promise with promise.all
const promise = num => new Promise((resolve) => {
setTimeout(() => { resolve(num) }, 500)
})
var arr1 = [1,2,3,4,5].map(x => promise(x))
arr1
var arr2 = [6,7,8,9,0].map(x => promise(x))
arr2
const resolvePromise = async function () {
let a = await Promise.all(arr1)
@max8hine
max8hine / work_with_git.md
Last active July 18, 2019 05:44
Working with Git

Work with git

git pull from master into the development branch

git checkout dmgr2      # gets you "on branch dmgr2"
git fetch origin        # gets you up to date with origin
git merge origin/master

read more

@max8hine
max8hine / long_road_to_async_func.js
Created June 23, 2018 00:22
The Long Road to Async/Await in JavaScript
/**
* https://www.youtube.com/watch?v=IZIcWl-jq_0
* The Long Road to Async/Await in JavaScript
*/
/* Synchronous Code (Single Stack) */
let result = sendMessage('001', 'yo')
console.log(result)
// Method 1
planList()
.then((planRes) => {
return planRes.data.plan
// locals.addOnUrlList = planRes.data.plan.map(obj => _.pick(obj, 'add_ons').add_ons.href)
// done()
})
.then((planListRes) => {
locals.planList = planListRes
const promises = planListRes.map(item => planAddonList(item.add_ons.href.split('/v2/')[1]))
@max8hine
max8hine / jQuery
Created May 23, 2018 21:50
DOM Manipulating
// Reconfigure font size based on window size
$(window).on('resize init', function (event) {
if ($(this).width() < 600) {
recurly.configure({
style: {
all: {
fontSize: '0.9rem',
},
},
})
@max8hine
max8hine / async+await.js
Last active April 25, 2018 06:17
the evolution of async function in JS
// kick off both thing, one after another
/**
* Promise
*/
const coffeePromise = makeCoffee()
const breakfastPromise = makeBreakfast()
// then once each are done, deal with them
coffeePromise.then(coffee => {
drinkCoffee()
// https://philipwalton.com/articles/the-dark-side-of-polyfilling-css/
@max8hine
max8hine / views_in_keystone.md
Created April 6, 2018 05:24 — forked from wuhaixing/views_in_keystone.md
How to Construct Yourself UI in KeystoneJS

#How to Construct Yourself UI in KeystoneJS

KeystoneJS provide Admin UI with one set of route controllers and view templates(list&item) for all of the models.But usually,you will need some custome views other than Admin UI to display models. Although the KeystoneJS documention don't tell us much about how to contruct custome view,we can learn this from the source code in skeleton project generated by yo keystone,or you can just check out the keystone demo project's source code.We will walk through the blog feature's implementation in this demo application to demonstrate how to construct custome UI in KeystoneJS application.

As KeystoneJS documention described in Routes & Views section,there is a routes/index.js file, where we bind application's URL patterns to the controllers that load and process data, and render the appropriate template.You can find following code in it:

app.get('/blog/:catego

// fron join.js
{ navLinks: [ { label: 'Home', key: 'home', href: '/' } ],
user: undefined,
basedir: '/Users/maxshine/Documents/workspace/keystone-boilerplate',
page: { title: 'Batch Dev', path: '/join' },
section: 'session',
form: {} }
@max8hine
max8hine / CSSOM.js
Created March 22, 2018 08:14
CSSOM - CSS Object Model In JS
// CSS Module
// https://medium.com/dailyjs/high-performance-dynamic-styles-db28c873940
// Create a <style> element. You can use an existing one as well.
const style = document.createElement(‘style’)
document.head.appendChild(style)
// Insert a CSS Rule to the sheet at position 0.
style.sheet.insertRule(‘.my-button {color: red}’, 0)