Skip to content

Instantly share code, notes, and snippets.

Jeremy Martin jmar777

Block or report user

Report or block jmar777

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View async-function-rejection.js
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 Sep 22, 2016
quick-async-error-scenarios-example.js
View gist:7285d7cfc38248b813f7cd34b77647e6
async function awaitsRejectection() {
await Promise.reject('blah');
}
async function throwsStuff() {
throw new Error('blah');
}
@jmar777
jmar777 / gist:8766e645512c6ba15bdba9d9e8cbb98a
Created Sep 22, 2016
quick-async-error-scenarios-example.js
View gist:8766e645512c6ba15bdba9d9e8cbb98a
async function awaitsRejectection() {
await Promise.reject('blah');
}
async function throwsStuff() {
throw new Error('blah');
}
@jmar777
jmar777 / enum.js
Created Jun 21, 2016
Enum Implementation using ES6 Proxies and Symbols
View enum.js
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 Mar 17, 2016
Verifying myself on keybase.io
View keybase.md

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:

View dw-node-http-request-example.js
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 Feb 28, 2014
Debugging "Failed to run npm install. Snapshot logs for more details." on Elastic Beanstalk
View debugging-node-elastic-beanstalk-woes
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 Aug 29, 2012
MongoDB Aggregation Framework Silly Eventing Benchmark
View index.js
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 Jan 6, 2012
gaas-license-verification jitsu deploy error
View gist:1571615
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 Jan 6, 2012
gaas-license-verification jitsu create error
View gist:1571603
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:
You can’t perform that action at this time.