Skip to content

Instantly share code, notes, and snippets.

View pprzetacznik's full-sized avatar

Piotr Przetacznik pprzetacznik

View GitHub Profile
@pprzetacznik
pprzetacznik / timeit.py
Created November 15, 2023 10:41
timeit
import time
from pytest import fixture
def timeit(iterations_num=10_000):
def wrapper(fun):
def nested_wrapper(*args, **kwargs):
start = time.time()
for i in range(iterations_num):
result = fun(*args, **kwargs)
@pprzetacznik
pprzetacznik / context_managers.py
Last active February 3, 2022 12:10
Context Managers in Python
import pickle
class Board:
def __init__(self):
self.board = [['.']*3 for i in range(3)]
def mark(self, x, y, sign):
self.board[x][y] = sign
import heapq
import time
from collections.abc import Callable
from typing import Any
class _Cache:
def __init__(self, my_fun: Callable, cache_limit: int = 3) -> None:
self.cache_limit = cache_limit
self.my_fun = my_fun
@pprzetacznik
pprzetacznik / tests.py
Created February 7, 2021 11:46
Testing in Python
# https://stackoverflow.com/questions/652276/is-it-possible-to-create-anonymous-objects-in-python
from typing import Dict
class MicroMock:
def __init__(self, **kwargs: Dict) -> None:
self.__dict__.update(kwargs)
MicroMock(text="aaa")
@pprzetacznik
pprzetacznik / wsl2_clipboard.md
Last active May 3, 2022 20:39
Clipboard with WSL2 and remote hosts

Clipboard with WSL2 and remote hosts

  1. How to copy from vim to windows clipboard?
  2. How to copy from tmux to windows clipboard?
  3. How to copy from remote tmux/vim to windows clipboard?

Install VcXsrv

Config on host

@pprzetacznik
pprzetacznik / ant.js
Last active December 4, 2015 09:54
ant.js
function anonymous() {
var world = new CAWorld({
width: 192,
height: 128,
cellSize: 3
});
world.palette = [
'68, 36, 52, 1',
@pprzetacznik
pprzetacznik / blog.sh
Created November 27, 2015 17:01
Error during preparing release for blog
[pankracy@piotrek-fedora blog]$ MIX_ENV=prod mix release
Building release with MIX_ENV=prod.
You have dependencies (direct/transitive) which are not in :applications!
The following apps should to be added to :applications in mix.exs:
earmark => earmark is missing from blog
Continue anyway? Your release may not work as expected if these dependencies are required! [Yn]:
@pprzetacznik
pprzetacznik / maraton.r
Created July 22, 2015 22:11
Maraton danych - eRka Kraków
library(dplyr)
data <- read.csv("gau12jbs Master 100715.csv", header=TRUE)
names <- select(data, starts_with("RV"), starts_with("RC"), starts_with("SW"), starts_with("SN"), starts_with("WC"), starts_with("AP"), starts_with("PH"), starts_with("SD"), starts_with("SY"), starts_with("RH"), starts_with("FS") ) %>%
na.omit %>%
row.names
train_names <- sample(names, length(names) * 7/10, replace = FALSE)
test_names <- setdiff(names, train_names)
iex(38)> map
%{"key" => "value"}
iex(39)> Poison.Encoder.encode(map, [])
[123, [[34, ["key"], 34], 58, [34, ["value"], 34]], 125]