Skip to content

Instantly share code, notes, and snippets.

import tables
import parseutils
proc parseRule(s: string): tuple[color: string, contains: seq[tuple[n: int, color: string]]] =
var thisColor: string
var n: int
n = parseUntil(s, thisColor, " bags")
n += len(" bags contain ")
var contains = newSeq[tuple[n: int, color: string]](0)
#include <stdio.h>
#include <fcntl.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <sys/time.h>
void incl(char bs[], int idx)
{
int bin = idx >> 3;
@madhadron
madhadron / markov.py
Last active September 30, 2020 05:07
import collections
import random
# We need a text to work from.
# Note that we stick 'it' and 'man' in random places here
# because we need to have transitions from and to them. With
# a nontrivial text this is not a problem.
words = ['it', 'is', 'a', 'truth', 'universally', 'man', 'acknowledged', 'that', 'it', 'a', 'man']
# We're going to create a dict of dicts to track the times that one word
Rake::TestTask.new do |t|
t.libs << "test"
t.pattern = "test/test_*"
t.verbose = true
end
@madhadron
madhadron / levels.md
Created July 10, 2012 16:46
Levels of use for AppFx

This document sets forth an image of the levels at which we expect various users to interact with AppFx. The levels herein are meant as a checklist of user perspectives to account for when making design decisions.

A user’s progression of skill with a piece of software isn’t linear with effort. For example, a novice user in PhotoShop will greatly increase his capabilities with the program by switching from the standard pan and zoom familiar in other programs on his system to ad hoc pan and zoom with a function key, which functions while other tools are active and doesn’t disrupt the user’s workflow. However, it is a large adjustment. The user will lose dexterity for some time before reaching the same level.

Such jumps in the effort required to advance cause users to accumulate at those points. These accumulation points provide a portrait of the progression of a user’s skill. They are also something designable in two ways:

  1. The leaps should be made as small as possible.
  2. The accumulation points divide t
@madhadron
madhadron / gist:2885358
Created June 6, 2012 22:59 — forked from anonymous/gist:2884516
Notes for Windows apps

The Windows Event Viewer is lousy. We can do better in Splunk, and it will be a nice test case for the new AppFx framework. Since AppFx is still in early develoment, I have intentionally done my thinking about viewing Windows events in Splunk before I learned what has been done so far on AppFx.

I trawled through questions tagged with ‘windows’ on ServerFault, looking for issues people were trying to diagnose. A few areas came up as clear, obvious areas where we can provide a lot of value very quickly:

  • When were systems booted, shut down, and restarted over the history of the machine, how long did it take, and where was that time spent?
  • When were applications/MSIs installed, changed, or uninstalled, and what are their detailed information (GUIDs, etc.)?
  • Which Windows updates were applied when? Which were opted out of?
  • What programs have bound and released TCP ports over time? What program is dead, but hasn’t released that port you need?
  • What are the IPs and other information bound to various networ
@madhadron
madhadron / versioning.py
Created May 9, 2012 18:40
Versioning APIs in Python
from collections import defaultdict
import pprint
class A(object):
# All the magic happens here.
def __init__(self, version):
self.version = version
# Assemble a dictionary of version -> method_name -> method
methods = defaultdict(lambda: {})
for field in dir(self):