Skip to content

Instantly share code, notes, and snippets.

View haraldh's full-sized avatar
☀️
🍻

Harald Hoyer haraldh

☀️
🍻
View GitHub Profile
@haraldh
haraldh / gist:a31e94f7d6904b626824
Last active August 29, 2015 14:24
Bash filevercmp - quicksort and version sort
#!/bin/bash
unset LC_MESSAGES
unset LC_CTYPE
export LC_ALL=C
export LANG=C
match_suffix()
{
[[ "$1" =~ (\.[A-Za-z~][A-Za-z0-9~]*)*$ ]] && printf -- "%s" "${BASH_REMATCH[0]}"
import random
import math
item_min = 57
item_max = 225
num_simulation = 100000
cost = 60000
def draw(sm):
global s, item_min, item_max
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>Cost of Reinforcement Simulator</title>
<style>
table, th, td {
border: 1px solid white;
border-collapse: collapse;
}
@haraldh
haraldh / udev_device_wait_change.c
Last active November 24, 2015 14:01
close a device file descriptor and wait for the udev change event
/*
close(fd) of a device file descriptor after making a change and wait for any udev change event
if none is received, trigger the change by writing change to the uevent file in /sys
Without udev watch rule:
$ sudo ./udev_device_wait_change
Issued 'change' uevent via '/sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/uevent'
Change event seen!
#!/usr/bin/python3
from systemd import journal
import random
import sys
import time
import string
from syslog import syslog
class ToLog:
#!/bin/bash
readonly TMPDIR="$(mktemp -d -t checkrpmset.XXXXXX)"
trap '
ret=$?;
[[ $TMPDIR ]] && rm -rf -- "$TMPDIR";
exit $ret;
' EXIT
rpms=(
#!/bin/bash
#
# Author: Harald Hoyer <harald@redhat.com>
# Copyright 2015 Red Hat, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
#### modified repoquery.py for graphviz .dot generation
# replace /usr/lib/python3.5/site-packages/dnf-plugins/repoquery.py
#
# example:
# $ dnf -q --disablerepo=* --enablerepo=rawhide repoquery \
# --arch=noarch,x86_64 --requires --recursive bash systemd kernel dracut bash
#
#
# Copyright (C) 2014 Red Hat, Inc.
#!/usr/bin/python3
#
# Usage:
# $ python3 prereq.py repodata-primary.xml.gz
#
import sys
import xml.etree.ElementTree as ET
import gzip
document = ET.parse(gzip.open(sys.argv[1]))
#include <net/if.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
char ifname[IF_NAMESIZE+1];
int ifindex = atoi(argv[1]);
if (if_indextoname( ifindex, ifname) != NULL)
puts(ifname);