Skip to content

Instantly share code, notes, and snippets.

View christianscott's full-sized avatar

Christian Scott christianscott

View GitHub Profile
@christianscott
christianscott / caesar.c
Created May 25, 2023 03:49
caesar cypher .c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc <= 1) {
printf("Usage: %s [+/-shift]\n", argv[0]);
return 1;
}
char* shift_str = argv[1];
int sign = 1;
if (shift_str[0] == '-') {
@christianscott
christianscott / main.js
Created March 20, 2023 10:36
NodeJS implementation of Simon Willinson's "A simple Python implementation of the ReAct pattern for LLMs"
// See https://til.simonwillison.net/llms/python-react-pattern
import * as proc from "node:child_process";
import * as https from "node:https";
import * as readline from "node:readline";
import * as url from "node:url";
import { Configuration, OpenAIApi } from "openai";
async function main() {
const bot =
// vec
#define vec_free(a) ((a) ? free(vec__raw(a)),0 : 0)
#define vec_push(a,v) (vec__maybegrow(a,1), (a)[vec__n(a)++] = (v))
#define vec_count(a) ((a) ? vec__n(a) : 0)
#define vec_add(a,n) (vec__maybegrow(a,n), vec__n(a)+=(n), &(a)[vec__n(a)-(n)])
#define vec_last(a) ((a)[vec__n(a)-1])
#include <stdlib.h>
#define vec__raw(a) ((int *) (a) - 2)
#define vec__m(a) vec__raw(a)[0]
@christianscott
christianscott / register_require_builtin_only.js
Created August 17, 2021 04:28
error on import of 3rd party module
const mod = require('module');
const os = require('os');
const colors = {
red: '\033[0;31m',
none: '\033[0m',
};
const logErr = (msg) => process.stderr.write(`${colors.red}ERROR: ${msg}${os.EOL}${colors.none}`);
@christianscott
christianscott / no_crawl_hastemap.js
Last active August 30, 2021 00:14
HasteMap impl that does not crawl
const { default: HasteMap } = require("jest-haste-map");
class NoCrawlHasteMap extends HasteMap {
// https://github.com/facebook/jest/blob/master/packages/jest-haste-map/src/index.ts#L754-L798
// usually calls out to a fn that runs `find` in the current directory, which is *incredibly*
// slow if you have a lot of files
async _crawl() {
return {
hasteMap: this._createEmptyMap(),
removedFiles: [],
};
set -e
rm -rf out
mkdir out
cat >"index.js" <<EOF
console.log("hello from nodejs!");
EOF
zip -q out/archive.zip index.js
@christianscott
christianscott / a_usage.sh
Created July 1, 2021 08:13
Count package versions across a JS monorepo
fd '**/package.json' | node count_versions_in_monorepo.js
class DirectedGraph<T> {
readonly edges: Map<T, Set<T>> = new Map();
addAll(from: T, ...to: T[]) {
let dependencies = this.edges.get(from);
if (dependencies == null) {
dependencies = new Set();
this.edges.set(from, dependencies);
}
Sets.addAll(dependencies, to);
#!/usr/bin/env sh
set -e
emoji=(
"+1"
"-1"
"100"
"1234"
"1st_place_medal"
import { atomizeCss } from "../";
describe(`${atomizeCss.name}`, () => {
it("works with a simple rule", () => {
const { newCss, selectorMapping } = atomizeCss(`.class { color: red; }`);
expect(newCss).toBe(".a0 { color:red; }");
expect(selectorMapping.get(".class")).toEqual([".a0"]);
});
test("de-dupes between rules", () => {