Skip to content

Instantly share code, notes, and snippets.

@nijave
nijave / multiprocessing_example.py
Last active July 10, 2019 15:34
Examples of using Python multiprocessing
from multiprocessing import Pool
import time
import random
import collections
def job(job_id):
time.sleep(job_id)
return job_id
from concurrent import futures
import collections
import time
def job(job_id):
time.sleep(job_id)
return job_id
import json
import re
with open("AARON1.DAT", "r") as f:
workoutfile = f.read().strip()
workouts_json = "[" + workoutfile.replace(" }\n}\n{", "},\n{").replace("}\n{", "},\n{").strip()[0:-1] + "]"
try:
workouts = json.loads(workouts_json)
@nijave
nijave / 42-dell-quirks.conf
Last active January 6, 2021 19:35
/usr/share/X11/xorg.conf.d/42-dell-quirks.conf
Section "InputClass"
Identifier "DELL08AF:00 06CB:76AF Touchpad"
MatchProduct "DELL08AF:00 06CB:76AF Touchpad"
MatchIsTouchpad "on"
MatchOS "Linux"
MatchDevicePath "/dev/input/event*"
Driver "mtrack"
#Option "Ignore" "on"
Option "IgnorePalm" "true"
@nijave
nijave / aws-login-setup.sh
Last active January 29, 2020 19:15
Sets up aws-login alias
if [[ ! -d ~/code/aws-login-windows ]]; then
mkdir -p ~/code/aws-login-windows
git clone https://github.com/Root-App/aws-login-windows.git ~/code/aws-login-windows
fi
pushd ~/code/aws-login-windows
git pull
popd
if [[ "$ZSH_NAME" != "" ]]; then
@nijave
nijave / grantLogonAsService.ps1
Last active January 31, 2024 09:10
Grants a user SeServiceLogonRight via Powershell (and LSA APIs...)
Add-Type @'
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
public class LsaUtility
{
[DllImport("advapi32.dll")]
private static extern int LsaOpenPolicy(
ref LSA_UNICODE_STRING sysName,
@nijave
nijave / util.py
Created May 19, 2020 14:05
Python helper functions
def find(func, i):
"""
Finds the first match in an iterable
Works like `filter` but returns a single item
"""
try:
return next(filter(func, i))
except StopIterator:
raise ValueError("No matching item found")
#!/usr/bin/env python
# coding: utf-8
# In[27]:
import logging
import json
import requests
import uuid
@nijave
nijave / hvkvp.py
Last active September 8, 2020 13:56
Read Hyper-V key-value pair data on Linux guest
# Inspired by https://github.com/ejsiron/hvkvp
# explanation of format https://www.altaro.com/hyper-v/key-value-pair-data-exchange-3-linux/
# pool_3 host->guest (read-only)
with open("/var/lib/hyperv/.kvp_pool_3", "r") as f:
data = f.read()
# Each k, v is a nul terminated string. k is 512 bytes, v 2048 bytes
# so 2560 bytes is a single item
n = 2560
@nijave
nijave / zfs_pool_devices.py
Last active July 11, 2021 16:26
FreeBSD ZFS Device Info
#!/usr/bin/env python3
import json
import re
import subprocess
import libzfs
zfs = libzfs.ZFS()