Skip to content

Instantly share code, notes, and snippets.

View andiac's full-sized avatar
🦄
Yooooooooo

Andi Zhang andiac

🦄
Yooooooooo
View GitHub Profile
@andiac
andiac / hanoi.cpp
Last active October 21, 2018 13:36
Hanoi Tower
#include <stdio.h>
struct stack {
int v[100];
int top;
} stacks[3];
int N;
void push(struct stack * a, int v) {
@andiac
andiac / count_path_grid.py
Last active March 1, 2019 22:42
Replicating "Counting the Paths on a Grid" by Donald Knuth in 1976 (An example of importance sampling)
'''
c style python because of the consideration of efficiency, please use pypy3 instead of python3!
This is a replication of "Counting the Paths on a Grid" introduced in the paper "Coping with Finiteness"
(Donald E. Knuth, 1976). This program estimates the number of self-avoiding paths on a 10×10 grid,
starting from the point(0, 0) and ending at the point(10, 10).
~ pypy3 count_path_grid.py
1.5810562057001226e+24
@andiac
andiac / pdf_merge.py
Last active January 30, 2020 16:01
Merge PDF
import glob
from PyPDF2 import PdfFileMerger
def merger(output_path, input_paths):
pdf_merger = PdfFileMerger()
file_handles = []
for path in input_paths:
pdf_merger.append(path)
@andiac
andiac / eduroam_rasp.py
Last active December 23, 2019 22:45
pi scroll bot
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
* **************************************************************************
* Contributions to this work were made on behalf of the GÉANT project,
* a project that has received funding from the European Union’s Framework
* Programme 7 under Grant Agreements No. 238875 (GN3)
* and No. 605243 (GN3plus), Horizon 2020 research and innovation programme
* under Grant Agreements No. 691567 (GN4-1) and No. 731122 (GN4-2).
* On behalf of the aforementioned projects, GEANT Association is
@andiac
andiac / ac_automaton.py
Created December 17, 2019 22:50
Aho-Corasick Automaton
from collections import deque
class TrieNode:
def __init__(self, endWord = False, parent = None, char = ''):
# to record duplicate words
self.count = int(endWord)
self.children = dict()
# fail pointer of Aho Corasick Automaton
self.fail = None
# recording the parent in order to output the matched concept
@andiac
andiac / IcdfBeta.ipynb
Created December 18, 2019 22:57
Pytorch Autograd Function for the Inverse CDF of Beta Distribution (numerical deriviation)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@andiac
andiac / cross_validation_std.ipynb
Last active January 18, 2020 21:02
cross_validation?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@andiac
andiac / qsort.py
Last active March 8, 2020 23:59
Some sorts
import random
import sys
import time
# sys.setrecursionlimit(10000)
def qsort(a):
if len(a) <= 1: return a
pivot = random.choice(a)
left = qsort([x for x in a if x < pivot])
/*
* Copyright (C) 2020-2021 Andi Zhang <me@andi.ac>
*/
#include <iostream>
using namespace std;
class MyInt {
public:
@andiac
andiac / retroarch.cfg
Created November 6, 2020 05:55
Clockwork os 0.5 default retroarch settings
ai_service_enable = "false"
ai_service_mode = "0"
ai_service_pause = "false"
ai_service_source_lang = "0"
ai_service_target_lang = "0"
ai_service_url = "http://localhost:4404/"
all_users_control_menu = "true"
apply_cheats_after_load = "false"
apply_cheats_after_toggle = "false"
aspect_ratio_index = "0"