Skip to content

Instantly share code, notes, and snippets.

Multimap.swift

Being able to insert into a Dictionary<Key, Array<Values>> without having to explicitly handle the fact that the value array is nil on the very first insert for a given key.

The code isn't difficult, but it is repetitive boilerplate. And it is also a decent example of extending a generic type in Swift.

@bwoods
bwoods / hrefs.js
Created January 24, 2020 22:30
All links on a webpage
Array.prototype.map.call(document.querySelectorAll('nav a'), function (e) { return e.getAttribute('href'); });

Shell scripting with Markdown documents

alias ~~~=":<<'~~~sh'";:<<'~~~sh'

@bwoods
bwoods / not.md
Created November 21, 2022 23:06
Swift .not “operator”
public extension Bool {
    static func not(_ exp: @autoclosure () -> Bool) -> Bool {
        !exp()
    }
}

Usage:

@bwoods
bwoods / xbox_button_names.md
Created May 24, 2023 07:00 — forked from palmerj/xbox_button_names.md
Xbox Controller Button Names and Layout

Buttons

  • RSB == Right Stick Button
  • LSB == Left Stick Button
  • RB == Right Bumper
  • RT == Right Trigger
  • LB == Left Bumper
  • LT == Left Trigger
  • Y == Y Button (Top)
  • A == A Button (Bottom)