Skip to content

Instantly share code, notes, and snippets.

View artemkin's full-sized avatar
🎯
Focusing

Stas artemkin

🎯
Focusing
View GitHub Profile

Keybase proof

I hereby claim:

  • I am artemkin on github.
  • I am stas (https://keybase.io/stas) on keybase.
  • I have a public key whose fingerprint is 9D25 6F3B FE9A 0ADF E7E5 D03E 5D55 61F3 B009 1428

To claim this, I am signing this object:

// Special case of memoization. Only last value is cached.
#include <iostream>
#include <memory>
template<typename R, typename Arg, typename Comp = std::equal_to<Arg>, typename Fun>
std::function<R(const Arg&)> memoize_last(Fun f)
{
struct Cache
{
@artemkin
artemkin / gadt_eval.ml
Created May 26, 2015 08:52
GADT based integer/boolean evaluator
type _ expr =
| Int_lit : int -> int expr
| Bool_lit : bool -> bool expr
| Add : int expr * int expr -> int expr
| Sub : int expr * int expr -> int expr
| Mul : int expr * int expr -> int expr
| Div : int expr * int expr -> int expr
| Lt : int expr * int expr -> bool expr
| Gt : int expr * int expr -> bool expr
@artemkin
artemkin / init.cpp
Last active August 29, 2015 14:26
Can't move from initializer_list
#include <iostream>
#include <memory>
#include <vector>
#include <initializer_list>
#include <iterator>
struct Item
{
virtual ~Item() {}
};
var toType = function(obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
}
function stringToArray(str) {
var arr = [];
for (var i = 0; i < str.length; ++i)
arr.push(str.charCodeAt(i));
return arr;
@artemkin
artemkin / bench.hs
Created October 2, 2015 12:42
Haskell `sort lst` vs `(select 1) lst` benchmark
import Data.List
import Criterion.Main
select :: Ord a => Int -> [a] -> [a]
select k = take k . sort
lst = ["temperish", "warehousemen", "hirtellous", "glaciology", "vermilion", "intrigante", "CDC", "torrent-flooded", "quasi-diplomatic", "writ", "toad-green", "infamiliar", "stomatorrhagia", "luminative", "bebathe", "keyless", "wonderless", "achalasia", "locules", "prettiness", "double-handed", "inirritant", "Marylinda", "Diploptera", "nonskilled", "high-low", "hypermetaphysical", "nicker", "prespreading", "kick-sled", "Sparland", "pastilled", "rebeguile", "noncurative", "nonextricable", "ketohexose", "unbraiding", "hyporhachidian", "Blephariglottis", "-log", "Wonnie", "self-evidentness", "Axonolipa", "Cappadocia", "mamsell", "agistator", "shins", "actinomycotic", "Fabriane", "abvolts", "fussbudgety", "olecranial", "sparkle-drifting", "iridocele", "Accalia", "apophlegmatism", "depersonize", "disleal", "mafia", "spuke", "gru-gru", "stupefies", "sun-marked", "casualties", "Burmannia", "Lalitta", "dauntlessly"
@artemkin
artemkin / explicit_instantiation.cpp
Created October 22, 2015 09:28
C++ Explicit instantiation
// foo.h
#pragma once
template<typename A>
class Foo
{
public:
Foo();
@artemkin
artemkin / tokenizer.cpp
Last active November 3, 2015 12:39
Simple tokenizer
#include <iostream>
#include <string>
#include <functional>
#include <ctype.h>
using Tokenizer = std::function<std::string()>;
Tokenizer CreateTokenizer(const std::string& i_str)
{
if (i_str.empty())
@artemkin
artemkin / pack_bool.cpp
Created December 22, 2015 12:58
Boolean pack
#include <iostream>
#include <type_traits>
namespace detail
{
constexpr std::size_t pack_bool(std::size_t result)
{
return result;
}
@artemkin
artemkin / subtitle-extract.txt
Created January 18, 2016 18:51 — forked from bmaeser/subtitle-extract.txt
extract subtitles from *.mkv-files on osx
lines with $ are commands
### install mkvtoolnix:
$ brew install mkvtoolnix
### list content of the mkv-file:
$ mkvmerge -i mymoviefile.mkv
### what will give you: