Skip to content

Instantly share code, notes, and snippets.

View khvorov's full-sized avatar

Dmitry Khvorov khvorov

View GitHub Profile
@khvorov
khvorov / resume.json
Last active August 28, 2021 02:21
CV template in JSON
{
"meta": {
"theme": "elegant"
},
"basics": {
"name": "Dmitry Khvorov",
"label": "Programmer",
"email": "dmitry.khvorov@gmail.com",
"phone": "+6590265669",
"website": "khvorov.com",
@khvorov
khvorov / mandelbrot.cpp
Created May 30, 2020 08:39
Zoom through the Mandelbrot set
// g++ -Wall -pedantic --std=c++17 -g -O3 -fopenmp -march=native -o mandelbrot{,.cpp} -lpng -pthread
// rm -rf *.png *.gif && ./mandelbrot
// convert -delay 5 movied_*.png -loop 0 movied.gif
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>
@khvorov
khvorov / ce_matrix.cpp
Created September 30, 2017 02:02
Matrix addition & multiplication at compile time using constexpr
#include <array>
#include <type_traits>
// TODO: using C++17 (-std=c++1z) as std::array functions are not constexpr in C++14
// g++ -Wall -pedantic -Wno-missing-braces -std=c++1z -O0
template <typename T, std::size_t R, std::size_t C>
struct matrix
{
std::array<std::array<T, C>, R> data_ {};
@khvorov
khvorov / mnist_conv.py
Last active April 30, 2017 11:34
tensorflow tutorial - MNIST data
# coding: utf-8
import input_data
mnist = input_data.read_data_sets('MNIST_data/', one_hot=True)
import tensorflow as tf
# training parameters
learning_rate = 1e-4
training_iteration = 4
batch_size = 50
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <unordered_set>
int main(int argc, char * argv[])
{
if (argc != 2)
{
@khvorov
khvorov / latency.txt
Created March 31, 2016 00:05 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@khvorov
khvorov / noexcept_move.cpp
Last active October 20, 2015 06:06
Simple test to see how 'noexcept' improves performance of that code
// noexcept
// $ g++ -Wall -pedantic -std=c++1y -O3 -march=native -DNOEXCEPT="noexcept" noexcept_move.cpp && ./a.out
// cap.: 10000000
// 28 ms
// no noexcept
// $ g++ -Wall -pedantic -std=c++1y -O3 -march=native -DNOEXCEPT="" noexcept_move.cpp && ./a.out
// cap.: 10000000
// 251 ms
@khvorov
khvorov / memoize.cpp
Created October 11, 2015 02:58
Memoization in C++
// memoize: F, Args... ==> R result
// hash(&F, args,,,) ==> R result
#include <boost/any.hpp>
#include <boost/functional/hash.hpp>
#include <exception>
#include <initializer_list>
#include <iostream>
#include <type_traits>
@khvorov
khvorov / lambda_to_function.cpp
Last active March 21, 2024 06:19
Convert lambda to std::function
// g++ prog.cc -Wall -Wextra -O2 -march=native -std=gnu++1y
#include <cxxabi.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <typeinfo>
namespace detail
@khvorov
khvorov / make_const_tuple.cpp
Created November 29, 2014 07:27
For a given tuple type constructs a new tuple where all element types are const
// $ clang++ -Wall -Wextra -pedantic -std=c++1y make_const_tuple.cpp -o /tmp/a.out
// make_const_tuple.cpp:43:22: error: read-only variable is not assignable
// std::get<0>(ctr) = 1;
// ~~~~~~~~~~~~~~~~ ^
// make_const_tuple.cpp:48:21: error: read-only variable is not assignable
// std::get<0>(ct) = 1;
// ~~~~~~~~~~~~~~~ ^
#include <tuple>
#include <type_traits>