Skip to content

Instantly share code, notes, and snippets.

View divi255's full-sized avatar

Sergiy S. divi255

View GitHub Profile
@divi255
divi255 / update-debian.yml
Last active March 9, 2020 19:57
ansible playbook for debian/ubuntu updates
---
- hosts:
- all
remote_user: root
tasks:
- name: update everything
apt: upgrade=dist force_apt_get=yes autoclean=yes
- name: check if a reboot is necessary
register: reboot_required_file
stat: path=/var/run/reboot-required get_md5=no
@divi255
divi255 / README.md
Created March 11, 2020 00:14 — forked from valyala/README.md
Optimizing postgresql table for more than 100K inserts per second

Optimizing postgresql table for more than 100K inserts per second

  • Create UNLOGGED table. This reduces the amount of data written to persistent storage by up to 2x.
  • Set WITH (autovacuum_enabled=false) on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we never DELETE or UPDATE the table).
  • Insert rows with COPY FROM STDIN. This is the fastest possible approach to insert rows into table.
  • Minimize the number of indexes in the table, since they slow down inserts. Usually an index on time timestamp with time zone is enough.
  • Add synchronous_commit = off to postgresql.conf.
  • Use table inheritance for fast removal of old data:
@divi255
divi255 / pydoc2rst.py
Last active December 22, 2020 23:23
Convert pydoc to rst. Dirty monkey patch above Sphinx.
#!/usr/bin/env python3
import sys
import tempfile
import os
import sphinx.ext.autodoc
from textwrap import dedent
from types import SimpleNamespace
_d = SimpleNamespace(result='')
@divi255
divi255 / logger.py
Last active August 20, 2021 08:08
Logging from embedded Python to Rust
import logging
def rust_emit_log(*args):
# Override from Rust with pyfunction
pass
class RustLogHandler(logging.Handler):
def emit(self, record):
msg = f'{record.name}: {record.getMessage()}'
@divi255
divi255 / lib-std.rs
Last active August 22, 2021 23:50
Rust example: load a shared library and allow it to call the main process functions
/*
shared lib with safe calls, for std
put in Cargo.toml
[lib]
name = "test"
crate-type = [ "cdylib" ]
*/
use std::cell::RefCell;
@divi255
divi255 / driver.c
Last active September 6, 2021 22:52
C driver vs Rust driver
/* build with
gcc -c -Wall -Werror -fpic -O3 driver.c
gcc -shared -o libmydriver.so -O3 driver.o
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Data {
char port[20];
@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 {
@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 / 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 / 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 {