Skip to content

Instantly share code, notes, and snippets.

View dkruchinin's full-sized avatar

Daniil Kruchinin dkruchinin

View GitHub Profile
@dkruchinin
dkruchinin / list_message_types.js
Created June 4, 2019 18:18
List message types containing in a proto file
const fs = require('fs')
const protobuf = require('protobufjs')
const protoFileName = process.argv[2]
if (protoFileName == null || !fs.existsSync(protoFileName)) {
console.error(`USAGE: ${process.argv[0]} <schema-file.proto>`)
process.exit(-1)
}
protobuf.load(protoFileName, function (err, root) {
Methodology:
1. The benchmark repeatedly performs every operation 2.5k times on randomly created and initialised objects
2. I ran the benchmark 5 times, obtaining 5 samples of 2.5k points for every operation
3. All the averages, means and standrad deviations that you see are actually median of means, median of medians and median of
standard deviations.
4. All IDs are incremented natural numbers (not recommended by datastore but somewhat reflects our usage of it)
5. I could not perform the `query` operation, because datastore now explicity asks to create an index for custom fields
(they changed the old behaviour where index was created automatically) and unfortunately I don't have permissions for that.
@dkruchinin
dkruchinin / USAGE
Last active July 31, 2018 16:48
Google pub/sub continuous streaming
% node pub.js <num-messages-to-send> <rate-limit-ms>
# EXAMPLE: node pub.json 1500 100 (will send 1500 messages, rate limit: at most 1msg every 100ms)
% node sub.js 1
@dkruchinin
dkruchinin / Sending 100 messages
Created July 30, 2018 15:46
Google Pub/Sub message reordering example
# run all commands in different terminal sessions
% node sub.js 1
% node sub.js 2
% node sub.js 3
% node pub.js 100
<no out-of-order messages>
@dkruchinin
dkruchinin / prime_xor.py
Last active August 7, 2017 19:23
Hackkerank problem: count all multisets that XOR to a prime number
#!/usr/bin/env python3
import sys
MOD = 10 ** 9 + 7
MAX_N = 8191
NBASE = 3500
UNIQUE_NUMS = 1000
@dkruchinin
dkruchinin / RoadsAndFools.java
Created May 10, 2017 15:01
codeforces: 191/C
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
public class FoolsAndRoads {
@dkruchinin
dkruchinin / entropy.py
Created April 5, 2016 19:09
Example of calculating characters entropy
#!/usr/bin/env python3
from math import log
def calc_entropy(distribution):
num_chars = sum([count for count in distribution.values()])
ent = 0
for (c, count) in distribution.items():
p = count / num_chars
@dkruchinin
dkruchinin / palindrome.cpp
Last active October 29, 2015 12:59
Longest palindrome substring O(nlog^2n)
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
struct sa_node {
std::pair<int, int> bounds;
int idx;
};
module Main where
isSquare :: Int -> Bool
isSquare n = sr * sr == n
where sr = floor .sqrt . fromIntegral $ n
trySequence :: Int -> [Int] -> [[Int]]
trySequence x [] = [[x]]
trySequence x seq = map (x :) $ foldr step [] seq
where step a acc
@dkruchinin
dkruchinin / gist:cfee36f5857c695f10d9
Last active August 29, 2015 14:23
MonteCarlo simulation: calculate PI
module Main where
import System.Environment
import System.Exit
import System.Random
import Control.Monad
import Control.Concurrent
import Control.Concurrent.MVar
workerFn :: Int -> Int -> MVar Double -> IO ()