Skip to content

Instantly share code, notes, and snippets.

View jmar777's full-sized avatar

Jeremy Martin jmar777

View GitHub Profile
async function example() {
// you can catch rejected promises that you await on
try {
await Promise.reject('blargh');
} catch (err) {
console.log(err);
}
// if you don't catch, then `example()` resolves to a rejected promise
await Promise.reject('blah')
@jmar777
jmar777 / gist:7285d7cfc38248b813f7cd34b77647e6
Created September 22, 2016 16:09
quick-async-error-scenarios-example.js
async function awaitsRejectection() {
await Promise.reject('blah');
}
async function throwsStuff() {
throw new Error('blah');
}
@jmar777
jmar777 / gist:8766e645512c6ba15bdba9d9e8cbb98a
Created September 22, 2016 16:09
quick-async-error-scenarios-example.js
async function awaitsRejectection() {
await Promise.reject('blah');
}
async function throwsStuff() {
throw new Error('blah');
}
@jmar777
jmar777 / enum.js
Created June 21, 2016 04:36
Enum Implementation using ES6 Proxies and Symbols
function Enum(names) {
let members = Object.create(null);
members.tryParse = name => {
if (!members[name]) {
throw new Error(`Unable to parse '${name}' as an Enum member.`);
}
return members[name];
};
@jmar777
jmar777 / keybase.md
Created March 17, 2016 19:35
Verifying myself on keybase.io

Keybase proof

I hereby claim:

  • I am jmar777 on github.
  • I am jmar777 (https://keybase.io/jmar777) on keybase.
  • I have a public key whose fingerprint is 5159 0463 0A5F 35F7 0ECC B9FB B5AB 0119 5DC6 FB5E

To claim this, I am signing this object:

function getTestPersonaLoginCredentials(cb) {
http.get({
host: 'personatestuser.org',
path: '/email'
}, function(res) {
// explicitly treat incoming data as utf8 (avoids issues with multi-byte chars)
res.setEncoding('utf8');
// incrementally capture the incoming response body
@jmar777
jmar777 / debugging-node-elastic-beanstalk-woes
Created February 28, 2014 22:32
Debugging "Failed to run npm install. Snapshot logs for more details." on Elastic Beanstalk
First, we need to figure out what the actual error is. This is obviously frustrating given that the error message is intentionally truncating it.
1) SSH in to your node (various guides available for this if you're not already familiar with this).
2) Run this command (basically an Elastic Beanstalk wrapper command for npm install I found in a blog post [1]):
$ sudo /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install 2
3) Find the actual error message in the output from the npm install.
Once you know the error, it should hopefully be fairly obvious how to fix it. I've run into two different errors over the last couple days on Elastic Beanstalk:
The first was a dependency that was using the new "^X.Y.Z" version syntax, which is only supported in Node >= v0.10.26 (whereas Elastic Beanstalk only supports up to v0.10.21 as of today). The solution here was easy: hardcode a dependency version *prior* to when that dependency adopted to the new syntax.
@jmar777
jmar777 / index.js
Created August 29, 2012 20:20
MongoDB Aggregation Framework Silly Eventing Benchmark
var db = connect('localhost:27017/aggr-test');
print('Dropping indexes...');
db.events.dropIndexes();
print('Creating index...');
var indexStart = Date.now();
db.events.ensureIndex({ ts: 1 });
var indexDuration = ((Date.now() - indexStart) / 1000).toFixed(2);
print('Index created (' + indexDuration + ' seconds)');
@jmar777
jmar777 / gist:1571615
Created January 6, 2012 17:42
gaas-license-verification jitsu deploy error
jmar777:gaas-license-verification jeremymartin$ jitsu deploy
info: Welcome to Nodejitsu
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Authenticated as jmar777
info: Analyzing your application dependencies in app.js
warn: Local version appears to be old.
warn: Your package.json version will be incremented for you automatically.
warn: About to write /Users/jeremymartin/Projects/gaas-license-verification/package.json
data:
@jmar777
jmar777 / gist:1571603
Created January 6, 2012 17:37
gaas-license-verification jitsu create error
jmar777:gaas-license-verification jeremymartin$ jitsu create
info: Welcome to Nodejitsu
info: It worked if it ends with Nodejitsu ok
info: Executing command create
info: Authenticated as jmar777
warn:
warn: Your package.json file is missing required fields:
warn:
warn: scripts.start
warn: