Skip to content

Instantly share code, notes, and snippets.

Avatar

Danylo Hlynskyi danbst

View GitHub Profile
@danbst
danbst / alphabetize.py
Last active Jan 19, 2021
Пачка програм
View alphabetize.py
"""
Алфавіт-квіз, автор Al Sweigart al@inventwithpython.com, переклав Данило (danbst)
"""
import random, time
QUESTION_SIZE = 5
QUIZ_DURATION = 30
abc = {}
@danbst
danbst / maze.py
Created Nov 20, 2020
Maze generation using Randomized Prim's algorithm
View maze.py
def maze(width=10, height=10):
def sides(field, x, y):
sides_ = []
if x > 0:
sides_.append((-1,0))
if x < len(field[y]) - 1:
sides_.append((1,0))
if y > 0:
sides_.append((0,-1))
if y < len(field) - 1:
@danbst
danbst / swap.js
Created Nov 5, 2020
draw swap/rotation animation using p5.js
View swap.js
var figures = [];
var size = 50;
var margin = 1.5;
var postprocessed = false;
var centerX = 0;
let names = ["a", "b", "c", "d", "e", "f"];
function addFigure(col) {
figures.push([figures.length * size * margin, 0, col]);
}
@danbst
danbst / fire.py
Created Sep 18, 2020
FIRE retro x80 Python numpy FTW
View fire.py
import pygame
import random
import colorsys
import numpy as np
from pygame import surfarray
def color_HSL(h, s, l):
color = colorsys.hls_to_rgb(h/255, l/255, s/255)
return tuple( int(x*255) for x in color )
@danbst
danbst / README.md
Created May 24, 2020
monkey ZNO simulation
View README.md

Results:

Cumulative distribution method (2019, by Taras Pavlov): 0.08891278153876137                                                                                                                                          
Simulation method (2019): 0.09003                                                                                                                                                                                    
Total simulation method (2019): 0.09858                                                                                                                                                                              
Total simulation method (2020): 0.04539                                                                                                                                                                              
View many_timers_telegram.py
# all users, key is chat.id
user_settings = {}
# user chat settings
class UserChat:
timers = {} # all timers. Key is timer ID, defined arbitrary
state = None
id = None # chat.id
def tick(self, current_time):
View gen.py
def generate_users_str(db, config, with_orders=False, with_ids=False):
all_s = []
total_orders = 0
if with_orders:
for user in db:
id_prefix = f"{user['telegram_id']} - " if with_ids else ""
is_ordered = user.get('order_food', config['DEFAULT_ORDER'])
if is_ordered:
total_orders += 1
@danbst
danbst / home-etc.nix
Created Dec 27, 2019
Manage your /etc from home-manager (install home-manager as root)
View home-etc.nix
{ config, pkgs, lib, ... }: {
imports = [
(import <nixpkgs/nixos/modules/system/etc/etc.nix>)
];
options.system.build.etc = lib.mkOption { type = lib.types.package; };
options.system.activationScripts.etc =
lib.mkOption { type = lib.types.unspecified; };
config = {
View nix-remote-build.md

Okay, I've got a need to build Firefox from source, and I'd like to do that on a remote machine, and then copy build result back to my laptop. With Nix, using bastion host. I'll note details of my successful adventure.

Setup & Sources of knowledge

Here's the list of resources I've used actively:

Here's my setup:

@danbst
danbst / README.adoc
Created Sep 5, 2019
Pure Nix Minecraft launcher. For every MC version!
View README.adoc

Pure Nix Minecraft launchers

  1. Download .nix file

  2. Run:

    $ nix run -f all-minecrafts.nix versions.v1_8_9.client -c minecraft
  3. Enjoy (…​power of fixed-output derivations)!