Skip to content

Instantly share code, notes, and snippets.

@garrow
garrow / represent-petri-net-in-typescript.ts
Created March 17, 2022 23:34
An attempt to make the Typescript compiler do some basic validation of a petri net, ensuring that only defined places (nodes) can be used, both for the places, and transitions (vertices) of the graph.
export {}
// Representing Petri Nets as typed values in Typescript.
type PlaceID = string
type Place<P extends PlaceID = PlaceID> = {
id: P
}
type Transition<P> = {
start: P
end: P
@garrow
garrow / main.gs
Created November 14, 2018 19:18
gmail-query-auto-archiver
function main() { autoArchiveMail() }
// A mapping of a query / saved search, and the ageCutoff for archiving.
function archiveMap() {
return [
{query: inbox('label:expirable label:stripe'), ageCutoff: hoursOld(1)}, // Quickly burn these
{query: inbox('"Your meeting attendees are waiting!"'), ageCutoff: hoursOld(1)}, // Quickly burn these
{query: inbox('label:n'), ageCutoff: hoursOld(6)},
{query: inbox('label:expirable'), ageCutoff: hoursOld(6)},
{query: inbox('label:office'), ageCutoff: daysOld(10)}, // Offce Notices
@garrow
garrow / README.md
Last active November 22, 2016 23:24
Delete all remote merged branches

Delete all remote merged branches

This will;

  • Lists all remote merged branches
  • Exclude master branch
  • Exclude stable branch
  • Remove the origin/ prefix
  • Push the deletion (one by one)
@garrow
garrow / gist:146ef5bf6d95e4c0e355f484a4cb57db
Last active October 2, 2016 04:14
Disable Dropbox's automatic reauthorising itself for Accessibility
# So I can access the following data only methods in both views and in class level validations, do I?
# e.g.
# validates :event_progress, inclusion: { in: event_progressions }
#
# = f.select :owner_relationship, f.object.owner_relationships, {}, class: "form-control"
########################################################################################################################
# 1) I tried defining as instance methods & use procs to access in validations
# DOESNT WORK - undefined method `event_progressions' for Forms::WeddingMoodboard:Class
def owner_relationships
%w{ALPHA BRAVO CHARLIE DELTA}
@garrow
garrow / console.question.rb
Last active August 29, 2015 14:07
WiiThree
# A new game console has been released, the WiiThree
# We need to add support for this new console to this code.
#
# It will require console specific code for each type of console.
# Add this feature to the code below.
class GameRenderer
def initialize(console)
@console = console
end
class Object
class << self
alias :🆕 :new
end
end
class FishingRod
def 🔪
puts "🍣"
@garrow
garrow / trifle_contracts_spec.rb
Last active August 29, 2015 13:56
A quick and crazy go at implementing contracts using Ruby 2.1 and naive evals.
require 'rspec'
require 'pry'
module Trifle
class BrokenContract < Exception ; end
def contract(*contracts, method_name)
old_method_name = :"__contractually_obligated_#{method_name}"
alias_method old_method_name, method_name
@garrow
garrow / big_decimal_matcher.rb
Created January 17, 2014 00:24
Quick and dirty rspec BigDecimal matcher
RSpec::Matchers.define :be_decimal do |expected|
match do |actual|
coerce(actual) == coerce(expected)
end
failure_message_for_should do |actual|
"expected that #{format(actual)} would equal #{format(expected)}"
end
def coerce(value)