Skip to content

Instantly share code, notes, and snippets.

View mattmazzola's full-sized avatar

Matt Mazzola mattmazzola

View GitHub Profile
export interface ISpi {
write(buffer: Buffer, callback: (error: any, data: any) => void): void;
}
export interface ILedStrip {
all(r: number, g: number, b: number, a?: number): void;
set(led: number, r: number, g: number, b: number, a?: number): void;
clear(): void;
off(): void;
sync(): void;
}
@mattmazzola
mattmazzola / jwt-simple-browser.js
Last active May 10, 2023 12:06
jwt-simple-browser
function createToken(payload, key) {
var header = { typ: 'JWT', alg: 'HS256' };
var segments = [];
segments.push(encodeURIComponent(btoa(JSON.stringify(header))));
segments.push(encodeURIComponent(btoa(JSON.stringify(payload))));
var footer = sign(segments.join('.'), key);
@mattmazzola
mattmazzola / route-recognizer-test.js
Last active June 1, 2016 23:15
Route Recognizer Wildcard Test
let RouteRecognizer = require("route-recognizer");
let router = new RouteRecognizer();
router.add([{ path: '*path', handler: null }]);
router.add([{ path: '/report/pages', handler: null }]);
router.add([{ path: '/report/pages/:pageName', handler: null }]);
router.add([{ path: '/report/pages/:pageName/visuals/:visualId', handler: null }]);
let getPages = router.recognize('/report/pages');
console.log('/report/pages: ', getPages);
@mattmazzola
mattmazzola / pagination.ts
Last active December 6, 2018 06:17
GraphQL Pagination Implementation
var graphql = require('graphql');
export function Edge(itemType: any) {
return new graphql.GraphQLObjectType({
name: "Edge",
description: "Generic edge to allow cursors",
fields: () => ({
node: { type: itemType },
cursor: { type: graphql.GraphQLString }
})
@mattmazzola
mattmazzola / schema.ts
Created October 10, 2016 01:42
GraphQL Paginated Query Implementation
units: {
type: pagination.Page(Unit),
description: "Return the 'first' X number of items 'after' the specified cursor'",
args: {
first: {
type: graphql.GraphQLInt,
description: "Limits the number of results returned in the page. Defaults to 10."
},
after: {
type: graphql.GraphQLString,
@mattmazzola
mattmazzola / query.js
Created October 10, 2016 01:46
GraphQL Pagination Sample Query
{
units(first: 2, after: "ODg=") {
totalCount
edges {
node {
id
meta {
name
}
}
@mattmazzola
mattmazzola / result.json
Created October 10, 2016 01:47
GraphQL Pagination Sample Result
{
"data": {
"units": {
"totalCount": 140,
"edges": [
{
"node": {
"id": 288,
"meta": {
"name": "Banshee"
@mattmazzola
mattmazzola / SampleRequest.txt
Created October 15, 2016 19:55
FiddlerExtensions_SampleRequest
GET http://www.example.com/ HTTP/1.1
User-Agent: Fiddler
Host: www.example.com
x-session-id: 1756a272-0f00-488f-832a-0b902170b1bf
x-activity-id: 717c62a2-41ac-41e4-bce2-47d65d4162cc
x-json-data: eyJmb28iOjEsImJhciI6MiwiYmF6IjozLCJvYmoiOnsiYSI6ImEiLCJiIjoiYiIsImMiOiJjIn19
@mattmazzola
mattmazzola / BindUIColumnAttribute.js
Created October 15, 2016 20:54
FiddlerExtension_CustomRule
public static BindUIColumn("x-activity-id", 61)
function BindSessionId(oS: Session): String {
return oS.RequestHeaders["x-activity-id"];
}