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 / 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
'BLD18qQhOwEylkVki91hjILTcIwbEMhUHamjkAzgyIWnl1tqOZvO+7AvOTqn036uyHAQVVbSH3/BzYMjNHTMXvogJBWI1siiMZF2zFzD0GEpuGdF+WbSIrug4fzHojQ/AAaBx2HT/tZ8hP+ITRc8z9a7ecsrGX+EBq+b3mada6zeJPxE2j47psb/J4Xnx0AEfh+lEb2GLpczI7e3o0BGP9GlmQYPSXINq87N2D8G175+cBwbMmzdfsIxr9hNGJgLGTFe/NdMP6NoAERNJOij9vzbgwiaOpdvmqBkV2HLp//Pj28HgIc392BrzFQ/slGN0/TqxugL1UY9GMpmI+GQVDSMzswGVWZ5VMjs4sSvkAmQ/p5AnrRyDoszxO+SKI5HV+OwHS0G7NcKXUMCx32xk6mVNxcpl0DwivGhJuvk/gphiG0b2f0gciQaaDJzuOJASND397ryTg4EuRYRw8D2A1lNF5lGEkzxMCGi56t4zCLduBcROWbbjBKKZer6enhbgsEytVBmzo4ONfQ+ZFv3sLhaEb72lnMkVKDD3tw7hzAoL86ObHGLOEGMUY3n9wihn1peBNBTcL3kSfH4/t9KF4qZ3GtXA++WO1h5/0edqVhDygXMUzQ87EZvcGuqLMk6iR08pFBO529aAADg8o9hHKfspYvwghDW/5HtJGL7CrGpE4Sr8FnvNvv7J3AGa9csWrhMB00P/dupnCafDuJAeCgFL0l'