Skip to content

Instantly share code, notes, and snippets.

View caspark's full-sized avatar

Caspar Krieger caspark

View GitHub Profile
@caspark
caspark / LICENSE
Last active December 6, 2024 03:30
Script to use network namespaces to create isolated network adapters on linux
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@caspark
caspark / cloning_world.rs
Created May 17, 2024 05:48
Example of how to clone world in hecs
use hecs::{ColumnBatchBuilder, ColumnBatchType, Component, TypeUnknownToCloner, World};
fn try_add_type_to_batch<T: Component>(
archetype: &hecs::Archetype,
batch_type: &mut ColumnBatchType,
) {
if archetype.has::<T>() {
batch_type.add::<T>();
}
}
@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 June 26, 2024 18:52
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 "),