Skip to content

Instantly share code, notes, and snippets.


Andriy Makukha amakukha

  • Hong Kong
View GitHub Profile
View APL_Competition_2020_P9.dyalog
2020 APL Problem Solving Competition Phase II
Problem 9, Task 1 - Weights
1) Read the diagram of a mobile from the file as a vector of lines (M).
2) Find lines which exactly repeat the preceding lines and contain only
vertical bars (│) and spaces. Such lines don't bring any useful
information. (This filtering step allows to process files which are
very deep without running out of memory. For example, 10K characters
wide, 100K lines deep. Without filtering, such a file would be
amakukha /
Created May 4, 2020
BERT (2018) script for movie comment sentiment analysis
#!/usr/bin/env python
# Copyright 2019 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
amakukha / .config
Created Feb 20, 2020
Config for compiling toybox on MacOS
View .config
# .config file for compiling toybox on MacOS
# 1) make defconfig
# 2) replace the .config file
# 3) make
# Also: don't forget to install gsed (GNU sed)
# Adding CPUS=1 in scripts/ might also be needed
# -----------------------------------------------
# Automatically generated make config: don't edit
amakukha /
Last active Feb 28, 2020
Generates a huge artificial text
#!/usr/bin/env python3
A script to generate text files that look like a novel in TXT form.
Words are completely made up, but vaguely resemble the Finnish language.
The resulting text uses ASCII encoding with only printable characters.
Distribution of words follows Zipf's law.
Standard parameters generate 1 GB text with 148391 distinct words.
amakukha / mostfreq.cpp
Last active Jul 10, 2019
Find k most frequent words in a file (fast implementation)
View mostfreq.cpp
* Solution of the Jon Bentley's k most frequent words problem using a prefix tree and
* a heap of size k. Worst case time complexity is O(N log k), where N is the total
* number of words.
* The problem is formulated in the Communications of the ACM 29,5 (May 1986), 364-369:
* "Given a text file and an integer k, you are to print the k
* most common words in the file (and the number of their
* occurrences) in decreasing frequency."
amakukha /
Last active May 7, 2020 — forked from mengzhuo/
DJB2 Hash in Python
# Proper (fast) Python implementation of Dan Bernstein's DJB2 hashing function
# DJB2 has terrible avalanching performance, though.
# For example, it returns the same hash values for these strings: "xy", "yX", "z7".
# I recommend using Murmur3 instead. Or, at least, SDBM hash below.
def hash_djb2(s):
hash = 5381
for x in s:
hash = ((( hash << 5) + hash) + ord(x)) & 0xFFFFFFFF
amakukha / ring_buff.h
Created Dec 27, 2018
Circular buffer in C++
View ring_buff.h
#ifndef _RING_BUFFER_
#define _RING_BUFFER_
// Source:
#include <memory>
#include <mutex>
template <class T>
class RingBuffer {
amakukha / Play2Tones.ino
Last active Jul 10, 2019
Play duo melody with Arduino
View Play2Tones.ino
* Play duo melody with Arduino
* ============================
* Description:
* This sketch simultaneously plays two separate melodies on two (passive)
* speakers or buzzers. This creates effect of a "choir".
* For simplicity, it uses function play2Tones(), which only plays two notes
* of equal duration simultaneosly.
* The actual melody here is the Anthem of Ukraine.
amakukha /
Last active Aug 18, 2018
Percentage area overlap between circles in Python.
## Percentage area overlap between circles in Python.
## Inspired by PHP code by JP Hastings-Spital:
import math
def circle_overlap(centers_distance, radius1, radius2):
# Make sure the larger circle is left-most (for convenience)
#!/usr/bin/env python3
A script to recursively compare two directories (including file size and file hash changes)
Usage: python3 DIR1 DIR2
import os, sys, hashlib
COMPARE_FILES = True # should file sizes be compared if their names are the same?