Skip to content

Instantly share code, notes, and snippets.

from inspect import signature
from functools import wraps
def dec(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper
def dec2(func):
@wraps(func)
@chtenb
chtenb / alarmevent.cs
Created December 17, 2015 11:02
Events are assignable, like delegates
namespace AlarmNamespace
{
public class AlarmEventArgs : EventArgs
{
private DateTime alarmTime;
private bool snoozeOn = true;
public AlarmEventArgs (DateTime time)
{
this.alarmTime = time;
@chtenb
chtenb / archive_merged_branches.py
Last active May 25, 2019 21:33
Python script that lets you archive branches interactively
"""
Archive branches that are merged into master.
This is done by tagging them as archive/<branchname> and removing them both locally and
remotely. Before each operation, the user is asked for confirmation.
"""
# This dependency can be found on github: https://github.com/Chiel92/python-shellout
from shellout import get, out, confirm
# Tag merged branches
import re
from shellout import get, out
errors = get('cat errors.txt')
# Fix missing explicit keyword using vim
# Where explicit.vim contains:
# exe "normal 0wiexplicit \<esc>"
# wq
import re
from shellout import out
errors = out('cat errors.txt')
regex = re.compile(r"\[(?P<filename>[^:]+):(?P<linenumber>\d+)\]: \(performance\) "
"Function parameter '(?P<argumentname>[^']+)'")
matches = regex.findall(errors)
for match in matches:
d = match.groupdict()
@chtenb
chtenb / codecheck.sh
Last active September 17, 2019 15:50
Example shell script that uses unix tools to check source code for some basic problems
#!/bin/bash
exitcode=0
root=`git rev-parse --show-toplevel`
echo "Root of repository: $root"
echo
cd "$root/Source"
source_files=$(find . \( -name \*.h -or -name \*.cpp \) \
@chtenb
chtenb / extension.js
Created January 28, 2021 13:40
Size of units in the letterspacing property of a tab character are erroneously scaled up: reproduction scenario
import * as vscode from 'vscode';
// this method is called when your extension is activated
export function activate(context: vscode.ExtensionContext) {
// Decoration types are very expensive to make, so we create them once and then reuse them.
// The decoration types are indexed by the amount of spaces they add.
let decorationType = vscode.window.createTextEditorDecorationType({ border: "1px solid red", letterSpacing: "-0.5ch" });
let decorationRanges: vscode.Range[] = [];
const updateDecorations = (editor: vscode.TextEditor | undefined) => {
@chtenb
chtenb / Option.cs
Created August 19, 2022 14:12
Recipe for nullable wrapper that can handle both value types and reference types, unlike System.Nullable
using System;
namespace Utils;
/// <summary>
/// "Nullable" wrapper. Can wrap both value types and reference types.
/// </summary>
/// <typeparam name="T"></typeparam>
public readonly struct Option<T> : IEquatable<Option<T>>
{
#!/bin/bash
cp ~/.steam/steam/steamapps/common/AoE2DE/vc_redist.x64.exe ~/.steam/steam/steamapps/compatdata/813780/pfx/drive_c/windows/system32/vc_redist.x64.exe
cd ~/.steam/steam/steamapps/compatdata/813780/pfx/drive_c/windows/system32/
sudo cabextract vc_redist.x64.exe
sudo cabextract a10
sudo chown -R $USER:$USER .
@chtenb
chtenb / segfault-repro-1.kk
Last active February 5, 2024 17:21
koka segfault
import std/core/unsafe
import std/core/undiv
pub fun debug(msg : string) : total ()
unsafe-total({println(msg)})
pub effect yield<a>
ctl yield(elem : a) : ()