Skip to content

Instantly share code, notes, and snippets.

@heolin
heolin / typed_dataset.py
Created February 18, 2022 21:21
Test typed datasets
import numpy as np
from typing import Text, List, TypeVar, Generic, Protocol
T = TypeVar('T')
@dataclass
class ItemPotential(Protocol):
item_id: Text
gmv_eur: float
@heolin
heolin / axiosExample
Created November 25, 2019 15:48
Simple axios example generating html table
<html>
<head>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<table class="table">
<thead>
<th>id</th>
<th>email</th>
@heolin
heolin / event_manager.py
Created November 21, 2019 15:19
Simple event manager in python
class Mom:
def on_door_opened(self):
print("Who's there?")
class Priest:
def on_door_opened(self):
print("Is it police? Run!")
from ahocorapy.keywordtree import KeywordTree
digit2letter = {
0: ["#"],
1: ["#"],
2: ['a', 'b', 'c'],
3: ['d', 'e', 'f'],
4: ['g', 'h', 'i'],
5: ['j', 'k', 'l'],
from ahocorapy.keywordtree import KeywordTree
digit2letter = {
1: [],
2: ['a', 'b', 'c'],
3: ['d', 'e', 'f'],
4: ['g', 'h', 'i'],
5: ['j', 'k', 'l'],
6: ['m', 'n', 'o'],
import tensorflow as tf
import numpy as np
import random
# neural network predicting if input hour is 21:37
# network created with layers of size: [73 21]
# because of small number of neurons if may take few tries to read good results (around 0.98 accuracy)
X, y = [], []
for _ in range(10000):
@heolin
heolin / adjust.py
Created July 4, 2018 22:11
Adjust obj file scale
import os
def adjust_directory(directory_path):
def adjust_file(file_path):
lines = open(file_path).read().split('\n')
scale = 0.1
with open(file_path, "w") as output_file:
for line in lines:
if line.startswith("v "):
splited = line.split(' ')
splited[1] = str(round(float(splited[1]) * scale, 5)-0.5)
from pynput import keyboard
import pyperclip
current = {"tags":[]}
def on_press(key):
global current
try: k = key.char # single-char keys
except: k = key.name # other keys
from pynput import keyboard
import pyperclip
current = {"tags":[]}
def on_press(key):
global current
try: k = key.char # single-char keys
except: k = key.name # other keys
set smartindent " TODO
set tabstop=4
set shiftwidth=4
set expandtab " TODO
set encoding=utf-8
set completeopt=menuone,longest " TODO
set number " Displays line number
set autochdir
set clipboard=unnamedplus