Skip to content

Instantly share code, notes, and snippets.

grawity / RunConsole.cs
Created Mar 15, 2011
Run a process on the console session
View RunConsole.cs
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
class RunConsole {
static extern uint WTSGetActiveConsoleSessionId();
[DllImport("wtsapi32.dll", SetLastError=true)]
static extern bool WTSQueryUserToken(UInt32 sessionId, out IntPtr Token);
grawity / .gitignore
Created Mar 31, 2011
Terminal Services session event monitor for
View .gitignore
grawity /
Created Jun 2, 2011
ADVENT magic mode script for TOPS-10-In-a-Box

This script was written for the TOPS-10-In-a-Box project. It calculates the passwords for Magic Mode in ADVENT, and is based on the one available at Zonadepruebas website.

Description copied from Zonadepruebas:

Don Woods, who deviced this authentication scheme 29 years ago, has given his kind permission to disclose it publically

'Advent' is reputedly the first text adventure game. It was originally created by William Crowthers, and later expanded by Don Woods. It was programmed in Fortran, on a DEC PDP-10 computer, and Woods' version dates from 1977. This first version has a maintenance feature called "Magic Mode". It was intended for administrators only, and involves a bizarre authentication process. After entering "MAGIC MODE" as first command in the game, the program will ask:

  1. "ARE YOU A WIZARD?", (replay "YES") > 2. "PROVE IT! SAY MAGIC WORD", (default is "DWARF")
grawity / Makefile
Created Jan 11, 2012
NTFS volume creation timestamp
View Makefile
CC = i486-mingw32-gcc
LDFLAGS = -lntoskrnl -lntdll
volumeinfo.exe: volumeinfo.c
$(CC) -o $@ $< $(LDFLAGS)
View WinlogonUnlocker.cpp
#include "stdafx.h"
#define WM_LOGONNOTIFY 0x004c
void showError()
NULL, GetLastError(), LANG_USER_DEFAULT, (LPWSTR)&pBuf, 4096, NULL);
View _Example polkit

These are only examples, for a few very common actions. You are expected to write your own rules for the rest. The syntax is regular JavaScript, but see the polkit(8) manpage for the object structure and available API. These examples are for polkit versions 106 and later, with the JS interpreter. They won't work with Debian's polkit v105.

  • If you don't know the action name, run pkaction:

    pkaction | grep cups
  • The possible results are YES, AUTH_SELF(_KEEP), AUTH_ADMIN(_KEEP), NO. Returning a result is final. Returning null will continue checking other rules.

  • Put your rules in /etc/polkit-1/rules.d/*.rules. (You can check everything in one giant addRule, or you can have a separate file and separate addRule for each program; it doesn't matter.)

grawity / GitHub protocol
Last active Sep 30, 2022
A comparison of protocols offered by GitHub (for #git on Freenode).
View GitHub protocol

Primary differences between SSH and HTTPS. This post is specifically about accessing Git repositories on GitHub.

Protocols to choose from when cloning:

plain Git, aka git://

  • Does not add security beyond what Git itself provides. The server is not verified.

    If you clone a repository over git://, you should check if the latest commit's hash is correct.

grawity / journal-follow.php
Last active Nov 10, 2021
PHP class that wraps `journalctl --follow`; for joltmode in #systemd and
View journal-follow.php
/* © 2013 Mantas Mikulėnas <>
* Released under the MIT Expat License <>
/* Iterator extends Traversable {
void rewind()
boolean valid()
void next()
mixed current()
grawity /
Last active May 12, 2022
SASL authentication from the perspective of IRC server-to-server protocols

SASL authentication in IRC

© 2014 Mantas Mikulėnas <>

This documentation is released under Creative Commons 3.0 Attribution license.

This is a description of server-server protocol, intended for ircd and services developers. For the client-server protocol descriptions, intended for client & bot developers, see the IRCv3 [sasl-3.1][] and [sasl-3.2][] specifications.

View mpris-now-playing.c
#if 0
pkg = glib-2.0 gio-2.0
app = $(basename $(src))
CFLAGS = $(shell pkg-config --cflags $(pkg)) -x c
LDFLAGS = $(shell pkg-config --libs $(pkg))
$(app): $(src)