This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <functional> | |
| #include <unordered_map> | |
| class HiMike { | |
| private: | |
| int value; | |
| public: | |
| HiMike(int value) : value(value) { } | |
| friend class std::hash<HiMike>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <atomic> | |
| #include <cstdint> | |
| #include <iostream> | |
| #include <thread> | |
| /* Improper locking (reproducible only with clang) | |
| $ time ./a.out | |
| 1000000000 1000000000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.Bits | |
| import qualified Data.ByteString as BS | |
| import Data.Maybe | |
| import Data.Word | |
| import Data.List.Split -- main, для профилирования | |
| {- | |
| 8-кодирование: число разбивается на группы по 7 бит, начиная с младших битов, | |
| и записываются в файл. В последней группе 8-й бит установлен в 1 как признак |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <complex.h> | |
| #include <math.h> | |
| #define MSTEPS 50000 | |
| #define MRADIUS 2.0 | |
| #define IMG_SIZE 1024 | |
| /* Squared absolute value. */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) []) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| m = re.compile(r'^("([^"]|\\\\.)*"|\'([^\']|\\\\.)*\'|[^"\',])*,') | |
| for s in ( '" " " " " , "', | |
| ' " " " " , " "', | |
| '" \' " \' " \' , " "', | |
| '" \' \' " " \' " \' \' \' , \''): | |
| print s, not not m.match(s) |