Skip to content

Instantly share code, notes, and snippets.

Avatar

Danylo Hlynskyi danbst

View GitHub Profile
View postgresql-vacuum-freeze.md

VACUUM FREEZE

Our database has fast rate of transactions. I did think, that such rate is impossible, until I've seen it with my eyes. I've been instinctively insisting on fixing code to reduce number of transactions (sometimes successful), but never checked what are consequences for database.

One of consequences is fast rate of autovacuum VACUUM FREEZE.

VACUUM is essential for Postgresql to mark non-visible rows (those which were normal rows, but became invisible because of update or delete) as visible to PG. Note, that they become visible only to PG, previously PG didn't know they are free for use, and thus had allocated extra buffers in the end of a table for any new rows (inserts or updates). PG not knowing which rows are free for use is another problem, which causes table bloat, which deserves another post.

VACUUM FREEZE is special kind of VACUUM. From resource usage perspective, it differs from VACUUM by that it has to scan full table (normal VACUUM processes only buffers known to contain at

@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)!

@danbst
danbst / iphone.nix
Created Sep 8, 2018
iPhone pairing for NixOS
View iphone.nix
# First add this module to your /etc/nixos/configuration.nix
# ...
# imports = [ /path/to/iphone.nix ];
# iphone.enable = true;
# iphone.user = "yourusername";
# ...
# Then rebuild system. Attach iPhone via cable, open terminal and run command `iphone`
# It will fail, but there will occure a dialog on your iPhone to "trust this computer"
# Press OK there and run `iphone` again. If it succeeds it will open a freshly mounted folder
@danbst
danbst / idea.md
Last active May 27, 2020
Nixos need a replacement for nixos-rebuild!
View idea.md

nixos executable

Basic features:

  • installable as package, even on non-nixos
  • is named nixos
  • is written in C++ and binds to Nix C++ library (or maybe Haskell? Nodejs? What you think?)
  • autocomplete, ncurses, Nix 2.0
  • commit to Git by default on each rebuild

Subcommands

@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 switch-NixOS-32bit-to-64bit.md

Switching NixOS architecture (32bit -> 64bit)

There are rumors, that you can switch from system architecture just adding 1 configuration option:

nixpkgs.system = "x86_64-linux"

and running nixos-rebuild boot && reboot.

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 / README.md
Last active Mar 7, 2020
nixq - jq but with Nix syntax
View README.md

nixq - jq but with Nix syntax

Familliar syntax and all of <nixpkgs/lib> and builtins in your hands.

Now going through jq tutorial:

Identity filter

$ # jq
@danbst
danbst / onsub.py
Created May 24, 2016
Mercurial 3.8+ compatible onsub extension
View onsub.py
# onsub.py - execute commands recursively on subrepositories
#
# Copyright 2010, 2011 aragost Trifork
#
# This software may be used and distributed according to the terms of
# the GNU General Public License version 2 or any later version.
import os
from mercurial.i18n import _
from mercurial import extensions, subrepo, util, cmdutil
You can’t perform that action at this time.