Skip to content

Instantly share code, notes, and snippets.

@GeeLaw
GeeLaw / trackfocus.cc
Created March 31, 2020 00:23
Track the focus of Windows using UI Automation.
/*
Copyright (c) 2020 by Gee Law
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@GeeLaw
GeeLaw / gnfa2.cpp
Created August 22, 2019 06:09
Creates a regular expression that accepts strings of length at least 15 that have a digit, a lowercase letter, an uppercase letter and a special character.
// gnfa.cpp
// Copyright 2019 by Gee Law.
// Forked from https://gist.github.com/GeeLaw/be3aec94a6ba7c3817ef2e16d261f616
// Licensed under the MIT license.
#include<cstdio>
#include<vector>
#include<map>
template <typename TDerived, typename TBase>
@GeeLaw
GeeLaw / Move-PhotosInteractively.ps1
Created May 21, 2019 08:17
Photo organizer (V2EX 566127)
& {
$source = '~\Documents\Playground\MovePhotos'
$destinations = @(
'~\Documents\Playground\MovePhotos\Category1',
'~\Documents\Playground\MovePhotos\Category2',
'~\Documents\Playground\MovePhotos\Category3'
)
$destinationNames = @(
'Category1',
@GeeLaw
GeeLaw / gnfa.cpp
Created December 29, 2018 03:09
Playing with generalized NFA. The program gets a positive number as input, and outputs a regular expression that matches positive decimal integer without leading zeros that is a multiple of the input number.
// gnfa.cpp
// Copyright 2018 by Gee Law.
// Licensed under the MIT license.
#include<cstdio>
#include<vector>
#include<map>
// #define DEBUG_ONLY(t) do { t; } while (false)
#define DEBUG_ONLY(t) do { } while (false)
@GeeLaw
GeeLaw / OutlookCourseMgmt.vb
Created September 21, 2018 21:32
Outlook course management macro
Option Explicit
' See https://geelaw.blog/entries/course-mgmt-outlook/
Dim termStartsOn As Date, curriculumCalendar As Folder
Sub AskForTermStartsOn()
Dim shouldAskNewDate As Boolean
TryAskNewDate:
@GeeLaw
GeeLaw / sfinae.cc
Created August 13, 2018 10:22
Use SFINAE to detect whether to_string is present.
#include<string>
#include<iostream>
#include<utility>
#include<type_traits>
template <typename T, typename TType, bool value =
std::is_same<std::string, decltype(to_string(std::forward<T>(*(T *)nullptr)))>::value
>
struct has_to_string { };
@GeeLaw
GeeLaw / handler.cc
Created May 26, 2018 22:00
URI protocol handler that chooses a class-verb combination based on the URI
/**************************************************************************\
|* *|
|* The MIT License (MIT) *|
|* *|
|* Copyright © 2018 by Gee Law *|
|* *|
|* Permission is hereby granted, free of charge, to any person obtaining *|
|* a copy of this software and associated documentation files (the “Soft- *|
|* ware”), to deal in the Software without restriction, including without *|
|* limitation the rights to use, copy, modify, merge, publish, distribute,*|
@GeeLaw
GeeLaw / keybase.md
Created February 19, 2016 16:01
Identifying this account as geelaw on Keybase.

Keybase proof

I hereby claim:

  • I am geelaw on github.
  • I am geelaw (https://keybase.io/geelaw) on keybase.
  • I have a public key whose fingerprint is 36A6 DC21 7826 C763 FCC4 7114 951F 0BEB A856 D53A

To claim this, I am signing this object:

@GeeLaw
GeeLaw / word-detach-template-vba-macro
Last active May 10, 2022 16:58
A VBA Macro for Microsoft Word to attach the normal template (Normal.dotm) to the active document.
Option Explicit
' CC BY-SA
' by Gee Law on github.com/geelaw
Sub DetachTemplate()
'
' DetachTemplate Macro
'
'
@GeeLaw
GeeLaw / geelawdicttkeytvaluedotnet.cs
Created June 16, 2014 15:44
On Dictionary<TKey, TValue> in .NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestDict
{
struct SampleStructIS
{