Skip to content

Instantly share code, notes, and snippets.

@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)
@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:

Shell scripting with Markdown documents

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

@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'); });

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 / git-describe.sh
Last active August 25, 2018 22:52
Xcode build step placing the git hash in the Settings.bundle
# TestFlight has… opinions… about the CFBundleShortVersionString, so this is removed
#defaults write ${CODESIGNING_FOLDER_PATH}/Info CFBundleShortVersionString `git describe --dirty=+ --tags --always`
# add the version info to the Settings.bundle
GitVersion=$(git describe --dirty=+ --tags --always)
CFBundleShortVersionString=$(defaults read ${CODESIGNING_FOLDER_PATH}/Info CFBundleShortVersionString)
plutil -insert PreferenceSpecifiers.0 -xml "<dict><key>DefaultValue</key><string>${CFBundleShortVersionString} (${GitVersion})</string><key>Key</key><string>Version</string><key>Title</key><string>Version</string><key>Type</key><string>PSTitleValueSpecifier</string></dict>" ${CODESIGNING_FOLDER_PATH}/Settings.bundle/Root.plist
@bwoods
bwoods / Acknowledgements.swift
Last active August 26, 2018 00:01 — forked from eoghain/acknowledgements.py
Swift script to generate Acknowledgements.plists (in the Settings.bundle) for the licenses of open source software you are using in your application.
// env -i swift Application/Acknowledgements.swift > $CODESIGNING_FOLDER_PATH/Settings.bundle/Acknowledgements.plist
import Foundation
let fileManager = FileManager()
let folders = try! fileManager.contentsOfDirectory(atPath: fileManager.currentDirectoryPath).sorted()
var specifiers = [[ "Type" : "PSGroupSpecifier", "Title" : "Open Source", "FooterText" : "This application uses the following third party libraries:" ]]
folders.forEach { folder in
if let path = [ "LICENSE.md", "LICENSE", "COPYING" ].lazy.map({ "\(folder)/\($0)" }).first(where: { fileManager.fileExists(atPath: $0) }) {
var license = (try! String(contentsOfFile: path, encoding: .utf8).replacingOccurrences(of: "(c)", with: "©"))
@bwoods
bwoods / Github Flavored Markdown.md
Created March 26, 2018 05:41 — forked from stevenyap/Github Flavored Markdown.md
Github Flavored Markdown cheatsheet

Github Flavored Markdown (GFMD) is based on Markdown Syntax Guide with some overwriting as described at Github Flavored Markdown

Text Writing

It is easy to write in GFMD. Just write simply like text and use the below simple "tagging" to mark the text and you are good to go!

To specify a paragraph, leave 2 spaces at the end of the line

Headings

@bwoods
bwoods / PlatonicSolidsOfSoftwareConstruction.md
Last active December 31, 2017 10:24 — forked from bryanedds/PlatonicSolidsOfSoftwareConstruction.txt
The Platonic Solids of Software Construction and Their Realization in C

Six Platonic Solids of Software Construction

@bryanedds

No matter the business domain or programming language, programmers always end up needing support for ALL of these things in some form,

  • Resource Semantics (such as RAII in C++, or finalizers in C#)
  • Error Semantics (such as exceptions in most languages, or conditions in Common Lisp)
  • Algebraic Types (such as structs and unions in C, or records and DUs in F#)
  • Data Abstraction (such as that which is often badly entangled within object systems in OO languages)
@bwoods
bwoods / FORECAST
Created December 9, 2017 03:16
Linear Interpolation in a Spreadsheet
FORECAST(x,
INDEX(ys,MATCH(x,xs,1)):INDEX(ys,MATCH(x,xs,−1)),
INDEX(xs,MATCH(x,xs,1)):INDEX(xs,MATCH(x,xs,−1)))