Skip to content

Instantly share code, notes, and snippets.

View Hlight's full-sized avatar

Aaron Ostrowsky Hlight

View GitHub Profile
@Hlight
Hlight / index.html
Last active August 29, 2015 14:21
When All Images Loaded - JS Bin// source http://jsbin.com/nirodepiwo
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<table border="0" width="573" cellspacing="0" cellpadding="0" align="center">
<tbody>
@Hlight
Hlight / index.html
Created April 27, 2016 20:12 — forked from anonymous/index.html
Breadcrumb Arrows (JS Bin// source http://jsbin.com/yomocov)
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.breadcrumbs {
font-family: sans-serif;
@Hlight
Hlight / jsbin.qufibad.js
Last active January 2, 2019 15:26
This in New Objects (JS Bin// source https://jsbin.com/qufibad)
// https://app.pluralsight.com/player?course=javascript-best-practices&author=jonathan-mills&name=javascript-best-practices-m3&clip=9&mode=live
'use strict';
var obj = function() {
var _this = this;
console.log(this);
this.hello = 'hello';
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.js"></script>
</head>
<body>
@Hlight
Hlight / jsbin.zekaxur.js
Last active January 2, 2019 15:58
JS Async Patters: Promises // source https://jsbin.com/zekaxur
/*
https://app.pluralsight.com/player?course=javascript-best-practices&author=jonathan-mills&name=javascript-best-practices-m4&clip=2&mode=live
Async Patters: Promises
*/
//-------------------
// # WITHOUT PROMISE:
//-------------------
@Hlight
Hlight / meld-osx.gitconfig
Created January 28, 2019 08:36
Meld OSX .gitconfig + CLI alias
# Paste this into ~/.gitconfig to enable meld for `git difftool` and `git mergetool`.
#### USE: meld
# Optional command line usage place below line in .bashrc
# alias meld="/Applications/Meld.app/Contents/MacOS/Meld"
[diff]
tool = meld
[difftool]
prompt = false
@Hlight
Hlight / js-strict-mode.md
Last active January 29, 2019 22:35
Javascript Strict Mode

Strict Mode

https://ponyfoo.com/articles/es6-modules-in-depth

In case it isn’t immediately obvious – you should 'use strict' in all the places. Even though it’s becoming de-facto in ES6, it’s still a good practice to use 'use strict' everywhere in ES6.

In the ES6 module system, strict mode is turned on by default. In case you don’t know what strict mode is, it’s just a stricter version of the language that disallows lots of bad parts of the language. It enables compilers to perform better by disallowing non-sensical behavior in user code, too.

The following is a summary extracted from changes documented in the strict mode article on MDN.

  • Variables can’t be left undeclared
@Hlight
Hlight / compare-arrays-numbers.js
Last active February 15, 2019 06:20
Compares numerical arrays for eqaulity including nested arrays.
// Function for testing our final arrays with the expected output.
// Compare function pulled from here:
// https://codeburst.io/comparison-of-two-arrays-using-javascript-3251d03877fe
function compare(arr1, arr2) {
if (!arr1 || !arr2) return
let result;
arr1.forEach((e1, i) => arr2.forEach(e2 => {
@Hlight
Hlight / generate-random-number-range.js
Created February 15, 2019 06:28
Function that returns a random integer between min and max. Both inclusive and exclusive options.
// Generate random numbers
// https://stackoverflow.com/a/1527820
/**
* Returns a random number between min (inclusive) and max (exclusive)
*/
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
@Hlight
Hlight / README.md
Last active February 25, 2019 05:30

make promise version of fs.readFile()

So, anytime you have multiple async operations to coordinate in some way, I immediately want to go to promises. And, the best way to use promises to coordinate a number of async operations is to make each async operation return a promise. The lowest level async operation you show is fs.readFile(). Since I use the Bluebird promise library, it has a function for "promisifying" a whole module's worth of async functions.

var Promise = require('bluebird');
var fs = Promise.promisifyAll(require('fs'));