Skip to content

Instantly share code, notes, and snippets.

View divi255's full-sized avatar

Sergiy S. divi255

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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