Skip to content

Instantly share code, notes, and snippets.

@nathanhoel
nathanhoel / logger.js
Last active Dec 14, 2016
Halite node.js logger module
View logger.js
const loggerOn = 0;
var winston = null;
try {
winston = require('winston');
winston.remove(winston.transports.Console);
winston.add(
winston.transports.File,
{
filename: 'match.log',
@hello-josh
hello-josh / crawler.go
Last active Dec 6, 2019
A Tour of Go - Exercise: Web Crawler
View crawler.go
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
@nixel2007
nixel2007 / init.coffee
Created Jan 22, 2016
save as utf-8-bom in atom
View init.coffee
atom.workspace.observeTextEditors (editor) ->
editor.onDidSave ->
if editor.getPath().slice(-3) is '.os'
if editor.getEncoding() is 'utf8' and editor.getText().charCodeAt(0) isnt 65279
editor.setText String.fromCharCode(65279) + editor.getText()
editor.save()
@paulirish
paulirish / what-forces-layout.md
Last active Sep 21, 2021
What forces layout/reflow. The comprehensive list.
View what-forces-layout.md

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@royling
royling / interweave.js
Last active Feb 25, 2018
Interweave arrays
View interweave.js
// inspired when reading https://leanpub.com/understandinges6/read#leanpub-auto-define-tags
// this is the behavior that template tags may interweave literals and subsitutions arrays
var interweave = (a, b) => {
let min = Math.min(a.length, b.length);
return Array.apply(null, Array(min)).reduce((result, value, index) => {
result.push(a[index], b[index]);
return result;
}, []).concat((a.length > min ? a : b).slice(min));
};
@tyler-johnson
tyler-johnson / asyncwhile.js
Created Oct 14, 2014
Asynchronous while loop for ES6 Promises.
View asyncwhile.js
function asyncWhile(condition, action, ctx) {
var whilst = function(data) {
return condition.call(ctx, data) ?
Promise.resolve(action.call(ctx, data)).then(whilst) :
data;
}
return whilst();
}