Skip to content

Instantly share code, notes, and snippets.

View leegao's full-sized avatar

Lee Gao leegao

  • Google
  • Jersey City, NJ
View GitHub Profile
@leegao
leegao / ai.sh
Created April 16, 2025 22:42
Pair Bashing with Gemini
#!/bin/bash
PPID1=$(ps -o ppid= "$$" | tr -d ' ')
PPID2=$(ps -o ppid= "$PPID1" | tr -d ' ')
PARENT=$(ps -p "$PPID2" -o comm=)
if [ -z "$1" ]; then
if [ "$PARENT" != "script" ] ; then
export HISTORY_FILE=$(mktemp)
echo "Run with history ($HISTORY_FILE), don't forget to ctrl+D"
@leegao
leegao / RPNJit.py
Created November 10, 2016 23:31
Ahead-of-time RPN compiler.
import ctypes, mmap, struct
DEBUG = True
try:
VirtualAlloc = ctypes.windll.kernel32.VirtualAlloc
raise Exception("Windows not supported.")
except(AttributeError):
libc = ctypes.CDLL("libc.so.6")
libc.valloc.restype = ctypes.c_void_p
def valloc(size):
addr = libc.valloc(size)
@leegao
leegao / RPNJit.py
Created November 10, 2016 23:05
Ahead-of-time compiled RPN for /r/DailyProgrammer
import ctypes, mmap, struct
DEBUG = True
try:
VirtualAlloc = ctypes.windll.kernel32.VirtualAlloc
raise Exception("Windows not supported.")
except(AttributeError):
libc = ctypes.CDLL("libc.so.6")
libc.valloc.restype = ctypes.c_void_p
def valloc(size):
addr = libc.valloc(size)
import re
from itertools import permutations
class Instance(object):
def __init__(self, groups):
self.groups = (tuple(groups[0]), tuple(groups[1]))
self.level = len([0 for group in groups for _ in group]) // 3
reserved = ''.join([x for group in groups for triplet in group for x in triplet if x is not 'x'])
self.residuals = ''.join([str(i) for i in range(1, 10) for _ in range(self.level - reserved.count(str(i)))])
def getAllNeighbors(origin, steps = 1):
seen = {origin}
worklist = [origin]
while steps:
new_worklist = []
for next in worklist:
seen.add(next)
for neighbor in next.get_all_neighbors(15):
if neighbor not in seen: new_worklist.append(neighbor)
worklist = new_worklist
\documentclass[11pt,a4paper,svgnames]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb,amsthm}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{algorithm}
\usepackage{algorithmicx}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@leegao
leegao / patch.c
Last active February 26, 2016 23:20
// Let's not mangle these names
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include <sys/mman.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@leegao
leegao / patch.c
Last active February 26, 2016 23:32
Null-packet protection
// Let's not mangle these names
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include <sys/mman.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
// Let's not mangle these names 0x0819ec3c
extern "C" {
#include <lua5.2/lua.h>
#include <lua5.2/lauxlib.h>
#include <sys/mman.h>
#include <stdio.h>
#include <limits.h>
#ifndef PAGESIZE
#define PAGESIZE 4096