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 / lit-element-spa.html
Last active Nov 22, 2019
Outline for single-page application (router + links + app container + routes) with lit-element
View lit-element-spa.html
<!doctype html>
<html>
<head>
<script type="module">
import { LitElement, css, html } from 'https://unpkg.com/lit-element@latest/lit-element.js?module'
class RouterLink extends LitElement {
static get properties() {
return {
href: { type: String }
@brandonros
brandonros / lit-element.html
Last active Nov 20, 2019
lit-element example with unpkg (no build), async API fetch() call, loading state, and styling
View lit-element.html
<!doctype html>
<html>
<head>
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@2.0.0/custom-elements-es5-adapter.js"></script>
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@2.0.0/webcomponents-bundle.js"></script>
<script type="module">
import { LitElement, css, html } from 'https://unpkg.com/lit-element@2.2.1/lit-element.js?module'
class SimpleGreeting extends LitElement {
static get styles() {
@brandonros
brandonros / gist:d992a1836671e4e43cad0943aeefca91
Created Nov 17, 2019
How to compile libusb in XCode for iPhoneOS 13
View gist:d992a1836671e4e43cad0943aeefca91
See comment/image/screenshot.
@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
You can’t perform that action at this time.