Skip to content

Instantly share code, notes, and snippets.

@park-brian
park-brian / index.js
Last active February 21, 2025 05:04
UPNP in Node.js
import http from "http";
import { once } from "events";
import NatUpnp from "./nat-upnp.js";
const mapping = {
public: 8081,
private: 8080,
protocol: "TCP",
description: "Node.js server",
ttl: 0,
@park-brian
park-brian / complete.js
Last active January 22, 2025 18:38
complete.js
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const vm = require("vm");
const util = require("util");
const { OpenAI } = require("openai");
const [inputFile, attemptsArg, model = "deepseek-reasoner"] = process.argv.slice(2);
const maxAttempts = parseInt(attemptsArg) || 5;
const maxTokens = 8000;
@park-brian
park-brian / substructure-search.js
Created January 22, 2025 01:46
substructure-search.js
/**
SMILES Rules:
Atoms:
Represented by their atomic symbols.
Common organic elements (B, C, N, O, P, S, F, Cl, Br, I) can be written without brackets if they have no formal charge and the number of attached hydrogens is implied by typical valence.
Atoms outside this set or with explicit hydrogens, charges, or isotopes are enclosed in brackets, e.g., [Fe], [OH2], [13C].
Bonds:
@park-brian
park-brian / getBytesFromRanges.js
Last active December 8, 2024 09:49
getBytesFromRanges (eg: sliceMany for remote files)
/**
* Retrieves byte ranges from a URL using the Fetch API.
* Uses ASCII encoding for direct byte<->text position mapping.
*
* @param {Object} options
* @param {string} options.url - Source URL
* @param {(number[]|null)[]} options.ranges - Array of [start, end] pairs (end is exclusive)
* @param {RequestInit} options.requestInit - Fetch API configuration
* @param {boolean} [options.trustContentType=false] - Whether to trust multipart boundary from content-type header
*/
@park-brian
park-brian / importDynamoDBTable.js
Last active July 19, 2021 23:49
Uses parallel batchWrite requests to quickly load data into DynamoDB.
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function insertDynamoDBItems(documentClient, tableName, items) {
if (!items.length) return;
let responses = [];
let response = await documentClient
.batchWrite({
@park-brian
park-brian / index.html
Last active July 6, 2021 15:39
Breast Cancer QQ Plot
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>PLCO QQ Plot</h1>
@park-brian
park-brian / fromCsv.js
Last active June 2, 2021 15:24
CSV utilities
/**
* A parser which handles any rfc4180 compliant csv file
* Configuration takes the following properties
* delimiter: specifies the field delimiter (default: ",")
* escape: specifies the escape character (default: ")
* skipLines: specifies the number of lines to skip (default: 0)
* transformRow: transform sthe default ouput from an array of strings to your custom format (eg: an array of objects)
* transformValue: transforms individual values (eg: for custom typecasting logic)
*/
@park-brian
park-brian / index.html
Last active August 11, 2021 19:00
RWS Editor Test Latest
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<input id="height" placeholder="Height">
<input id="width" placeholder="Width">
@park-brian
park-brian / index.html
Last active January 30, 2021 20:12
RWS Editor Test 2
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<input id="height" placeholder="Height">
<input id="width" placeholder="Width">
@park-brian
park-brian / QuadTree.js
Last active October 12, 2020 21:53
A simple quadtree for rapidly fetching spatial data
/**
* A simple quadtree for rapidly fetching spatial data
* @param {number} xMin
* @param {number} xMax
* @param {number} yMin
* @param {number} yMax
*/
function QuadTree(xMin, xMax, yMin, yMax) {
// swap xMin/xMax and yMin/yMax if needed
if (xMin > xMax) [xMin, xMax] = [xMax, xMin];