Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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);
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 / UnicodeData.cpp
Last active January 13, 2021 23:31
Parsing UnicodeData.txt
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <array>
@bwoods
bwoods / literals.hpp
Created December 17, 2015 21:12
C++11 user defined literals for std::integral_constant<int64_t, N>
namespace literals { // inspired by http://codereview.stackexchange.com/a/51576
constexpr int64_t combine(int64_t accumulator) {
return accumulator;
}
template <typename... Characters>
constexpr int64_t combine(int64_t accumulator, char character, Characters... Rest) {
int digit = (character >= '0' && character <= '9') ? character - '0'
: throw std::range_error("Only decimal literals are supported.");
@bwoods
bwoods / raii.hpp
Last active September 19, 2015 22:48
#pragma once
#include <type_traits>
namespace raii {
template <class T>
class pointer {
template <typename D>
@bwoods
bwoods / uniform_type_identifiers.cpp
Last active September 20, 2015 04:34
Parse Application bundles for UTI information
#include <CoreFoundation/CoreFoundation.h>
#include <sqlite3/sqlite3.h>
#include <cstdio>
#include <iterator>
#include <vector>
#include "raii/raii.hpp"
@bwoods
bwoods / declname.cpp
Created July 8, 2015 23:55
demangle C++ TypeID names (std::unique_ptr version)
#include <cxxabi.h> // gcc and clang…
#include <stdlib.h>
auto demangle(std::string&& name) -> std::unique_ptr<char, void(*)(char *)>
{
int status = 0;
return { abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), [] (char * p) { ::free(p); } };
}
template <typename... T, int... I>
static auto subtuple(std::tuple<T...>&& tuple, std::index_sequence<I...>) {
return std::make_tuple(std::get<I>(tuple)...);
}