Skip to content

Instantly share code, notes, and snippets.

View Hlight's full-sized avatar

Aaron Ostrowsky Hlight

View GitHub Profile
=== General Commands
help # show this usage
version # show the gem version
list # list your apps
create [<name>] # create a new app
keys # show your user's public keys
keys:add [<path to keyfile>] # add a public key
@Hlight
Hlight / README.md
Last active March 4, 2019 23:37
Typescript Docs Javascript Equality

Typescript Docs Javascript Equality


Equality

One thing to be careful about in JavaScript is the difference between == and ===. As JavaScript tries to be resilient against programming errors == tries to do type coercion between two variables e.g. converts a string to a number so that you can compare with a number as shown below:

console.log(5 == "5"); // true   , TS Error
console.log(5 === "5"); // false , TS Error
@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'));
@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 / 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 / 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 / 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 / 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:
//-------------------
<!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>