Skip to content

Instantly share code, notes, and snippets.

View stemid's full-sized avatar

Stefan Midjich stemid

View GitHub Profile
@stemid
stemid / snifstat.c
Created September 26, 2016 06:02
Old program I wrote for freebsd 4.x about 10 years ago
/* this application captures packets destined to and from
* a specified host, it then tries to calculate in and out
* traffic statistics and display it like ifstat
* by nocturnal [at] swehack [dot] se */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@stemid
stemid / VMDK-orphaned.ps1
Created October 27, 2016 08:53
VMDK-orphaned
add-pssnapin VMware.VimAutomation.Core
Set-PowerCLIConfiguration -invalidCertificateAction 'ignore' -confirm:$false -Scope Session
Connect-VIServer -Server 10.220.100.220 -Protocol https
$report = @()
$daysAgo = (Get-Date).AddDays(-14)
$arrUsedDisks = Get-View -ViewType VirtualMachine | % {$_.Layout} | % {$_.Disk} | % {$_.DiskFile}
$arrDS = Get-Datastore | Sort-Object -property Name
foreach ($strDatastore in $arrDS) {
$ds = Get-Datastore -Name $strDatastore.Name | % {Get-View $_.Id}
#!/usr/bin/env bash
home_base=/var/sftp
test $(id -u $PAM_USER) -gt 500 || exit 1
grep ^{{chroot_openssh_group}} /etc/group | grep -q $PAM_USER || exit 1
_HOME=$(getent passwd $PAM_USER 2>/dev/null | cut -d: -f6 2>/dev/null)
if [ -z "$_HOME" ]; then
#!/usr/bin/env python3
# This was a failed PoC to try and use socket files as ssh_config file. :)
# by Stefan Midjich
import os
import functools
import asyncio
def set_socket_permission(socket_file):
#!/usr/bin/env python
from __future__ import print_function
try:
from configparser import RawConfigParser
except ImportError:
from ConfigParser import RawConfigParser
from json import dumps
from argparse import ArgumentParser, FileType
@stemid
stemid / compress.sh
Last active December 22, 2016 13:31
Recursively compress files with xz using multiple threads
# With Bash 4.3 I'd rather use wait -n to keep N
# processes running at all times. As it is now you
# unfortunately have to wait for the last process
# to finish.
# Recursively compress all files in $dir
compress () {
dir=$1
count=${2:-2}
num_procs=${3:-0}
#!/usr/bin/env bash
# {{ ansible_managed }}
# vim: set filetype=bash
#
# WARNING: Have you run xtrabackup_prepare.sh first?
# WARNING: You must know what you're doing or the backup will be ruined!
shopt -s nullglob
backup_dir=/var/backups/xtrabackup

Keybase proof

I hereby claim:

  • I am stemid on github.
  • I am stemid (https://keybase.io/stemid) on keybase.
  • I have a public key ASD1nmKQzW0A_OGRdxfATEZL8ZAy55k5LulsWPfC2Iz2cAo

To claim this, I am signing this object:

@stemid
stemid / pyvmomi_example1.py
Last active November 29, 2017 07:02
pyVmomi template script that demonstrates traversing objects from vcenter.
#!/usr/bin/env python
# This is sort of a template script for most operations that might have to
# recursively traverse the vcenter objects looking for something.
#
# by Stefan Midjich <swehack@gmail.com>
#
# See comments further down in the code to understand more.
# It's important to know the object structure of your vcenter so look into
# your own MOB first. It's found at https://10.11.12.13/mob on your vcenter
# server.
@stemid
stemid / defaults.cfg
Last active June 7, 2018 11:38
Boilerplate logging class I use in most my applications
# AppLogger specific config.
[logging]
log_format = %(asctime)s %(name)s[%(process)s] %(levelname)s: %(message)s
log_debug = True
log_level = INFO
# Handler can be one of file, stdout or syslog
log_handler = stdout
# Can use this to log directly to another server if need be