Skip to content

Instantly share code, notes, and snippets.

View monoid's full-sized avatar

Ivan Boldyrev monoid

  • Fluence Labs
  • Barcelona, Spain
View GitHub Profile
@monoid
monoid / Cargo.toml
Last active August 20, 2020 10:41
Concept of interned string pool in Rust
[package]
name = "tests"
version = "0.1.0"
authors = ["Ivan Boldyrev <lispnik@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
derivative = "1
@monoid
monoid / test.cpp
Created October 20, 2019 17:07
C++ inset is not a replacement for Rust Element API
#include <iostream>
#include <functional>
#include <unordered_map>
class HiMike {
private:
int value;
public:
HiMike(int value) : value(value) { }
friend class std::hash<HiMike>;
@monoid
monoid / arm_race.cpp
Created August 17, 2019 18:04
ARM imporper atomic example
#include <atomic>
#include <cstdint>
#include <iostream>
#include <thread>
/* Improper locking (reproducible only with clang)
$ time ./a.out
1000000000 1000000000
@monoid
monoid / gist:7e5bf172a4fd7192a556
Created December 29, 2014 17:52
Variable-lenght encoding
import Data.Bits
import qualified Data.ByteString as BS
import Data.Maybe
import Data.Word
import Data.List.Split -- main, для профилирования
{-
8-кодирование: число разбивается на группы по 7 бит, начиная с младших битов,
и записываются в файл. В последней группе 8-й бит установлен в 1 как признак
@monoid
monoid / HesBs.hs
Created August 1, 2014 16:34
ByteString: hex integers
module HexBs where
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Char
itox :: Integer -> B.ByteString
itox 0 = B.singleton '0'
itox n | n > 0 = B.reverse $ B.unfoldr unhex n
where unhex i = if i == 0 then
Nothing
else
sp :: (Double, Double) -> (Integer, Double, Double)
sp (x, p) = (floor x, x - (fromIntegral $ floor x), p)
ch (f, r, p) = (1.0 / r, r)
fst' (x, _, _) = x
thd' (_, _, x) = x
-- TODO зипать список с самим собой вместо третьего элемента тупла. Или unfold...
chain x = map fst' $ takeWhile ((/= 0.0) . thd') $ iterate (sp . ch) $ sp (x,x)
@monoid
monoid / cmandelbrot.c
Created February 8, 2012 16:01
Mandelbrot with complex numbers: Lisp vs C
#include <stdio.h>
#include <complex.h>
#include <math.h>
#define MSTEPS 50000
#define MRADIUS 2.0
#define IMG_SIZE 1024
/* Squared absolute value. */
@monoid
monoid / package-reader.lisp
Created January 11, 2012 17:54
Package reader
(defun package-reader (stream subchar arg)
(declare (ignore subchar arg))
(let ((*package* (find-package (read stream)))) ; Warning! current package is polluted.
(read stream)))
(set-dispatch-macro-character #\# #\; #'package-reader)
#|
Example
> (defpackage another (:use cl))
@monoid
monoid / q.hs
Created August 27, 2011 09:35
Old hack: list queue
data Q a = Q [a] [a] deriving Show -- head and reversed tail
emptyQ = Q [] []
enQ a (Q h t) = Q h (a:t)
popQ (Q [] []) = error "Empty queue"
popQ (Q (a:h) t) = (a, Q h t)
popQ (Q [] t) = popQ (Q (reverse t) [])
@monoid
monoid / re.py
Created August 25, 2011 17:40
Ну что, лошки
import re
m = re.compile(r'^("([^"]|\\\\.)*"|\'([^\']|\\\\.)*\'|[^"\',])*,')
for s in ( '" " " " " , "',
' " " " " , " "',
'" \' " \' " \' , " "',
'" \' \' " " \' " \' \' \' , \''):
print s, not not m.match(s)