Skip to content

Instantly share code, notes, and snippets.

View corporatepiyush's full-sized avatar
🎯
Focusing

Piyush Katariya corporatepiyush

🎯
Focusing
View GitHub Profile
@corporatepiyush
corporatepiyush / optimizations.html
Created May 11, 2026 10:28
Web, NodeJS and Common optimizations in JS
<h2 class="sr-only">Low-level JavaScript optimizations, filterable by category and search</h2>
<style>
*{box-sizing:border-box;margin:0;padding:0}
.wrap{padding:1rem 0;font-family:var(--font-sans)}
.search{width:100%;padding:8px 12px;font-size:14px;border:0.5px solid var(--color-border-secondary);border-radius:var(--border-radius-md);background:var(--color-background-primary);color:var(--color-text-primary);margin-bottom:1rem}
.search:focus{outline:none;border-color:var(--color-border-primary)}
.tabs{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:1rem}
.tab{padding:5px 14px;font-size:13px;border:0.5px solid var(--color-border-secondary);border-radius:var(--border-radius-md);cursor:pointer;background:var(--color-background-primary);color:var(--color-text-secondary);transition:all .12s;user-select:none}
.tab.on{background:var(--color-background-secondary);color:var(--color-text-primary);border-color:var(--color-border-primary);font-weight:500}
"""
The most atomic way to train and run inference for a GPT in pure, dependency-free Python.
This file is the complete algorithm.
Everything else is just efficiency.
@karpathy
"""
import os # os.path.exists
import math # math.log, math.exp
@corporatepiyush
corporatepiyush / For.java
Created October 16, 2025 21:26
Optimizing For loops
import java.util.Random;
public class For {
static final int SIZE = 1_000_000;
public static void main(String[] args) {
int[] data = new int[SIZE];
Random rnd = new Random(42);
for (int i = 0; i < SIZE; i++) data[i] = rnd.nextInt(1000) - 500;
@corporatepiyush
corporatepiyush / Matmul.c
Last active October 16, 2025 08:11
Matrix Multiplication
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
// REQUIRED for the M1/Apple Silicon native BLAS implementation (Accelerate Framework)
// gcc -O3 -Wall -Wextra Matmul.c -o Matmul -lm -framework Accelerate
#include "cblas.h"
// --- Utility Functions ---
@corporatepiyush
corporatepiyush / bp-golang.md
Last active May 23, 2026 10:30
Top 100 Best Practices for Golang

Memory Management & Allocation

  1. Pre-allocate Slices with Known Capacity When the eventual size of a slice is known, pre-allocating with make([]T, 0, capacity) creates the underlying array a single time. This critical practice avoids multiple, inefficient reallocations and the expensive process of copying all existing elements to a new, larger array as you append data.

  2. Use the arena for Short-Lived Objects This is perfect for functions that create many temporary objects (like during a single request), as it can nearly eliminate GC pressure from that workload. or else you can also implement custom arena code. Custom Arena backed by mmap file function might help if you want storage for those value and gaurantees which comes with it if process fails or you need more space than allocated RAM size. If data persistence is not important, implementing arena with off-heap storage using unsafe package and pointers can be very beneficial as it is faster than GC heap (default) acce

@corporatepiyush
corporatepiyush / BufferPool.dart
Last active October 10, 2025 20:43
High Performace Application level Buffer Pool for Networking, Image Processing, Graphics, Game engines and File IO Tasks
/// @file A high-performance buffer pool implementation in Dart for managing TypedData.
/// @author Piyush Katariya
/// @version 1.5.0
library buffer_pool;
import 'dart:typed_data';
import 'dart:math';
import 'dart:ffi';
import 'package:ffi/ffi.dart';
@corporatepiyush
corporatepiyush / benchmark.js
Created September 23, 2025 08:40
Benchmark for JSON vs Binary and why JS/V8 so stupid
// benchmark.js
import { faker } from '@faker-js/faker';
import fs from 'fs';
import crypto from 'crypto';
// Text encoder/decoder for binary operations
const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();
// Mock MessageType enum
@corporatepiyush
corporatepiyush / bufferpool.c
Last active September 19, 2025 15:29
Custom memory allocator with Buffer Pool
#define _GNU_SOURCE
#include "bufferpool.h"
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <stdatomic.h>
#include <dlfcn.h>
#include <errno.h>
#include <sys/mman.h>
#include <inttypes.h>
@corporatepiyush
corporatepiyush / http2.js
Last active September 15, 2025 08:09
HTTP 2 implementation
'use strict';
process.title = 'http2server';
console.error('SERVER PID', process.pid);
/* ---------- Linux early tuning ------------------------------ */
if (process.platform === 'linux') {
try {
require('fs').writeFileSync('/proc/sys/net/core/somaxconn', '65535');
@corporatepiyush
corporatepiyush / rsa.dart
Created September 11, 2025 10:29
RSA 2048 Key Algo
import 'dart:typed_data';
import 'dart:math';
// SIMD-optimized big integer operations using Float32x4 and Int32x4
class SIMDBigInt {
static final _rng = Random.secure();
// Convert regular int to SIMD-friendly chunks
static Float32x4List toFloat32x4List(List<int> values) {
final padded = List<int>.from(values);