codehygiene / presets.json
brianbellx's picture
Upgrade to codehygiene v0.6.1, Bonsai 1.7B WebGPU + ZeroGPU refiner, and Data Retention page
5c265c1 verified
Raw History Blame Contribute Delete
6.73 kB
[
{
"id": "python-receipt",
"filename": "send_receipt.py",
"before": "def send_receipt(order: Order) -> None:\n try:\n if order is not None:\n if order.paid and not order.refunded:\n # Extract email address from order\n email = order.email\n if email is not None:\n if len(email.strip()) > 0:\n mailer.send(email, order.id)\n except Exception:\n pass",
"after": "def send_receipt(order: Order) -> None:\n if not order.paid or order.refunded:\n return\n\n if not order.email or not order.email.strip():\n return\n\n mailer.send(order.email, order.id)"
},
{
"id": "ts-ceremony",
"filename": "pricing.ts",
"before": "export class DiscountStrategyFactoryManager {\n public computeTotalAmount(cartItems: CartItem[], promoRate: number): number {\n try {\n // Step 1: Compute discounted subtotal from cart items\n const total = cartItems.filter((item) => item.active && item.qty > 0).map((item) => item.price * item.qty * (promoRate > 0 ? (promoRate > 0.5 ? 0.5 : 1 - promoRate) : 1)).reduce((acc, val) => acc + val, 0);\n return total;\n } catch (err) {\n console.log(err);\n return 0.0;\n }\n }\n}",
"after": "export function computeOrderTotal(items: CartItem[], promoRate: number): number {\n const cappedRate = Math.min(Math.max(promoRate, 0), 0.5);\n const multiplier = 1 - cappedRate;\n\n let subtotal = 0;\n for (const item of items) {\n if (item.active && item.qty > 0) {\n subtotal += item.price * item.qty * multiplier;\n }\n }\n\n return subtotal;\n}"
},
{
"id": "rust-golf",
"filename": "frame.rs",
"before": "#[allow(clippy::many_single_char_names)]\npub fn decode_frame(buf: &[u8]) -> Option<(u32, u16, u8)> {\n let mut hd = [0u8; 16];\n hd[0] = buf[12] ^ buf[28];\n hd[1] = buf[14] ^ buf[30];\n hd[2] = buf[18] ^ buf[34];\n hd[3] = buf[22] ^ buf[38];\n let mg = u16::from_be_bytes([buf[10], buf[11]]);\n let sq = u32::from_be_bytes([buf[16], buf[17], buf[18], buf[19]]);\n let ln = u16::from_be_bytes([buf[24], buf[25]]);\n let fl = buf[36] ^ buf[42];\n let ck = buf[44] ^ buf[47];\n let vr = hd[0].wrapping_add(hd[1]).wrapping_add(hd[2]);\n let ok = mg == 23112 && vr > 0 && (fl & 4) != 0 && ck != 0;\n if !ok { return None; }\n Some((sq, ln, ck))\n}",
"after": "const HEADER_LEN: usize = 48;\nconst FRAME_MAGIC: u16 = 0x5A48;\nconst FLAG_VERIFIED: u8 = 0x04;\n\npub struct FrameHeader {\n pub sequence: u32,\n pub payload_len: u16,\n pub checksum: u8,\n}\n\npub fn decode_header(bytes: &[u8]) -> Result<FrameHeader, FrameError> {\n if bytes.len() < HEADER_LEN {\n return Err(FrameError::TruncatedHeader);\n }\n\n let magic = u16::from_be_bytes([bytes[0], bytes[1]]);\n if magic != FRAME_MAGIC {\n return Err(FrameError::InvalidMagic);\n }\n\n let flags = bytes[2];\n if flags & FLAG_VERIFIED == 0 {\n return Err(FrameError::UnverifiedPayload);\n }\n\n let sequence = u32::from_be_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);\n let payload_len = u16::from_be_bytes([bytes[8], bytes[9]]);\n Ok(FrameHeader {\n sequence,\n payload_len,\n checksum: bytes[3],\n })\n}"
},
{
"id": "go-clones",
"filename": "webhook.go",
"before": "func resolveEndpoint(region string) string {\n if region == \"us-east-1\" { return \"https://east.hooks.internal\" }\n if region == \"us-west-2\" { return \"https://west.hooks.internal\" }\n if region == \"eu-central-1\" { return \"https://eu.hooks.internal\" }\n if region == \"ap-northeast-1\" { return \"https://ap.hooks.internal\" }\n if region == \"sa-east-1\" { return \"https://sa.hooks.internal\" }\n return \"https://default.hooks.internal\"\n}\n\nfunc publishAuditEvent(httpClient *Client, region string, auditItem Event) {\n targetUrl := resolveEndpoint(region)\n bodyBytes := serializeJsonBody(auditItem)\n authToken := computeHmacSignature(bodyBytes, httpClient.signingSecret)\n statusCode := transmitHttpPost(httpClient, targetUrl, bodyBytes, authToken)\n recordTelemetryCounter(statusCode, region)\n}\n\nfunc publishBillingEvent(httpClient *Client, region string, billingItem Event) {\n targetUrl := resolveEndpoint(region)\n bodyBytes := serializeJsonBody(billingItem)\n authToken := computeHmacSignature(bodyBytes, httpClient.signingSecret)\n statusCode := transmitHttpPost(httpClient, targetUrl, bodyBytes, authToken)\n recordTelemetryCounter(statusCode, region)\n}",
"after": "var regionEndpoints = map[string]string{\n \"us-east-1\": \"https://east.hooks.internal\",\n \"us-west-2\": \"https://west.hooks.internal\",\n \"eu-central-1\": \"https://eu.hooks.internal\",\n \"ap-northeast-1\": \"https://ap.hooks.internal\",\n \"sa-east-1\": \"https://sa.hooks.internal\",\n}\n\nfunc resolveEndpoint(region string) string {\n if endpoint, ok := regionEndpoints[region]; ok {\n return endpoint\n }\n return \"https://default.hooks.internal\"\n}\n\nfunc postStreamEvent(\n ctx context.Context,\n client *http.Client,\n endpoint string,\n stream string,\n event Event,\n) error {\n payload, err := json.Marshal(event)\n if err != nil {\n return fmt.Errorf(\"marshal %s: %w\", stream, err)\n }\n\n req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(payload))\n if err != nil {\n return fmt.Errorf(\"build %s request: %w\", stream, err)\n }\n req.Header.Set(\"Content-Type\", \"application/json\")\n req.Header.Set(\"X-Event-Stream\", stream)\n\n resp, err := client.Do(req)\n if err != nil {\n return fmt.Errorf(\"send %s webhook: %w\", stream, err)\n }\n defer resp.Body.Close()\n return nil\n}"
},
{
"id": "self-engine",
"filename": "engine.js",
"before": "export function unpack(tb, vb, ms) {\n let sp, ft, bo, vo, bv, ds;\n // TODO: clean up golfed trit unpacking\n sp = ms.split(\"|\");\n ft = new Int8Array(tb.length * 5);\n bo = 0;\n vo = 0;\n for (let i = 0; i < tb.length; i++) {\n bv = tb[i];\n ds = i * 5;\n ft[ds] = (((bv % 3) + 1) % 3) - 1;\n ft[ds + 1] = (((Math.floor(bv / 3) % 3) + 1) % 3) - 1;\n ft[ds + 2] = (((Math.floor(bv / 9) % 3) + 1) % 3) - 1;\n ft[ds + 3] = (((Math.floor(bv / 27) % 3) + 1) % 3) - 1;\n ft[ds + 4] = (((Math.floor(bv / 81) % 3) + 1) % 3) - 1;\n }\n try {\n return sp[0].length > 0 && bo >= vo ? ft : (vb || []);\n } catch (e) {}\n}",
"after": "__LOAD_LIVE_ENGINE__"
}
]