Skip to content

Instantly share code, notes, and snippets.

View day9.py
#!/bin/python
# https://adventofcode.com/2020/day/9
with open('day9.txt') as f:
heightmap = [list(map(int, line.strip())) for line in f]
H, W = len(heightmap), len(heightmap[0])
COORDS = [(x, y) for y in range(H) for x in range(W)]
value_at = lambda p: heightmap[p[0]][p[1]]
View day5.py
#!/bin/python
# solution for https://adventofcode.com/2021/day/5
data = []
with open('day5.txt') as f:
for line in f:
data.append([tuple(map(int, c.split(','))) for c in line.strip().split(' -> ')])
def get_line_points(pair):
View day1.py
#!/bin/python
with open('day1.txt') as f:
measurements = list(map(int, f))
def compare(values):
return [m for i, m in enumerate(values) if i and m > values[i-1]]
print(f"Part One: {len(compare(measurements))}")
View day2.py
#!/bin/python
class Submarine():
def __init__(self):
self.horizontal = 0
self.depth = 0
self.aim = 0
def forward(self, amount):
self.horizontal += amount
self.depth += amount * self.aim
View machine.js
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@Tomalak
Tomalak / Twitter-uBlock.txt
Last active Jul 20, 2021
Custom blocking rules for websites I use.
View Twitter-uBlock.txt
! Twitter element block rules, for use in uBlock Origin -------------------------
! ads ---------------------------------------------------------------------------
twitter.com##div.suggested-tweet-stream-container
twitter.com##div.promoted-tweet
twitter.com##li.promoted-trend
twitter.com##div.Footer-adsModule
twitter.com##div.js-actionable-user.promoted-account
! timeline breakers -------------------------------------------------------------
twitter.com##.js-stream-item[data-suggestion-json*='RecycledTweetInline']
View rulesets.txt
! uMatrix: Ruleset recipes 1.0
! Title: My various uBlock rulesets
! Maintainer: Tomalak
Vine.co Embeded Frames
* vine.co
_ vine.co image
_ vine.co css
_ vine.co script
_ vine.co frame
View keybase.md

Keybase proof

I hereby claim:

  • I am tomalak on github.
  • I am tomalak (https://keybase.io/tomalak) on keybase.
  • I have a public key whose fingerprint is 131F C1F5 BEFD 5B22 7E26 24F1 134E 854E 117D 1A21

To claim this, I am signing this object:

@Tomalak
Tomalak / linq-multilevel-grouping.js
Created Jan 3, 2015
linq.js Dynamic Multilevel Grouping
View linq-multilevel-grouping.js
/* Utility functions to create a nested, multilevel grouped, ordered
* structure out of a flat array of uniform objects.
*
* usage: result = applyStructure(items, structure);
*
* structure is an object of the form:
* {
* group: "propertyName1"
* order: ["propertyName1", "propertyName2 DESC", ...]
* next: {
@Tomalak
Tomalak / knockout-undoBuffer.js
Created Aug 29, 2014
A "multi-level undo" extender for Knockout observables.
View knockout-undoBuffer.js
ko.extenders.undoBuffer = function (target, maxUndo) {
var undoBuffer = ko.observableArray([]), undoing;
target.canUndo = ko.computed(function () {
return undoBuffer().length > 0;
});
target.undo = function () {
if (!target.canUndo()) return;
undoing = true;
target(undoBuffer.pop());