Skip to content

Instantly share code, notes, and snippets.

Brandon Ros brandonros

Block or report user

Report or block brandonros

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
@brandonros
brandonros / stripe.js
Last active Jul 6, 2019
Easiest node.js Stripe API implementation I could come up with
View stripe.js
const rp = require('request-promise-native')
const apiRequest = (uri, form) => {
return rp.post({
uri,
form,
json: true,
headers: {
authorization: `Basic ${Buffer.from(`${process.env.STRIPE_API_KEY}:`).toString('base64')}`
}
@brandonros
brandonros / isotp-frames.js
Last active Jun 3, 2019
node.js implementation of chunking a CAN response into ISO-TP frames
View isotp-frames.js
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([
@brandonros
brandonros / grpc+avro.js
Created Mar 27, 2019
gRPC + SSL with Avro encoding in node.js
View grpc+avro.js
const grpc = require('grpc')
const fs = require('fs')
const avro = require('avsc')
const hexdump = require('hexdump-nodejs')
const encodeMessage = (avroType, request) => {
let opts = {
codec: null,
writeHeader: true
}
@brandonros
brandonros / gist:f276b75099d363d8c74e00ec55892e91
Created Feb 21, 2019
Vanilla JavaScript equivalent of jQuery $('body').on('click', 'selector', ...)
View gist:f276b75099d363d8c74e00ec55892e91
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 / cookies.js
Created Feb 21, 2019
Vanilla JavaScript frontend client cookie manipulation
View cookies.js
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 / blueGreenDeployment.js
Created Dec 17, 2018
node.js + nginx + PM2 rolling release/blue green deployments (zero downtime)
View blueGreenDeployment.js
const Promise = require('bluebird');
const fs = require('fs');
const execa = require('execa');
class BlueGreenDeployment {
constructor({appName, blueProxyPassPattern, greenProxyPassPattern, nginxConfigFile}) {
this.appName = appName;
this.blueProxyPassPattern = blueProxyPassPattern;
this.greenProxyPassPattern = greenProxyPassPattern;
this.nginxConfigFile = nginxConfigFile;
View mandeljit.c
// 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 / bmw-esys-series-codes.java
Last active Dec 20, 2018
Extracted BMW F series ESYS commands (DME/ECU/Tune/Code)
View bmw-esys-series-codes.java
// Random code sequences I found throughout a flashing tool
D = new hs("RCS_EraseCoding", "31 01 0F 01", 3, false);
e = new ha("DSC_DS", "10 01");
f = new ha("DSC_ES", "10 03");
g = new ha("DSC_PS", "10 02");
h = new ha("DSC_DEVS", "10 4F");
i = new ha("DSC_CS", "10 41");
j = new ku("RCS_SEMD", "31 01 0F 0C 00");
k = new ku("RCS_SEMF", "31 01 0F 0C 03");
View Makefile
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
@brandonros
brandonros / countries+states.json
Created Aug 25, 2016
Two/three letter country codes with provinces/states
View countries+states.json
[
{
"code": "AF",
"name": "Afghanistan",
"provinces": [
{
"code": "BDS",
"name": "Badakhshān"
},
{
You can’t perform that action at this time.