Skip to content

Instantly share code, notes, and snippets.

View jirihnidek's full-sized avatar

Jiri Hnidek jirihnidek

View GitHub Profile
@jirihnidek
jirihnidek / wip_dmidecode_output.json
Created July 3, 2023 16:06
WIP: output of dmidecode --json
{
"data":[
{
"header":{
"handle":0,
"type":0,
"length":24
},
"description":"BIOS Information",
"values":{
@jirihnidek
jirihnidek / dmidecode_output.json
Created June 23, 2023 14:24
Example of "dmidecode --json | python -m json.tool"
{
"BIOS Information": {
"Vendor": "SeaBIOS",
"Version": "1.16.2-1.fc38",
"Release Date": "04/01/2014",
"Address": "0xE8000",
"Runtime Size": "96 kB",
"ROM Size": "64 kB",
"Characteristics:": [
"BIOS characteristics not supported",
@jirihnidek
jirihnidek / flock_example.py
Created June 21, 2021 13:56
File locking using fcntl.flock using Python
"""
Example of using fcntl.flock for locking file. Some code inspired by filelock module.
"""
import os
import fcntl
import time
def acquire(lock_file):
@jirihnidek
jirihnidek / sub-sub-command.py
Last active February 17, 2024 14:18
Python example of using argparse sub-parser, sub-commands and sub-sub-commands
"""
Example of using sub-parser, sub-commands and sub-sub-commands :-)
"""
import argparse
def main(args):
"""
Just do something
@jirihnidek
jirihnidek / register_system.sh
Created July 1, 2020 08:35
Register system using D-Bus API
#!/bin/bash
echo "reseting config file..."
cp /etc/rhsm/rhsm.conf.default /etc/rhsm/rhsm.conf
echo "restarting rhsm.service..."
systemctl restart rhsm.service
# Set new variables using D-Bus API
echo "changing configuration..."
@jirihnidek
jirihnidek / singleton.py
Last active February 3, 2020 18:01
Python singleton
class Singleton(object):
"""
Singleton and parent for singletons
"""
_instance = None
_initialized = False
def __new__(cls, *args, **kwargs):
"""
@jirihnidek
jirihnidek / CMakeLists.txt
Created February 27, 2019 13:30
Libdnf plugin
CMAKE_MINIMUM_REQUIRED (VERSION 3.11.2)
project(example C)
include(GNUInstallDirs)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
# Build type
@jirihnidek
jirihnidek / client_multi_process.py
Created May 29, 2018 16:06
Multi-threaded vs multi-process vs serial https client
#!/usr/bin/env python
import requests
import time
import copy
from multiprocessing import Process
from data import URLS
def send_request(num, url):
@jirihnidek
jirihnidek / example_res_reset.py
Created May 29, 2017 12:51
Example of reseting resolver using D-Bus, NetworkManager and ctypes
from __future__ import print_function
import dbus
import dbus.mainloop.glib
from gi.repository import GLib
import threading
import time
import socket
import ctypes
try:
@jirihnidek
jirihnidek / getaddrinfo_example.c
Last active October 31, 2023 20:09
Example of getaddrinfo() program.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
int
lookup_host (const char *host)