Skip to content

Instantly share code, notes, and snippets.

View joshtwist's full-sized avatar

Josh Twist joshtwist

View GitHub Profile
@joshtwist
joshtwist / fire-requests.js
Created April 21, 2024 19:23
Fire async requests and summarize results in table (node)
import fetch from "node-fetch";
import ProgressBar from "progress";
// Function to handle the individual fetch operation
async function sendRequest(url, index) {
try {
// console.log(`Sending request ${index + 1} to ${url}`);
const startTime = process.hrtime(); // Start timing here
const response = await fetch(url);
const duration = process.hrtime(startTime);
@joshtwist
joshtwist / extract-query-to-context.ts
Created March 5, 2024 12:34
Extract Query String (search params) to context.custom in Zuplo
import {ZuploContext, ZuploRequest} from "@zuplo/runtime";
export default async function policy(
request: ZuploRequest,
context: ZuploContext,
options: never,
policyName: string
) {
context.custom.originalQuery = request.query;
import {
ZuploContext,
ZuploRequest,
OpenIdJwtInboundPolicy,
InboundPolicyHandler,
OpenIdJwtInboundPolicyOptions,
Auth0JwtInboundPolicy,
Auth0JwtInboundPolicyOptions,
} from "@zuplo/runtime";
@joshtwist
joshtwist / graphql-logging.ts
Last active April 29, 2022 02:43
GraphQL Logging Policy
import { ZuploContext, ZuploRequest } from "@zuplo/runtime";
import environment from "@app/environment";
import { parse, visit } from "graphql";
import { BQWriter } from "./bg-writer";
interface LoggingEntry {
url: string;
method: string;
@joshtwist
joshtwist / BQWriter.ts
Created April 22, 2022 03:44
Writing to BigQuery from Zuplo
import { getTokenFromGCPServiceAccount } from "@sagi.io/workers-jwt";
import { Logger, ZuploContext } from "@zuplo/runtime";
const aud = "https://bigquery.googleapis.com/";
export class BQWriter<T> {
constructor(serviceAccountJson: string, projectId: string, datasetId: string, tableId: string) {
this.#serviceAccountJson = JSON.parse(serviceAccountJson);
this.#insertUrl = `${aud}bigquery/v2/projects/${projectId}/datasets/${datasetId}/tables/${tableId}/insertAll`;
export default async () => {
const response = await fetch('https://your-api.com');
const transformed = await transformBody(response);
return transformed;
}
@joshtwist
joshtwist / Fusion.ps1
Last active July 30, 2018 16:29
PowerShell to move and organize files from GoPro fusion
## GoPro Fusion Script to move files into grouped folders
# Where do you want your files moved to?
$targetFolder = "D:\GoPro Fusion\"
# For easiest workflow, just set the friendly/file system label for your front and back SD cards to "FusionSD"
$volumes = Get-Volume | Where FileSystemLabel -eq "fusionsd"
#### ==== support functions
[
{
"name": "Logger1",
"source": "https://gist.githubusercontent.com/joshtwist/93ed4ad55f814021c3a9fb45af98222d/raw/a0547371300d37290bc8527b1717105f591b567d/test.js",
"config": {
"appid": 123456
}
},
{
"name": "Logger2",
var config;
module.exports.init = function(config) {
utils.log("L2Configuration recevied");
utils.log(config);
config = config;
}
module.exports.log = function(message, params) {
utils.log("L2 Message :" + message);
module.exports.init = function(config) {
utils.log("Configuration recevied");
utils.log(config);
}
module.exports.log = function(message, params) {
utils.log("Message :" + message);
utils.log("Params :" + params);
}