Skip to content

Instantly share code, notes, and snippets.

@nathanhoel
nathanhoel / logger.js
Last active December 14, 2016 20:01
Halite node.js logger module
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 December 6, 2019 01:54
A Tour of Go - Exercise: Web Crawler
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 January 22, 2016 07:33
save as utf-8-bom in atom
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 March 14, 2024 20:17
What forces layout/reflow. The comprehensive list.

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 February 25, 2018 13:49
Interweave arrays
// 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 October 14, 2014 16:26
Asynchronous while loop for ES6 Promises.
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();
}