Skip to content

Instantly share code, notes, and snippets.

View AaronHarris's full-sized avatar

Aaron Harris AaronHarris

  • University of Southern California
  • Seattle, WA
View GitHub Profile
@AaronHarris
AaronHarris / schema.graphql
Created November 29, 2022 00:04
Advanced GraphQL Schema
type Post {
id: ID!
title: String!
title2: String!
}
type Query {
# Get a single value of type 'Post' by primary key.
singlePost(id: ID!): Post
@deprecated(reason: "Use localization field instead")
@AaronHarris
AaronHarris / pdf417.html
Created October 7, 2021 12:00 — forked from ix4/pdf417.html
PDF417 Barcode Generator
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
@AaronHarris
AaronHarris / main.js
Last active April 10, 2021 04:29
Node's Pipeline Bug
import { pipeline, PassThrough, TransformCallback, Transform } from 'stream/promises';
import { createGunzip } from 'zlib';
import * as csv from 'csv-parser';
import * as S3 from 'aws-sdk/clients/s3';
const s3client = new S3({ maxRetries: 15, httpOptions: { timeout: 15 * 60_000 } });
async function main(bucketName, dataKey) {
const s3Stream = s3client.getObject({ Bucket: bucketName, Key: dataKey}).createReadStream()
.on('error', err => { console.error('S3 read error:', err); }); // errors from S3 service
const unzipStream = createGunzip()
@AaronHarris
AaronHarris / remove-invalid-xml-characters.js
Last active January 11, 2021 18:49 — forked from john-doherty/remove-invalid-xml-characters.js
JavaScript function that removes invalid XML characters from a string according to the spec
// remove everything forbidden by XML 1.0 specifications, plus the unicode replacement character U+FFFD
const INVALID_XML_REGEX = /((?:[\0-\x08\x0B\f\x0E-\x1F\uFFFD\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g;
// remove everything discouraged by XML 1.0 specifications
const DISCOURAGED_XML_REGEX = new RegExp(
'([\\x7F-\\x84]|[\\x86-\\x9F]|[\\uFDD0-\\uFDEF]|(?:\\uD83F[\\uDFFE\\uDFFF])|(?:\\uD87F[\\uDF' +
'FE\\uDFFF])|(?:\\uD8BF[\\uDFFE\\uDFFF])|(?:\\uD8FF[\\uDFFE\\uDFFF])|(?:\\uD93F[\\uDFFE\\uD' +
'FFF])|(?:\\uD97F[\\uDFFE\\uDFFF])|(?:\\uD9BF[\\uDFFE\\uDFFF])|(?:\\uD9FF[\\uDFFE\\uDFFF])' +
'|(?:\\uDA3F[\\uDFFE\\uDFFF])|(?:\\uDA7F[\\uDFFE\\uDFFF])|(?:\\uDABF[\\uDFFE\\uDFFF])|(?:\\' +
'uDAFF[\\uDFFE\\uDFFF])|(?:\\uDB3F[\\uDFFE\\uDFFF])|(?:\\uDB7F[\\uDFFE\\uDFFF])|(?:\\uDBBF' +
'[\\uDFFE\\uDFFF])|(?:\\uDBFF[\\uDFFE\\uDFFF])(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\' +
@AaronHarris
AaronHarris / fun-with-flow.js
Last active June 3, 2020 08:06
Fun with lodash-fp's flow
/**
* Nested grouping of a list of objects by multiple nested keys
* Unwraps groupByAll(['dataset_name', 'table_name', 'column_name']) to something like:
*
* ```
* _.flow(
* _.groupBy('dataset_name'),
* _.mapValues(_.groupBy('table_name')),
* _.mapValues(_.mapValues(_.groupBy('column_name')))
* )
@AaronHarris
AaronHarris / modulo.c
Last active June 10, 2019 09:57
Simple C program
#include <stdio.h>
int main()
{
int num1 = 0, num2 = 0, res1 = 0, res2 = 0;
printf("\nEnter num %% num: ");
scanf("%d %d", &num1, &num2);
res1 = num1 % num2;
res2 = num1 / num2;
@AaronHarris
AaronHarris / get_palindromic_cr.sh
Created January 6, 2019 09:07
Script I write to squat palindromic CR ids. I spent way too long on this.
read -p "Enter a string: " string
if [[ $(rev <<< $string) == "$string" ]]; then
echo Palindrome
fi
kcurl -s -o /dev/null -I -w "%{http_code}" https://cr.amazon.com/r/$FOO
curl -s http://www.example.com | sed -e 's#<!doctype.*##gm' | xpath '/html/body/div/h1/text()'
crlink=`kcurl -s https://cr.amazon.com/r/ | xmllint --html --xpath 'string(//*[@id="datagrid-0"]/div[2]/table/tbody/tr[1]/td[2]/a/@href)' 2>/dev/null -`
cr=${latestcr//[\/r]/}
@AaronHarris
AaronHarris / bootstrap-4-starter-template-using-cdn.markdown
Created January 24, 2018 21:46
Bootstrap 4: Starter template (using CDN)
@AaronHarris
AaronHarris / truncate-json.js
Last active January 7, 2019 23:21
A module that shortens JSON to a number of bytes while keeping syntactically valid JSON. Useful for when apis can only accept a certain byte length for input. Only works for NODE but can be ported to browsers. WIP.
function getBytes(string) {
return Buffer.byteLength(String(string), 'utf8');
}
function trimToBytes(string, diff) {
return Buffer.alloc(diff, string, 'utf8').toString();
}
// This is only intended atm for flat objects with string values
// Does not handle edge cases
@AaronHarris
AaronHarris / dummy.js
Last active September 27, 2017 09:54
JavaScript Stump - the Ultimate Singleton: This describes a function object that no matter whether you call it, instantiate it, or access or modify a property, it always returns itself.
var proxy, handler;
handler = {
has(/*target, prop*/) {
return false;
},
get(target, prop, receiver) {
if (prop in target) return target[prop];
return receiver;
},
set(/*target, prop, value, receiver*/) {