Skip to content

Instantly share code, notes, and snippets.

@caspark
caspark / textfetch.py
Created May 28, 2020 03:12
Python UI Automation text fetching from a Windows contro sample
import uiautomation as auto
# move mouse cursor over a text box with some text in it first
c = auto.ControlFromCursor()
v = c.GetValuePattern()
print(v.Value) # should print the contents of the text box
# now select some text in that same control
t = c.GetTextPattern()
@caspark
caspark / _reloader.py
Created February 19, 2020 04:40
Script to reload all natlink grammars
from __future__ import print_function
import datetime
import os
import sys
import traceback
import dragonfly
try:
@caspark
caspark / demo.py
Created February 18, 2020 05:25
2020-02-17-kaldi-breaking-grammar
import logging, os
import dragonfly
if False:
logging.basicConfig(level=10)
logging.getLogger('grammar.decode').setLevel(20)
logging.getLogger('compound').setLevel(20)
# logging.getLogger('kaldi').setLevel(30)
logging.getLogger('engine').setLevel(10)
@caspark
caspark / slash-search.js
Created January 19, 2020 22:26
Google slash search
// ==UserScript==
// @name Google Slash Search
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.google.com/search*
// @grant none
// ==/UserScript==
@caspark
caspark / complexity.py
Created April 19, 2019 14:52
Dragonfly grammar visualizer & complexity debugging helpers
# to get started, try `print get_grammar_complexity_tree(some_grammar, threshold=5)`.
# If you don't get any interesting output, turn up the threshold (max depth visualized) to something like 7 or 10 :)
class ComplexityNode(object):
def __init__(self, item):
self.item = item
self.children = []
self.total_descendents = 1
@caspark
caspark / _window_switcher.py
Last active March 29, 2019 03:07
Window switching grammar for Dragonfly
"""A grammar to swap windows by saying words in their title.
Uses a natlink timer to periodically load the list of open windows into a DictList,
so they can be referenced by the "switch window" command.
Commands:
"switch window <keyword>" -> switch to the window with the given word in its
title. If multiple windows have that word in
their title, then you can say more words in the
@caspark
caspark / do-some-signing.ps1
Last active April 28, 2023 03:18
Sign an arbitrary windows executable with a new self signed certificate
# Snippets to sign an executable of your choice with a new certificate trusted only by you.
# Run these commands in an Administrative Powershell session.
#
# WARNING: This creates a new certificate authority and installs it on your computer!
# This means that if someone gets a hold of the certificate you generate here, they can
# impersonate (almost) any HTTPS website you visit (exception being sites which pin their
# certificates - but that is not the norm yet).
#
# Source: https://stackoverflow.com/a/51443366/775982
@caspark
caspark / git.py
Created March 8, 2019 04:39
dragonfly git commands
# git and related commands (assumes you have the extra `text` bound to dragonfly `Dictation()`
"git add": Text("git add "),
"git add patch": Text("git add -p "),
"git branch": Text("git branch "),
"git checkout": Text("git checkout "),
"git clone": Text("git clone "),
"git commit": Text("git commit -v "),
"git commit message [<text>]": Text("git commit -m ''") + Key("left") + Text("%(text)s"),
"git commit all message [<text>]": Text("git commit -a -m ''") + Key("left") + Text("%(text)s"),
"git commit all": Text("git commit -va "),
@caspark
caspark / vscode.py
Created March 2, 2019 06:17
Caspar vscode grammars
vscode_repeatable_action_map = {
"join line": Key("csa-j"),
# requires bracket jumper extension
"klane": Key("ca-left"),
"krane": Key("ca-right"),
"krupper": Key("ca-up"),
"krowner": Key("ca-down"),
"shift klane": Key("csa-left"),
"shift krane": Key("csa-right"),
@caspark
caspark / morris-traversal-kth-smallest-in-bst.py
Created February 3, 2018 21:08
Explaining how to use Morris Traversal to find the k'th smallest element in a binary search tree
# Problem:
# Given a binary search tree t with each node having properties left, right
# (the left and right subtrees respectively) and value (the value of that
# node) and an integer k, find the k-th smallest element in the BST using
# constant space.
#
# Example:
# t =
# 3
# / \