Skip to content

Instantly share code, notes, and snippets.

Avatar

Danylo Hlynskyi danbst

  • Ivano-Frankivsk, Ukraine
View GitHub Profile
@danbst
danbst / fire.py
Last active Nov 11, 2021
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)!

View asciidoc.adoc

Hey let’s start a list:

  1. Yeah, all good.

    a bit of code.
    Oh wow, it is indented compared to markdown!

    A bit of text. Wow, it is indeted as well!

@danbst
danbst / README.md
Last active Mar 22, 2022
[Linux] [Firefox] Open link in browser, which is in current workspace
View README.md

I use separate Firefox profiles for work and personal stuff. To distinguish those I place them on different workspaces.

  • Workspace 0: firefox --no-remote -P MyJob
  • Workspace 1: firefox --no-remote -P default

I have also company Slack on Workspace 0. Which usually contains links to some work stuff.

The problem

@danbst
danbst / uuid-bloom.sql
Created Apr 27, 2019
Postgresql UUID Bloom index support (best for UUIDv4) (https://www.postgresql.org/docs/current/bloom.html)
View uuid-bloom.sql
create extension "uuid-ossp";
-- https://www.postgresql.org/docs/current/bloom.html
create extension bloom;
CREATE or replace FUNCTION hashuuid(u uuid) RETURNS integer AS $$
DECLARE
a bytea := uuid_send(u);
BEGIN
RETURN (get_byte(a, 3) << 24) + (get_byte(a, 2) << 16) + (get_byte(a, 1) << 8) + get_byte(a, 0);
END;