Skip to content

Instantly share code, notes, and snippets.

Danylo Hlynskyi danbst

Block or report user

Report or block danbst

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danbst
danbst / README.md
Last active Jun 19, 2019
[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;
@danbst
danbst / background-script.js
Created Mar 30, 2019
Firefox extension, which tracks time spent in Facebook and tells it to you INSTANTLY.
View background-script.js
timeSpent = 0;
timeStarts = 0
browser.tabs.onActivated.addListener((activeInfo) => {
browser.tabs.sendMessage(
activeInfo.tabId,
{timeSpent: timeSpent}
).then(response => {
timeStarts = (new Date).getTime();
}).catch(error => {
View submodule-with-parent-config.nix
let
sub = { config, lib, parentConfig, ...}: {
options.foo = lib.mkOption {
type = lib.types.bool;
default = parentConfig.bar;
};
};
in { config, lib, ...}: {
options.bar = lib.mkOption { type = lib.types.bool; default = true; };
@danbst
danbst / all-packages.nix
Created Jan 19, 2019
Overlays in nixpkgs!
View all-packages.nix
...
inherit (import ../servers/sql/postgresql-default.nix pkgs super)
postgresql
postgresqlPackages
postgresql_9_4
postgresql_9_5
postgresql_9_6
postgresql_10
postgresql_11
@danbst
danbst / idea.md
Last active Jan 17, 2019
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 / imperative-env.sh
Last active Mar 5, 2019
Imperative nix-env rewrite (so it becomes declarative)
View imperative-env.sh
#!/usr/bin/env bash
statefile=~/.config/nixpkgs/declarative
action="$1"
package="$2"
mkdir -p $(dirname "$statefile")
touch "$statefile"
function update {
envExpr=~/.config/nixpkgs/declarative-env.nix
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 / 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 / bash-curl-pup-jq-notifysend-nix.md
Created Jul 19, 2018
Bash. Curl. Pup. Jq. Notify-send. Nix
View bash-curl-pup-jq-notifysend-nix.md

Цей список складений з технологій (утиліт Linux), які я використаю для однієї життєвої ситуації - пошуку аренди квартири по риночній ціні.

Знайомим з поняттям "скрейпінг" мабуть уже зрозуміло, про що буде пост. Тим не менше, запрошую під кат.

Постановка задачі

OLX є, здається, найактивнішою площадкою для пошуку аренди квартири у Києві. Але просто зайти на OLX, задати фільтри (район, кількість кімнат) недостатньо. Справа в тім, що є 3 типи аренд:

  • аренди від ріелторів - ціни на ці квартири майже завжди завищені, тому-що від ціни квартири залежить дохід ріелтора. Через завищену вартість (неринкову) афіші висять відносно довго
  • аренди від хазяїв - ціни на квартири нижчі, щоб швидше знаходити арендаторів
You can’t perform that action at this time.