Skip to content

Instantly share code, notes, and snippets.

@KirillLykov
KirillLykov / how-to-use-another-linker-with-rust.md
Created May 24, 2023 14:52
How to set up a linker with rust

In order to speed up your linking stage, you can use a linker that takes advantage of multiple CPU cores.

Such linkers are lld and mold.

mold is considered more cutting edge, but it works for me.

Just add

[build]
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId};
use itertools::Itertools;
use rand::Rng;
type T = u64;
fn sum_1(data: &Vec<T>) -> (T, T, T)
{
let mut sum: (T, T, T) = (T::default(), T::default(), T::default());
for (x,y,z) in data.iter().tuples() {
sum.0 += x;
@KirillLykov
KirillLykov / pre-hook.md
Last active February 22, 2022 13:36
How to set up pre-commit hook

It works for rust and for C++. The difference is that for rust you need to specify rustfmt and for C++ clang-format -i.

  1. Add file pre-commit to the folder .githooks in your repo with the following text:
#!/bin/bash

exe=$(which rustfmt)

if [ -n "$exe" ]

Kitty

  1. Search in kitty text ctrl + shift + h + /

How to disable fn on keyboard

@KirillLykov
KirillLykov / system-performance.md
Last active September 18, 2023 15:02
Systems performance book by B. Gregg

Summary for Systems Performance book by Brendan Gregg

Book it sel on o'reilly

OS-related things

  • Kernel -- software that manages the system by providing access to hardware and other resources (memory, network stack, scheduling cpu, etc). Runs in priveleged CPU mode -- kernel mode. It uses kernel-space stack.
  • Process -- an OS abstraction for running programs. Runs in user mode with access to kernel mode via system calls. It consists of: memory address space, file descriptors, thread stacks, registers. Process uses user-space stacks. For example, syscalls use a s kernel exception stack associated with each thread.
@KirillLykov
KirillLykov / interval-map.md
Created August 15, 2021 09:11
Interval maps -- cheap alternative to segment tree

Given a data stream input of non-negative integers a1, a2, ..., an, summarize the numbers seen so far as a list of disjoint intervals.

The basic idea is to use map : start -> end where end is not inclusive. Invariant is that this map is always disjoint.

lc

class SummaryRanges {
    map<int, int> m; // start to end, [x,y)
@KirillLykov
KirillLykov / radix_msd.md
Last active April 29, 2021 08:50
This is LOG for my MSD Radix Sort experiments

This gist will be to place steps and numbers for optimization of msd radix sort.

Benchmakring for Travis' radix_sort7 LSD radix sort implementation:

CPU Caches:
  L1 Data 32K (x28)
  L1 Instruction 32K (x28)
  L2 Unified 1024K (x28)
  L3 Unified 19712K (x2)
@KirillLykov
KirillLykov / maxLenghtOfSubsetOfStrings.md
Created July 25, 2020 21:13
Nice brute force problem

Nice problem from leetcode: https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/submissions/

Given a set of strings, find a subset of these strings such that:

  1. This subset is max{sum length(strings)}
  2. All the characters in this subset are unique

We can of course conseder a vectors from {0,1}^26 instead of strings. If we say that there is an edge between two these vectors iff a & b == 0, the problem is to find a clique in the graph such that the & a -> max where a is vertex in this clique. So we need to consider all the cliques and find the maximum.

@KirillLykov
KirillLykov / vim-files-navigation.md
Created June 26, 2020 15:18
vim files navigation
:bf            # Go to first file.
:bl            # Go to last file
:bn            # Go to next file.
:bp            # Go to previous file.
:bw            # Close file.
@KirillLykov
KirillLykov / cf_how_many_triangles.md
Last active May 25, 2020 08:59
How many triangles exists? Prefix sum problem

Interesting problem in prefix sums cf.

Given a, b, c, d find how many triangles with sides (x, y, z) exist such that a <= x <= b <= y <= c <= z <= d. The idea of the solution is to sum up prefix sum as described in the comment

#include <bits/stdc++.h>
using namespace std;
using ll = long long;