Skip to content

Instantly share code, notes, and snippets.

View jefflau's full-sized avatar
🏪
Working from Taipei

Jeff Lau jefflau

🏪
Working from Taipei
View GitHub Profile
@jefflau
jefflau / .bash_profile
Last active August 29, 2015 14:25
Alias for sublime
// Open ~/.bash_profile and add this
alias s="open -a '/Applications/Sublime Text.app'"
source ~/.bash_aliases
@jefflau
jefflau / gridmixin.styl
Last active September 7, 2015 05:47
Stylus Grid Mixin using calc() to create grids with percentage widths, but pixel based gutters
grid($columns, $gutter)
$width = 100% /$columns;
$marginDeficit = $gutter * ($columns - 1) / $columns;
float: left;
width: "calc(%s - %s)" % ($width $marginDeficit);
margin-right: $gutter
&:nth-child({$columns}n)
margin-right: 0;
@jefflau
jefflau / es6Part1.md
Last active October 3, 2015 09:39
A journey through ES6 - Part 1

A journey through ES6 - Part 1

I’ve just started learning ES6 properly and to help others I’m going to document what I’ve learnt through a series of blog posts. In this post we’re going to start with the most basic parts of ES6 that you can jump into straight away. let and const are two new keywords for defining variables. Both are really simple to use and solve some problems in the JavaScript language. 

##let

We’ll start looking at let first. JavaScript’s scoping is done with functions. That means anything declared as a var inside a function closure will be only accessible within the function. One thing JavaScript didn’t have before ES6 was block scoping, and that is where let comes into play. Block scoping is scoping within a ‘block’. That block is denoted by the { ... } curly braces in JavaScript.

let allows you to create block scopes

@jefflau
jefflau / destructuring.md
Last active October 3, 2015 10:09
A journey through ES6 - Part 3

#Destructuring

Destructuring is a very useful technique in ES6. It allows you to 'break down' or 'deconstruct' an object into variables. Think of it like flattening the object so all the properties and value come out as normal variables.

##Simple Example

var obj = {
  a: 1,
@jefflau
jefflau / nomadlinks.md
Last active October 23, 2015 08:32
Links for nomads and freelancers in Taiwan
@jefflau
jefflau / arrowFunctions.md
Last active December 22, 2016 16:17
A journey through ES6 - Part 2

#Arrow Functions

Arrow functions (also known as fat arrow functions) are awesome. They do two main things for you. Create a shorter syntax, and lexically scope this.

##Shorter syntax

//ES5
[1, 2, 3].map(function(n){ return n + 1 } // [2, 3, 4]
//ES6
@jefflau
jefflau / redax.js
Last active May 16, 2017 09:18
Redax
//Redax.js
export default class Redax {
constructor(data, render, middleware) {
this.db = data
this.render = render
this.middleware = middleware
}
update(newData){
let data = this.middleware.reduce((state, middleware) => middleware(state), newData)
@jefflau
jefflau / _utils.styl
Last active May 16, 2017 16:12
Stylus mixins and extends
$width-xxs = 600px
$width-xs = 728px
$width-s = 970px
$width-m = 1024px
$width-l = 1200px
bp(width)
@media (max-width: width)
{block}
@jefflau
jefflau / asyncawait.js
Last active May 30, 2017 05:59
Async await vs promises
export const getSubdomains = async name => {
let namehash = await getNamehash(name)
let logs = await getENSEvent('NewOwner', {node: namehash}, {fromBlock: 900000, toBlock: 'latest'})
let labels = await decryptHashes(...logs.map(log => log.args.label))
let ownerPromises = labels.map(label => getOwner(`${label}.${name}`))
return Promise.all(ownerPromises).then(owners => {
let subdomains = labels.map((value, index) => {
//if(label === false)
// TODO add check for labels that haven't been found
0x866B3c4994e1416B7C738B9818b31dC246b95eEE