Skip to content

Instantly share code, notes, and snippets.

View zackiles's full-sized avatar

Zachary Iles zackiles

View GitHub Profile
@zackiles
zackiles / patch-command.js
Created November 3, 2024 02:45
Virtualized Patch Command in Javascript
import fs from 'node:fs/promises';
import path from 'node:path';
/**
* Applies a unified diff to a file system, emulating the Unix 'patch' command.
* @param {string} jsonString - The JSON string containing 'target_file' and 'diff'.
* @param {Object} [fsModule] - Optional file system module (e.g., memfs) for virtual file systems.
*/
async function applyPatch(jsonString, fsModule = fs) {
try {
@zackiles
zackiles / gnu-unified-diff-prompt.xml
Created November 3, 2024 02:43
Token-Efficient and Consistent AI Code Generation Through GNU Unified Diff (XML)
<output>
<OUTPUT_FORMAT>
<type>JSON</type>
<encoding>UTF-8</encoding>
<structure>
<target_file>string (relative path with forward slashes)</target_file>
<diff>string (unified diff with \n line breaks)</diff>
<error>string (optional, only present for errors)</error>
</structure>
</OUTPUT_FORMAT>
@zackiles
zackiles / gnu-unified-diff-prompt.json
Created November 3, 2024 02:43
Token-Efficient and Consistent AI Code Generation Through GNU Unified Diff (JSON)
{
"OUTPUT_FORMAT": {
"type": "JSON",
"encoding": "UTF-8",
"structure": {
"target_file": "string (relative path with forward slashes)",
"diff": "string (unified diff with \\n line breaks)",
"error": "string (optional, only present for errors)"
}
},
@zackiles
zackiles / bind_hack.js
Created November 26, 2015 00:10 — forked from tralamazza/bind_hack.js
node.js bind() hack
/*
* Author: Daniel Tralamazza <tralamazza@gmail.com>
*
* Patch Socket for a before connect event.
* Important! You must require this module before anything else.
*
* Usage:
*
* var patch = require('./bind_hack');
* var bind_f = process.binding('net').bind;