Skip to content

Instantly share code, notes, and snippets.

coro: main.cpp
$(CXX) -O3 -DNDEBUG -g -fno-exceptions -fcoroutines -std=c++2a main.cpp -o coro
@matwey
matwey / convert.py
Last active October 3, 2019 09:40
GOST-4401
#!/usr/bin/env python3
import pandas as pd
import numpy as np
import re
number = re.compile("(-)?(\d+)((\.|,)(\d+))?([-+ ](\d))?")
x = pd.read_csv("raw.csv", header=None)
@matwey
matwey / main.cpp
Last active September 30, 2019 13:03
byte-swapping bench
#include <iostream>
#include <chrono>
#include <cstring>
#include <memory>
#include <cstdint>
#include <unistd.h>
inline void swab_bi(const void* from, void* to, std::size_t size) {
const auto begin = reinterpret_cast<const std::uint16_t*>(from);
@matwey
matwey / client.c
Last active September 18, 2019 10:35
memfd_create + sdbus example
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <systemd/sd-bus.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
@matwey
matwey / test.exs
Last active May 22, 2019 17:37
elixir git
#!/usr/bin/env elixir
:ok = Application.ensure_started(:crypto)
defmodule Git do
defp write_object(repo, type, content) do
object = type <> <<" ">> <> (byte_size(content) |> to_string) <> <<0>> <> content
hash = :crypto.hash(:sha, object)
object = object |> :zlib.compress
@matwey
matwey / main.cpp
Last active February 12, 2019 14:01
c++ partial_shuffle
#include <iostream>
#include <cstring>
#include <random>
#include <chrono>
#include <iterator>
template<class RandomIt, class URBG>
void partial_shuffle(RandomIt first, RandomIt middle, RandomIt last, URBG&& g)
{
using difference_type = typename std::iterator_traits<RandomIt>::difference_type;
@matwey
matwey / main.c
Last active January 3, 2019 18:00
qemu pwrite test case
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
/*
@matwey
matwey / p.py
Created September 10, 2018 18:06
Erlang/OTP notes.xml parser
import xml.etree.ElementTree as ET
import textwrap
w = textwrap.TextWrapper(initial_indent=' * ', subsequent_indent=' ', width=62)
root = ET.parse('notes.xml')
for x in root.findall('./section[title]'):
print(x.find("title").text)
z = x.findall("./section[title='Fixed Bugs and Malfunctions']/list/item/p[1]")
for y in z:
@matwey
matwey / ADefine.h
Last active April 23, 2023 07:11
LMST test
/**
Name : ADefine.h 常量及宏定义声明文件
Author : Xiaomeng Lu
Version : 0.1
Date : Oct 13, 2012
Last Date : Oct 13, 2012
Description : 天文数字图像处理中常用的常量及宏定义
**/
#ifndef _ADEFINE_H_
#define _ADEFINE_H_
@matwey
matwey / TimeAndCoordinate.cpp
Last active August 30, 2018 07:36
TimeAndCoordinate disassembled code
#include <math.h>
#include <string.h>
#include "TimeAndCoordinate.h"
// FIXME: data!!!
char c19[160];
char c18[160];
void Rot123(int a1, double a2, double *a3, double *a4)
{