Skip to content

Instantly share code, notes, and snippets.

@AlexTalker
AlexTalker / auth.c
Created June 28, 2022 16:22
Simple example of how `getent ---service <service>` retrieves the information for specific service only.
#include <sys/types.h>
#include <grp.h>
#include <pwd.h>
#include <nss.h>
#include <stdio.h>
/* Possibly a memory leak according to documentation */
#define SETUP_DB(db, service) if (service != NULL) { __nss_configure_lookup(db, service); }
void print_passwd(struct passwd *entry) {
@AlexTalker
AlexTalker / mpath-debug.sh
Created April 8, 2022 16:58
Collect information about present multipath devices in sufficient for `awk` format
#!/usr/bin/env bash
# vim: set number tabstop=4 shiftwidth=4 smarttab expandtab:
_transform_slaves() {
xargs -n1 -I{} realpath "/sys/block/{}/../../" | sort -u | tr '\n' ','
}
iterate_dms() {
local dmname dmuuid dmslaves dmslavescnt
@AlexTalker
AlexTalker / pcie-throughput.sh
Created January 12, 2022 13:15
Show performance information about NVMe PCie drives or any PCIe sysfs device, based on https://community.mellanox.com/s/article/understanding-pcie-configuration-for-maximum-performance
#!/usr/bin/env bash
# BEGIN: PCIe-related things
_read_attr() {
local dir="$1" name="$2"
local path=$(printf "%s/%s" "$dir" "$name")
cat "$path"
}
#!/usr/bin/env bash
function cat_passwd_column() {
awk -F: '{ print $2; }'
}
function cat_passwd_salt() {
awk -F'$' '{ print $3; }'
}
#!/usr/bin/env bash
_calc() { awk "BEGIN{print $*}"; }
_call_lspci() {
local pcie="$1"
lspci -s "$pcie" -vvv
}
@AlexTalker
AlexTalker / helloworld.pyx
Created March 5, 2020 09:49
Direct I/O in Python with Cython
from libc.stdlib cimport malloc, free
from libc.stdio cimport *
from posix.unistd cimport *
from posix.stdlib cimport *
from posix.fcntl cimport *
def test_cython(path):
cdef int ret
cdef int stdout_save, dev_null
cdef int O_DIRECT = 040000
# Maintainer: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor:
pkgname=marker-git
pkgver=2018.03.09.r86.g2d701156
pkgrel=1
pkgdesc='Markdown editor for linux made with Gtk+-3.0'
arch=('x86_64')
url='https://github.com/fabiocolacio/Marker'
license=('GPL3')
@AlexTalker
AlexTalker / mock_open.pl
Created April 7, 2017 18:02 — forked from ernix/mock_open.pl
Mock(override) built-in `open` function in perl.
#
# http://perldoc.perl.org/CORE.html#OVERRIDING-CORE-FUNCTIONS
# > To override a built-in globally (that is, in all namespaces), you need to
# > import your function into the CORE::GLOBAL pseudo-namespace at compile
# > time:
# >
# > BEGIN {
# > *CORE::GLOBAL::hex = sub {
# > # ... your code here
# > };
#!/usr/bin/python
from sys import argv
from os import listdir, symlink, unlink
from os.path import isfile, join, getctime
from fnmatch import fnmatch
from datetime import datetime, date
from subprocess import run, Popen, PIPE
from ftpush import ftpush
from parse_db import DBReader
#!/usr/bin/python
import tarfile
from sys import argv
from os.path import dirname, basename
class TarFileWithDirs(tarfile.TarFile):
def __init__(self, *args, **kwargs):
super(TarFileWithDirs, self).__init__(*args, **kwargs)
self._dirs = {}
for o in self: