Skip to content

Instantly share code, notes, and snippets.

var urls = ['http://www.google.com', 'http://www.twitter.com'];
function get_request(url) {
return new Promise(function (resolve, reject) {
...
});
}
Error: write EPROTO
at Object.exports._errnoException (util.js:874:11)
at exports._exceptionWithHostPort (util.js:897:20)
at WriteWrap.afterWrite (net.js:763:14)
Error: write EPROTO
at Object.exports._errnoException (util.js:874:11)
at exports._exceptionWithHostPort (util.js:897:20)
at WriteWrap.afterWrite (net.js:763:14)
var Schema = function (input) {
var output = {};
Object.keys(input).forEach(function (key) {
if (input[key] === Number) {
output[key] = 'REAL';
}
else if (input[key] === String || input[key] === 'TEXT') {
output[key] = 'TEXT';
@brandonros
brandonros / countries+states.json
Created August 25, 2016 19:27
Two/three letter country codes with provinces/states
[
{
"code": "AF",
"name": "Afghanistan",
"provinces": [
{
"code": "BDS",
"name": "Badakhshān"
},
{
PROJECT = hello_erlang
DEP_PLUGINS = cowboy hexpm.mk
BUILD_DEPS = hexpm.mk
dep_hexpm.mk = git https://github.com/botsunit/mix.mk.git master
dep_cowboy_commit = 2.1.0
dep_pgapp = hex 0.0.2
dep_poison = hex 3.1.0
dep_epgsql = hex 3.4.0
// mandeljit.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <stdarg.h>
typedef struct {
char *dest;
} microasm;
// this makes it more obvious what we're doing later on
@brandonros
brandonros / cookies.js
Created February 21, 2019 06:04
Vanilla JavaScript frontend client cookie manipulation
const getCookie = (name) => {
var value = '; ' + document.cookie
var parts = value.split('; ' + name + '=')
if (parts.length === 2) {
return parts.pop().split(';').shift()
}
}
const setCookie = (name, value) => {
@brandonros
brandonros / gist:f276b75099d363d8c74e00ec55892e91
Created February 21, 2019 06:05
Vanilla JavaScript equivalent of jQuery $('body').on('click', 'selector', ...)
const bindEvent = (eventNames, selector, handler) => {
eventNames.split(' ').forEach((eventName) => {
document.addEventListener(eventName, function (event) {
if (event.target.matches(selector + ', ' + selector + ' *')) {
handler.apply(event.target.closest(selector), arguments)
}
}, false)
})
}
@brandonros
brandonros / isotp-frames.js
Last active June 3, 2019 18:04
node.js implementation of chunking a CAN response into ISO-TP frames
const FIRST_FRAME_PCI_BYTE = 0x01
const CONSECUTIVE_FRAME_PCI_BYTE = 0x02
const FIRST_FRAME_DATA_LENGTH = 5
const CONSECUTIVE_FRAME_DATA_LENGTH = 7
const PADDING_BYTE = 0xAA
const buildFirstFrame = (responseSid, data) => {
const responseLength = data.length + 1 // add a byte for response SID
const firstFrameData = data.slice(0, FIRST_FRAME_DATA_LENGTH)
const firstFrameHeader = Buffer.from([