Skip to content

Instantly share code, notes, and snippets.

@felipap
felipap / gist:d23858fe4245e47a225891722e3441ac
Last active January 9, 2024 02:56
Joyent's Error Handling in Node.js

The links to the original on the internet are all down. Posting this here hoping others can easily find it. Of course, I don't own this content.

Error Handling in Node.js

Error handling is a pain, and it's easy to get by for a long time in Node.js without dealing with errors correctly. However, building robust Node.js applications requires dealing with errors properly, and it's not hard to learn how. If you're really impatient, skip down to the "Summary" section for a tl;dr.

This document will answer several questions that programmers new to Node.js often ask:

  • In functions that I write, when should I throw an error, and when should I emit it with a callback, event emitter, or something else?
  • What should my functions assume about their arguments? Should I check that they're the correct types? Should I check more specific constraints, like that an argument is non-null, is non-negative, looks like an IP address, or the like?
normal
<div style="font-family: 'notoserif'; font-size: 30; margin-bottom: 20;">notoserif</div>
<div style="font-family: 'sans-serif'; font-size: 30; margin-bottom: 20;">sans-serif</div>
<div style="font-family: 'sans-serif-light'; font-size: 30; margin-bottom: 20;">sans-serif-light</div>
<div style="font-family: 'sans-serif-thin'; font-size: 30; margin-bottom: 20;">sans-serif-thin</div>
vector<double> *genRandomVector(int size) {
static random_device rnd_device;
static mt19937 mersenne_engine(rnd_device());
uniform_real_distribution<double> dist(-1, 1);
auto gen = std::bind(dist, mersenne_engine);
vector<double> *vec = new vector<double>(size);
generate(begin(*vec), end(*vec), gen);
return vec;
}
@felipap
felipap / .vimrc
Created June 12, 2016 22:13
.vimrc as of today
" I can't believe I'm redoing this.
" List of sources this .vimrc was based on:
" - https://amix.dk/vim/vimrc.html
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
@felipap
felipap / genymotionwithplay.txt
Created March 4, 2016 23:43 — forked from amondnet/genymotionwithplay.txt
Genymotion with Google Play Services
Download the following ZIPs:
ARM Translation Installer v1.1 (http://www.mirrorcreator.com/files/0ZIO8PME/Genymotion-ARM-Translation_v1.1.zip_links)
Download the correct GApps for your Android version:
Google Apps for Android 6.0 (https://www.androidfilehost.com/?fid=24052804347835438 - benzo-gapps-M-20151011-signed-chroma-r3.zip)
Google Apps for Android 5.1 (https://www.androidfilehost.com/?fid=96042739161891406 - gapps-L-4-21-15.zip)
Google Apps for Android 5.0 (https://www.androidfilehost.com/?fid=95784891001614559 - gapps-lp-20141109-signed.zip)
Google Apps for Android 4.4.4 (https://www.androidfilehost.com/?fid=23501681358544845 - gapps-kk-20140606-signed.zip)
Google Apps for Android 4.3 (https://www.androidfilehost.com/?fid=23060877490000124 - gapps-jb-20130813-signed.zip)
@felipap
felipap / cmpSemver.js
Created December 20, 2015 22:22
Compares two semvers.
function cmpSemver(v1, v2) {
if (v1 === "") {
return v2 === "" ? 0 : -1;
} else if (v2 === "") {
return 1;
}
var e1 = v1.match(/^(\d+)\.?(.*)/), e2 = v2.match(/^(\d+)\.?(.*)/);
if (parseInt(e1[1]) === parseInt(e2[1]))
return cmpVersions(e1[2], e2[2]);
return parseInt(e1[1]) > parseInt(e2[1]) ? 1 : -1;
@felipap
felipap / plugins.js
Last active August 29, 2015 14:15
Plugins! :)
$.fn.sshare = function (options) {
// Prevent binding multiple times.
if (this.find('.sn-share-btns').length)
return;
var defOptions = {
trigger: 'hover',
duration: 'fast',
text: undefined,
'''
Created on 18/06/2010
@author: Felipe
'''
#REMENBER TO COMMENT THE CODE!!!
def separate(eq,G,icox,icoy):
'''Separates the coeficients and sums of both equations and returns'''
#removes the spaces and *s of the equation
eq = eq.replace(' ','').replace('*','')
@felipap
felipap / foo.py
Created January 9, 2015 06:06
Exploit Ingresso.com
#!/usr/bin/env python3
from bs4 import BeautifulSoup
import urllib.request
base_url = 'http://carrinho.ingresso.com.br/br/compra/ingresso/codbarra/cinema/codbarra_novo.asp?id=00000000000000003620158410000'
base_url = 'http://carrinho.ingresso.com.br/br/compra/ingresso/codbarra/cinema/codbarra_novo.asp?id=0000000000000000 36201%04d 0000'
base_url = 'http://carrinho.ingresso.com.br/br/compra/ingresso/codbarra/cinema/codbarra_novo.asp?id=0000000000000000 361%05d 00000'
@felipap
felipap / server.js
Last active August 29, 2015 14:03
Server using passport to get twitter credentials for an account
passport = require 'passport'
express = require 'express'
app = express()
app.use(require('express-session')({
secret: 'mysecret',
resave: true,
saveUninitialized: true,
}))