Skip to content

Instantly share code, notes, and snippets.

@bwoods
bwoods / UnicodeData.cpp
Last active May 31, 2024 23:27
Parsing UnicodeData.txt
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <array>
digraph {
ranksep=.75
" " // end node
{
node [shape=plaintext, fontsize=12]
1973 -> 1983 -> 1990 -> 1996 -> 2000 -> 2001 -> 2004 -> 2005 -> 2010 -> 2011 -> 2014
"ML"; "C++"; "Standard ML"; "OCaml"; "C#"; D; Scala; "F#"; Rust; Ceylon; Kotlin; Swift
}
@bwoods
bwoods / tiny_gzip_decompressor.cc
Created October 3, 2016 18:23
Joel Yliluoma’s tiny gzip decompressor (without using zlib) — http://pastebin.com/kYKpfUjd
/* My tiny gzip decompressor without using zlib. - Joel Yliluoma
* http://iki.fi/bisqwit/ , http://youtube.com/user/Bisqwit
* Inspired and influenced by a 13th IOCCC winner program by Ron McFarland */
/* Fun fact: Contains zero new/delete, and no STL data structures */
#include <assert.h>
// This is the public method declared (later) in this file.
template<typename InputFunctor, typename OutputFunctor>
void Deflate(InputFunctor&& input, OutputFunctor&& output);
@bwoods
bwoods / UITableViewDelegate.swift
Created April 21, 2017 05:58
UITableViewCell with bottom-centered fixed-width image
// MARK: - UITableViewDelegate methods
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let margin: CGFloat = 8
var size = CGSize(width: cell.bounds.height - margin, height: cell.bounds.height - margin)
if cell.imageView!.image!.size.width > cell.imageView!.image!.size.height {
let factor = cell.imageView!.image!.size.width / cell.imageView!.image!.size.height;
size.height = size.height / factor;
}
else {
@bwoods
bwoods / sqlite3.hpp
Last active October 13, 2017 05:56
A (light) C⁺⁺¹⁴ wrapper for SQLite₃
#include <stdexcept>
#include <memory>
#include <limits>
#include <sqlite3.h>
#include <assert.h>
namespace sql {
@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)))
@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 / 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 / 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 / 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