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 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 / 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:
@unixpickle
unixpickle / reductions.md
Last active October 30, 2023 21:28
Global reduction speed

Benchmarking global reductions with varying numbers of SMs and warps per SM. We find interesting facts, like that using one warp across more SMs is more efficient than more warps across a single SM.

These were computed on an NVIDIA Titan X GPU.

Code for the benchmark is here and the kernel is here.

1 warps
@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 / guess_the_number.ipynb
Created August 12, 2023 22:57
Guess the number
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@unixpickle
unixpickle / main.go
Created December 3, 2017 20:20
Jane Street problem
// Solves this problem: http://1mage.us/1339.
package main
import (
"fmt"
"math"
"math/rand"
"sort"
@unixpickle
unixpickle / char_poly.py
Created May 17, 2022 16:34
Characteristic polynomial
"""
Compute the closed-form characteristic polynomial of a 4x4 matrix.
"""
import sympy
syms = sympy.symbols('a b c d e f g h i j k l m n o p')
mat = sympy.Matrix([[syms[i+j*4] for i in range(4)] for j in range(4)])
print(sympy.collect((mat - sympy.eye(4)*sympy.symbols('x')).det(), 'x'))
# a*f*k*p - a*f*l*o - a*g*j*p + a*g*l*n + a*h*j*o - a*h*k*n - b*e*k*p + b*e*l*o + b*g*i*p - b*g*l*m - b*h*i*o + b*h*k*m + c*e*j*p - c*e*l*n - c*f*i*p + c*f*l*m + c*h*i*n - c*h*j*m - d*e*j*o + d*e*k*n + d*f*i*o - d*f*k*m - d*g*i*n + d*g*j*m + x**4 + x**3*(-a - f - k - p) + x**2*(a*f + a*k + a*p - b*e - c*i - d*m + f*k + f*p - g*j - h*n + k*p - l*o) + x*(-a*f*k - a*f*p + a*g*j + a*h*n - a*k*p + a*l*o + b*e*k + b*e*p - b*g*i - b*h*m - c*e*j + c*f*i + c*i*p - c*l*m - d*e*n + d*f*m - d*i*o + d*k*m - f*k*p + f*l*o + g*j*p - g*l*n - h*j*o + h*k*n)
@unixpickle
unixpickle / plexdblist.sh
Created July 10, 2012 23:26
List all of the items in Plex (w/ view count)
#!/bin/bash
#
# Simply pass in your plex library database file and have some fun!
# NOTE: your DB file is probably called "com.plexapp.plugins.library.db"
#
if [ $# != 1 ]; then
echo "plexdblist - lists the media items in a plex DB file."
echo "Usage: plexdblist <database>"
exit 1
@unixpickle
unixpickle / argcount.pl
Created November 5, 2010 02:33
count the number of command-line arguments in perl
#!/usr/bin/perl
use strict;
sub arrcount {
my ($arr) = @_;
my $c = 0;
foreach my $str (@{$arr}) {
++$c;
}
@unixpickle
unixpickle / egg_balance.py
Created November 21, 2021 14:33
Egg balance
import numpy as np
rows = 3
cols = 6
# Create all 2^(rows*cols) combinations of egg matrices.
all_combos = np.zeros([1] * (rows * cols + 2), dtype=np.float32)
for i in range(rows * cols):
m = np.zeros([2, rows * cols], dtype=np.float32)
m[1, i] = 1