Skip to content

Instantly share code, notes, and snippets.

@oversider-kosma
oversider-kosma / hexlet_snail.js
Created September 28, 2023 15:13
hexlet snail
function* go_right(matrix, x, y, times) { for (let x_=x; x_ < x+times; x_++) yield matrix[y][x_]; }
function* go_left(matrix, x, y, times) { for (let x_=x; x_ > x-times; x_--) yield matrix[y][x_]; }
function* go_up(matrix, x, y, times) { for (let y_=y; y_ > y-times; y_--) yield matrix[y_][x]; }
function* go_down(matrix, x, y, times) { for (let y_=y; y_ < y+times; y_++) yield matrix[y_][x]; }
function* iter_snail(M) {
let cnt = 0;
let i = -1;
let funcs = [go_right, go_down, go_left, go_up];

Keybase proof

I hereby claim:

  • I am oversider-kosma on github.
  • I am oversider_kosma (https://keybase.io/oversider_kosma) on keybase.
  • I have a public key whose fingerprint is 4DAE 81A1 43B0 AB8D B219 DFF6 48CC 607F 6876 1646

To claim this, I am signing this object:

@oversider-kosma
oversider-kosma / build_superkaramba_to_bullseye.sh
Last active March 12, 2020 13:16
Builds inside buster-chroot superkaramba and fetch buided package out of chroot
#!/bin/bash
#
# - create a buster-chroot,
# - Build supercaramba there,
# - fetch builded binary and required libraries to package
# - fetch package out of chroot
# - remove chroot
set -e
@oversider-kosma
oversider-kosma / set_wallpaper
Created February 28, 2020 20:32 — forked from mamantoha/set_wallpaper
Set desktop wallpaper in Plasma5 via a dbus command
qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript 'var allDesktops = desktops();print (allDesktops);for (i=0;i<allDesktops.length;i++) {d = allDesktops[i];d.wallpaperPlugin = "org.kde.image";d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");d.writeConfig("Image", "file:///path/to/image.png")}'
@oversider-kosma
oversider-kosma / dataclass_like_auto_init.py
Created June 21, 2019 02:17
When to lazy to do simple assigments.
#!/usr/bin/env python2
class SomeClass(object):
def __init__(self, an_attribute, another_attribute, attr_with_name_to_hard_to_write,
hate_to_write_stupid_identical_assignments,
so_lazy_to_write_self_many_times, no_dataclasses_in_py2,
what_can_we_do_with_a_drunken_sailor, here_is_a_solution,
kak_tebe_takoe_Elon_Musk):
(lambda l: [setattr(self, attr, l[attr]) for attr in
filter(lambda x: x != 'self',
@oversider-kosma
oversider-kosma / so_dangerous_comma.py
Created October 27, 2018 01:47
Multiple assignment and dict
#!/usr/bin/env python
def key_first():
dct = {}
key = 'foo'
key, dct[key] = 'some_new_key', 'bar';
return dct
def dict_first():
dct = {}
@oversider-kosma
oversider-kosma / count_occurrences.py
Last active October 21, 2018 15:35
Counts the appearance of a word in a (probably large) file or stream, reading it by chunks.
#!/usr/bin/python
"""Counts the appearance of a word in a (probably large) file or stream reading it by chunks."""
import os
import sys
from time import time
DEFAULT_CHUNK_SIZE = 2048
REPORT_EVERY_SECS = 1