Skip to content

Instantly share code, notes, and snippets.

View vladris's full-sized avatar
🤠

Vlad Riscutia vladris

🤠
View GitHub Profile
@vladris
vladris / gol.ts
Last active June 11, 2022 17:17
Game of Life visualization
// Game of Life cell matrix wrapped in an object
type Matrix = {
m: boolean[][]
wrap: boolean;
};
// Makes matrix of desired width x height plus an initial configuration of "on" cells and wrap-around flag
function makeMatrix(width: number, height: number, initialConfig: [number, number][], wrap: boolean) {
let m = new Array<boolean[]>(height);
@vladris
vladris / timsort.py
Created December 30, 2021 19:04
Python Timsort implementation based on the OpenJDK Java implementation
MIN_MERGE = 32
MIN_GALLOP = 7
minGallop = MIN_GALLOP
def minRunLength(n):
r = 0
while n >= MIN_MERGE:
r |= n & 1
n >>= 1
@vladris
vladris / timeline.csv
Last active September 5, 2021 23:12
Timeline table
Timestamp KeyType KeyValue EventType EventProperties
2020-06-01T00:00:00Z CustomerId 1001 Subscription-Create {"SubscriptionId": "fd10b613-8378-4d37-b8e7-bb665999d122"}
2020-07-01T00:00:00Z Support-CustomerId 21 SupportTicket-Opened {"Message": "..."}
2020-07-03T00:00:00Z Support-CustomerId 21 SupportTicket-Opened {"Message": "..."}
2020-07-05T00:00:00Z Support-CustomerId 21 SupportTicket-Closed {"Message": "..."}
2020-07-19T00:00:00Z Support-CustomerId 21 SupportTicket-Closed {"Message": "..."}
2020-07-19T00:00:00Z CustomerId 1001 Subscription-Close {"SubscriptionId": "fd10b613-8378-4d37-b8e7-bb665999d122"}
@vladris
vladris / keyring.csv
Created May 28, 2021 17:01
Keyring content
GroupId KeyType KeyValue
f03c9e90-5d97-4a11-82aa-480f74325a2c CookieId 657d31b9-0614-4df7-8be6-d576738a9661
62159798-2447-41e3-b0ef-f1a239d55978 CookieId 0864c60d-cc36-4384-81a3-e4c1eee14fe7
f03c9e90-5d97-4a11-82aa-480f74325a2c ProfileId 10002
62159798-2447-41e3-b0ef-f1a239d55978 ProfileId 10003
f03c9e90-5d97-4a11-82aa-480f74325a2c Email emma@hotmail.com
62159798-2447-41e3-b0ef-f1a239d55978 Email oliver@hotmail.com
f03c9e90-5d97-4a11-82aa-480f74325a2c SupportCustomerId 21
62159798-2447-41e3-b0ef-f1a239d55978 SupportCustomerId 22
f03c9e90-5d97-4a11-82aa-480f74325a2c CustomerId 1001
@vladris
vladris / prune.cmd
Created January 3, 2019 00:40
Prune already deleted files from git history
git log --diff-filter=D --name-only --pretty="format:" > ..\FILES
for /f "tokens=*" %%a in (..\FILES) do (
git filter-branch --tag-name-filter cat --index-filter "git rm -r --cached --ignore-unmatch %%a" --prune-empty -f -- --all
)
@vladris
vladris / bf.cpp
Last active June 12, 2019 10:36
Tiny Brainfuck interpreter
#include <array>
#include <fstream>
#include <iostream>
using namespace std;
const size_t memory_size = 1024;
template <typename It>
It& skip(It&& it, char from, char to) {
@vladris
vladris / peano.h
Created August 16, 2018 01:43
Peano arithmetic in C++ type system
#include <type_traits>
// Natural numbers
struct nat { };
// Typed only if T is derived from nat
template <typename T>
using nat_only = std::enable_if_t<std::is_base_of<nat, T>::value>;
// Zero is a natural number
@vladris
vladris / GenericOverloading.java
Last active September 16, 2018 14:46
Overloading methods with generic arguments
// Since generics in Java are removed at compile-time, we cannot overload methods
// based on generic types
// Below class does not compile:
// Erasure of method Foo(T1) is the same as another method in type Test<T1,T2>
// Erasure of method Foo(T2) is the same as another method in type Test<T1,T2>
class Generic<T1, T2> {
void Foo(T1 arg) {
}
@vladris
vladris / kami.py
Created April 15, 2018 16:09
Python solution for Kami 2 puzzle
class Graph:
def __init__(self, nodes=dict(), edges=[]):
self.nodes = nodes
self.edges = edges
self.colors = len(set(nodes.values()))
def connected(self, node):
for edge in self.edges:
if edge[0] == node:
yield edge[1]
@vladris
vladris / bridge.py
Last active January 6, 2018 16:29
Solution for Adevent of Code 2017/Day 24
components = [tuple(map(int, line.strip().split('/'))) for line in open("input.txt").readlines()]
def best_bridge(end, components):
result = 0
for i, c in enumerate(components):
if end == c[0]:
new_end = c[1]
elif end == c[1]:
new_end = c[0]
else: