Skip to content

Instantly share code, notes, and snippets.

View artemkin's full-sized avatar
🎯
Focusing

Stas artemkin

🎯
Focusing
View GitHub Profile
@artemkin
artemkin / Makefile
Last active September 26, 2019 07:03 — forked from porglezomp/Makefile
Multiple return types
all: union exn variant
%: %.cpp
clang++ -Wall -Wextra -Werror -std=c++17 -O3 $< -o $@
clean:
rm -f union exn variant
#include <stdio.h>
#include <stdint.h>
int main()
{
int64_t i = 12345;
if (i < INT64_C(-9223372036854775808))
printf("ERROR\n");
if (i < INT64_C(-9223372036854775807) - 1)
printf("ERROR\n");
@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:
@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 / 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 / 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 / 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"
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 / 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() {}
};
@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