Skip to content

Instantly share code, notes, and snippets.

View unixpickle's full-sized avatar

Alex Nichol unixpickle

View GitHub Profile
@unixpickle
unixpickle / README.md
Created November 3, 2025 15:31
Fil-C race allows access to incorrect buffer.

What happens

Compile with Fil-C and run it a few times. Most of the time, it will trap. However, every few times, it will print "secret password".

This covers the scenario where a malicious user causes a program to leak information using an overflowing offset. Typically Fil-C will mitigate this kinds of thing with a bounds check. However, a data race can cause the bounds on a pointer to be incorrect.

Why this is a realistic issue

@unixpickle
unixpickle / README.md
Last active July 24, 2025 20:57
Solve TSP with 2-opt and multiple random seeds

Results

First, I tested on berlin52. The program occasionally finds the optimal solution, usually taking a few hundred iterations.

Next, I tested a 127-city problem, bier127.tsp. I started with 1,000 initial random routes.

The optimal solution is known to be of length 118282, but the optimal solution found by the program is 121950. This is ~3% above optimal.

@unixpickle
unixpickle / LU.swift
Created June 19, 2025 19:56
LU factorization
import Accelerate
private let Epsilon: Double = 1e-8
private enum LUFactorizationResult {
case success(LUFactorization)
case singular(Int)
}
private struct LUFactorization {
@unixpickle
unixpickle / writeup.md
Last active June 6, 2025 19:14
Image Unblur

This example shows how we might blur and unblur 4x4 images. Let b0 through b15 be pixels in a blurred image. For example, the pixel at coordinates (2,3) is b14, since 14 is 2+3*4. Likewise, let the pixels of an unblurred image be x0 through x15.

Whenever we blur an image x into a blurred image b, we average each pixel of x with the pixels around it, giving the corresponding pixel of b. For example:

b5 = 1/5*x1 + 1/5*x4 + 1/5*x5 + 1/5*x6 + 1/5*x9

The output pixel b5 is at (1,1), so we compute it by averaging the pixels at (1,0), (1,2), (2,1), (0,1), and (1,1). This formula is similar for all the other pixels. Thus, we get:

@unixpickle
unixpickle / matching.py
Created June 2, 2025 20:30
Linear programming matching
import numpy as np
from scipy.optimize import linear_sum_assignment, linprog
def main():
n_verts = 20
weights = np.random.uniform(low=0.01, high=1.0, size=(n_verts, n_verts))
print("Using linear programming solution...")
soln = solve_matching_linprog(weights)
@unixpickle
unixpickle / README.md
Created November 14, 2019 20:58
Hacking Lily's Garden

Overview

In this document, I will describe how I managed to get unlimited stars and coins in the Android game "Lily's Garden". In short, here are the steps:

  • Use the adb backup feature to extract all of the game's data
  • Extract the Android backup into a tar file
  • Modify the file which stores the number of coins and stars
  • Re-sign the coins/stars field using a reverse-engineered HMAC key
  • Convert the tar file back to an Android backup
@unixpickle
unixpickle / main.go
Created June 20, 2017 21:03
List Famobi games
// Command famobi_games creates a useful JSON file listing
// all Famobi games and their corresponding tags.
//
// With the resulting JSON, you can easily find all the
// games with a given tag using `jq`:
//
// jq '.[] | select(.categories | contains(["Match 3"]))'
//
package main
@unixpickle
unixpickle / puzzle.go
Created December 24, 2018 23:14
Logic puzzle
// Solve this logic puzzle:
// https://xmonader.github.io/prolog/2018/12/21/solving-murder-prolog.html
package main
import (
"fmt"
"github.com/unixpickle/approb"
)
@unixpickle
unixpickle / maml.py
Created October 12, 2019 19:08
MAML in PyTorch
import torch
import torch.nn.functional as F
def maml_grad(model, inputs, outputs, lr, batch=1):
"""
Update a model's gradient using MAML.
The gradient will point in the direction that
improves the total loss across all inner-loop
@unixpickle
unixpickle / bitonic.py
Created November 8, 2023 00:22
Bitonic sequences
import numpy as np
from tqdm.auto import tqdm
def is_bitonic(xs):
results = []
for seq in xs:
prev = seq[0]
direction = 0
num_changes = 0
for x1 in seq: