Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

import rg
import random
class Robot:
def act(self, game):
self.game = game
max_angry = 10
angry = 8
[12] pry(main)> Digest::MD5.hexdigest('one two three four five six seven eight nine ten').to_i(16) % (2**100)
=> 1097922911283534226527226500115
@hwayne
hwayne / lru_cache.py
Created June 8, 2016 22:38
Showing difference in using lru_cache
import functools
import timeit
def fib(x):
if x <= 1:
return 1
return fib(x-1) + fib(x-2)
@functools.lru_cache()
def cached_fib(x):
if x in (0,1):
@hwayne
hwayne / dfa.py
Created July 14, 2016 16:21
Type checking a DFA
from abc import ABCMeta
from enum import Enum
import typing as t
class AbstractDFA:
...
T = t.TypeVar('T', bound=t.Type[AbstractDFA])
---- MODULE logger ----
EXTENDS Integers, TLC, Sequences
Files == { "a" }
FileStruct == [ requested : BOOLEAN, uploaded : {FALSE}, logged : {FALSE}, downloaded : {FALSE}]
Range(F) == { F[x]: x \in DOMAIN F }
(* --algorithm logger
variables files \in [Files -> FileStruct];
define
FileProc(proc) == [ f : Files, p : {proc} ]
@hwayne
hwayne / final.tla
Last active April 14, 2023 20:29
Formal Methods Example Spec
EXTENDS Integers, TLC, Sequences
CONSTANTS Devices
(* --algorithm BatchInstall
variables
AppScope \in [Devices -> {0, 1}];
Installs \in [Devices -> BOOLEAN];
batch_pool = {};
lock = FALSE;
@hwayne
hwayne / initial.tla
Created March 11, 2017 20:25
Formal Methods Example Spec
EXTENDS Integers, TLC, Sequences
CONSTANTS Devices
(* --algorithm BatchInstall
variables
AppScope \in [Devices -> {0, 1}];
Installs \in [Devices -> BOOLEAN];
batch_pool = {};
define
EXTENDS Integers, Sequences, TLC, FiniteSets
(* --algorithm deadlock
variable mq = <<>>;
macro add_message(msg) begin
await Len(mq) < 5;
mq := Append(mq, <<msg>>);
end macro
@hwayne
hwayne / god-has-abandoned-me.rb
Last active July 23, 2017 03:40
AWS Data Pipelines
aws_pipeline = client.create_pipeline(name: pipeline_name,
unique_id: pipeline_uid,
description: 'Automatic')
begin
# AWS uses different JSON formats for CLI and ruby sdk.
tempjson = Tempfile.new('tempjson')
tempjson.write(JSON.dump(pipeline_schema))
tempjson.rewind
`aws datapipeline put-pipeline-definition --pipeline-id #{aws_pipeline.pipeline_id} --pipeline-definition file://#{tempjson.path}`
ensure
@hwayne
hwayne / person.html
Last active January 28, 2018 00:26
person shortcode
{{ with index $.Site.Data.person (.Get 0) }}
{{ if .site }}
{{ printf "[%s](%s)" .name .site | markdownify }}
{{ else }}
{{ .name }}
{{ end }}
{{ end }}