Skip to content

Instantly share code, notes, and snippets.

@cyingfan
cyingfan / 00.md
Last active December 16, 2021 15:28
Advent of Code 2021

Advent of Code 2021 solutions that run in browser

https://adventofcode.com/2021

Running instruction

  • Open puzzle input URL in browser.
  • Start developer console.
  • Paste code into the console.
@cyingfan
cyingfan / .AoC2020.md
Last active December 8, 2020 13:54
Advent of Code 2020

Advent of Code 2020 solutions that run in browser

@cyingfan
cyingfan / MiracleBoard.py
Last active May 26, 2020 02:30
(Miracle) Sudoku Solver
from copy import deepcopy
from time import time
from typing import Dict, Optional, Set, Tuple
class Cell:
def __init__(self):
self.possibilities: Set[int] = set(range(1, 10))
self._update()
# import nltk
# import nltk.tokenize
import random
import re
#import requests
# reg = r'<a href="/title/[^"]+"\n>([^<]+)</a>'
# r = requests.get('https://www.imdb.com/list/ls033759520/?sort=list_order,asc&st_dt=&mode=simple&page=1&ref_=ttls_vw_smp')
# movies = re.findall(reg, r.text)
# alltext = " ".join(movies).strip()
@cyingfan
cyingfan / BaseConv.py
Last active July 12, 2018 08:47
Base converter
from collections import OrderedDict
class BaseConv:
def __init__(self, charset:str):
self.charset = OrderedDict.fromkeys(charset)
i = 0
for k in self.charset:
self.charset[k] = i
i += 1
self.charset_string = ''.join(self.charset.keys())
@cyingfan
cyingfan / _readme.md
Last active May 29, 2021 11:13
Cure to Golden Ratio OCD on Humble Bundle

Set the humble bundle payment portions to follow golden ratio

TLDR

  1. Copy paste the content from bundlecalculator.min.js into developer console.
  2. Run set_ratio(15). Replace 15 to any figure you wish to pay.

Additional parameters

Disable full allocation to user selected charity

Enabled by default. To disable the behaviour, set second parameter to false, e.g. set_ratio(15, false).

@cyingfan
cyingfan / pandabuiltin.py
Last active January 18, 2018 05:21
data size in python
import json
from glob import iglob
import resource
dflist = []
for i in iglob('./data/FULL/data/visits*.json'):
print(i)
dflist.append(json.load(open(i, 'r')))
print(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
@cyingfan
cyingfan / DeepThoughtSimulator.php
Last active December 29, 2017 06:50
Deep Thought Simulator
<?php
class DeepThoughtSimulator
{
public function getAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()
{
sleep(7500000 * 365.24219 * 24 * 60 * 60);
return 42;
}
public function __call($name, $arguments)
@cyingfan
cyingfan / spiral.py
Last active August 5, 2016 09:46
spiraling number in python
class Spiral(object):
def __init__(self, xsize=4, ysize=None):
self.xsize = xsize
self.ysize = xsize if ysize is None else ysize
self.x = 0
self.y = -1
self.vx = 0
self.vy = 1
self.max = self.xsize * self.ysize
self.init_board()