Skip to content

Instantly share code, notes, and snippets.

View divi255's full-sized avatar

Sergiy S. divi255

View GitHub Profile
@divi255
divi255 / ttt.rs
Last active February 11, 2024 03:56
tags to tree Rust
use std::collections::BTreeMap;
#[macro_use]
extern crate bma_benchmark;
// here Arc<String> is wanted to be used but for small depth Arc provides additional overhead and
// results are lower
#[derive(Default)]
struct Tree(BTreeMap<String, Tree>);
@divi255
divi255 / ttt.py
Last active February 11, 2024 03:42
tags to tree Python
from bma_benchmark import benchmark
def tags_to_tree(tags):
def fill_tags_tree_recursive(tag, tree):
ch = tag.split('.', maxsplit=1)
if len(ch) == 1:
tree[tag] = {}
else:
@divi255
divi255 / download_csv.tsx
Created February 7, 2024 22:38
Download CSV from useEvaStateHistory hook
import { useMemo } from "react";
import {
get_engine,
useEvaStateHistory,
generateStateHistoryCSV,
StateHistoryOIDColMapping
} from "@eva-ics/webengine-react";
import { Eva, StateProp } from "@eva-ics/webengine";
import { Timestamp } from "bmat/time";
import { downloadCSV } from "bmat/dom";
@divi255
divi255 / build.rs
Created June 1, 2023 16:39
Use cargo metadata to deny build if some dependency crate feature has been enabled
use cargo_metadata::{CargoOpt, MetadataCommand};
use std::path::Path;
fn main() {
let mut manifest = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).to_owned();
manifest.push("Cargo.toml");
let metadata = MetadataCommand::new()
.manifest_path(manifest)
.features(CargoOpt::AllFeatures)
.exec()
@divi255
divi255 / hash.rs
Created December 5, 2022 02:23
hash calc by ChatGPT (FIPS-140 compliant)
extern crate clap;
extern crate openssl;
use clap::{App, Arg};
use openssl::hash::{Hasher, MessageDigest};
use std::error::Error;
use std::fs::File;
use std::io::{BufReader, Read};
fn main() -> Result<(), Box<Error>> {
@divi255
divi255 / main.rs
Last active November 14, 2022 01:45
RPC call tracing with Rust+Tokio
// Full article: https://medium.com/@disserman/api-call-tracing-in-high-loaded-asynchronous-rust-applications-bc7b126eb470
//
// Cargo.toml:
// [package]
// name = "rct"
// version = "0.1.0"
// edition = "2021"
//
// [dependencies]
// hyper = { version = "0.14.23", features = ["server", "tcp", "http1"] }
@divi255
divi255 / thinkpad_acpi.patch
Created May 18, 2022 02:11
Thinkpad 2nd fan patch hack for Linux Kernel 5.13. Forces 2nd fan detection and control. Use at your own risk! (confirmed to work on P15 Gen2)
--- drivers/platform/x86/thinkpad_acpi.c.bak 2021-06-28 00:21:11.000000000 +0200
+++ drivers/platform/x86/thinkpad_acpi.c 2022-05-18 04:07:06.814390699 +0200
@@ -8883,31 +8883,22 @@
quirks = tpacpi_check_quirks(fan_quirk_table,
ARRAY_SIZE(fan_quirk_table));
- if (gfan_handle) {
- /* 570, 600e/x, 770e, 770x */
- fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
- } else {
@divi255
divi255 / main.rs
Last active January 18, 2022 01:17
nats-elbus
/* [dependencies]
tokio = { version = "1.15.0", features = ["full"] }
bma-benchmark = "0.0.18"
async-nats = "0.10.1"
elbus = { version = "", features = ["full"] }
*/
#[macro_use]
extern crate bma_benchmark;
@divi255
divi255 / client.rs
Last active January 16, 2022 21:09
simple hyper RPC client/server
#[macro_use]
extern crate bma_benchmark;
use hyper::{client::connect::HttpConnector, Body, Client, Method, Request, StatusCode};
#[tokio::main]
async fn main() {
let iters = 1_000_000;
//let iters = 10;
let workers = 4;
@divi255
divi255 / minefield.rs
Last active October 12, 2021 05:21
Mine field generator for Minesweeper game
use rand::{thread_rng, Rng};
use std::fmt;
struct MineField {
field: Vec<u16>,
x: usize,
y: usize,
}
impl MineField {