Skip to content

Instantly share code, notes, and snippets.

@Enteee
Enteee / add_nodes.py
Created August 27, 2019 07:53
ucmdb-api example
import random
import string
N=20
api.insert([
{
'ucmdbId': i,
'type': 'node',
'properties': {
'name': ''.join(random.choices(string.ascii_uppercase + string.digits, k=N))
}
@Enteee
Enteee / class-variable-in-subprocess.py
Last active August 6, 2019 09:15
Demonstrate operating syste dependent behaviour w.r.t static class members in subprocess
from multiprocessing import Process
class C(object):
VAR = 'DEFAULT'
def print_c():
print(f'C.VAR = {C.VAR}')
def main():
@Enteee
Enteee / events.js
Last active August 5, 2019 22:26
FluentFlow Example: If you see within 2 seconds two invalid login attemps followed by a successful login from the same source, then alert.
const ff = require('fluentflow')
const $ = ff.RuleBuilder;
const _ = require('lodash');
const moment = require('moment')
/**
* Not interesting if older than 2 seconds
*/
function isInteresting(c, pc){
return moment.duration(
@Enteee
Enteee / docker-compose.sh
Last active September 25, 2019 22:14 — forked from Gems/docker-compose.sh
A `docker-compose` wrapper for multiple configuration files with relative paths
#!/usr/bin/env bash
# Docker compose wrapper with submodule support
# Reads all docker-compose.yaml files given with -f / --files and compiles one
# big docker-compose.yaml file before running docker-compose.
#
# This is useful when you have nested docker-compose subprojects in different
# folders which contain relative paths.
# see: https://github.com/docker/compose/issues/3874
#
# Environment:
@Enteee
Enteee / :for
Last active December 26, 2022 22:05
Bash: Parallel execute and retain exit code
#!/usr/bin/env bash
# Wait for pids to terminate. If one pid exits with
# a non zero exit code, send the TERM signal to all
# processes and retain that exit code
#
# usage:
# :wait 123 32
function :wait(){
local pids=("$@")
@Enteee
Enteee / code_quality.py
Created October 7, 2017 19:36
Check eval(repr(cls())) == cls() for whole package
#!/usr/bin/env python3
# vim: set fenc=utf8 ts=4 sw=4 et :
"""
Tests the follwoing rules for a whole package:
1. Repr is unique: All classes must implement __repr__ with eval(repr(cls())) == cls()
"""
import unittest
@Enteee
Enteee / Makefile
Last active August 11, 2016 14:42
scanf userland & kernelspace test
.PHONY: all runtest
MODULES_DIR := /lib/modules/$(shell uname -r)
KERNEL_DIR := $(MODULES_DIR)/build
obj-m := test.o
all: test test.ko