Skip to content

Instantly share code, notes, and snippets.

@oluseyi
oluseyi / Lightbox-SwiftUI-UIKit.swift
Last active October 6, 2019 09:06
A snippet showing how easily UIKit and SwiftUI are bridged in Lightbox
import SwiftUI
struct ContentView : View {
var body: some View {
Timeline()
}
}
// ---
@oluseyi
oluseyi / lightbox-cocoa.rs
Last active October 6, 2019 09:47
That one time I dabbled with writing Mac applications in Rust using cocoa-rs…
// Mac GUI code in Rust, testing out feasibility. April 2017.
fn create_window() -> id {
unsafe {
let screen = NSScreen::mainScreen(nil);
let window_frame = screen.visibleFrame();
let window_frame = NSRect::new(NSPoint::new(window_frame.origin.x + 0.2 * window_frame.size.width,
window_frame.origin.y + 0.2 * window_frame.size.height),
NSSize::new(0.6 * window_frame.size.width,
0.6 * window_frame.size.height));
@oluseyi
oluseyi / LightboxSequential.swift
Last active October 6, 2019 09:39
An excerpt from a prototype brush implementation written on the iPad using Swift Playgrounds (!), in an app for sequential image layout (comics)
// Unrelated Swift excerpt, circa 2017
func addStrokePointForTouch(_ touch: UITouch) {
let loc = touch.location(in: self)
var radius = touch.majorRadius
if touch.type == .stylus {
radius = touch.force
touch.previousLocation(in: inputView)
}
let point = StrokePoint(point: loc, radius: radius)
@oluseyi
oluseyi / RLCompositor.m
Last active October 6, 2019 09:37
Excerpt from circa-2015 implementation of early rendering compositor (no layers)
// Objective-C snippet circa 2015
CMTime frameTime = CMTimeMake(timescale / self.frameRate, timescale);
NSUInteger frameStride = imageFilePaths.count;
NSUInteger maxIndex = frameStride - 1;
NSUInteger loopStride = frameStride * ((self.mirrorSequence) ? 2 : 1);
NSMutableArray *pixelBuffers = [NSMutableArray arrayWithCapacity:imageFilePaths.count];
NSUInteger frameCount = loopStride * self.loopCount;
for (int i = 0; i < frameStride; ++i) {
@oluseyi
oluseyi / build.rs
Created April 26, 2017 01:51
Trying to generate Rust bindings to Foundation, Cocoa, AppKit
extern crate bindgen;
use std::env;
use std::path::PathBuf;
fn main() {
let sdk_root = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk";
let framework_root = format!("{}/System/Library/Frameworks", sdk_root);
let bindings = bindgen::Builder::default()
@oluseyi
oluseyi / autolayout-not-so-bad.txt
Created December 6, 2016 06:16
RE: Why AutoLayout sucks
> 1. It's very slow on large, complicated layouts
True, but this can be mitigated by separating constraints into distinct sets, applied to subviews. Resolving a single set of constrainta on one view and its subviews is slower than resolving multiple distinct constraint sets applied to sifferent subviews as approriate.
> 2. Xcode's layout editor still sucks even though it's 100x better than it used to be.
I find it passable. How does it "suck" for you?
> 3. Runtime errors. No programming tool should create data that will cause runtime errors.
Might as well never use storyboards, or images, or data files, or… That simply isnt a reasonable position.
> 4. No way to diff layout changes in source code control because they're within the storyboard. Creating constraints in code is still pretty tedious, although better than it used to be.
@oluseyi
oluseyi / manually-migrate-ghost_db-001-008.sql
Created October 4, 2016 05:33
It wasn't worth the effort to write a proper migration from Ghost's db v001 to v004 or later, so I did it manually in SQLite.
CREATE TABLE accesstokens2 (
id integer PRIMARY KEY AUTOINCREMENT NOT NULL,
token text NOT NULL,
user_id integer NOT NULL,
client_id integer NOT NULL,
expires BIGINT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (client_id) REFERENCES clients (id)
);
@oluseyi
oluseyi / dispatch_closure
Created March 24, 2015 06:09
Eat your heart out, dispatch_once!
class AccountManager {
static let sharedInstance:AccountManager = {() -> AccountManager in
var instance = AccountManager()
instance.restoreIfAny()
return instance
}()
func restoreIfAny() {
// deserialize saved accounts
}
@oluseyi
oluseyi / gist:c9217ac35ff88e76cfd2
Created March 5, 2015 03:25
Thanks to an updated understanding of what .loadNibNamed will do for me…
class DocumentController: NSDocumentController {
@IBOutlet var toolsPanelController: NSWindowController!
@IBOutlet var timelinePanelController: NSWindowController!
@IBOutlet var layersPanelController: NSWindowController!
override init() {
super.init()
var topLevelObjects:NSArray? = []
NSBundle.mainBundle().loadNibNamed("panels", owner: self, topLevelObjects:&topLevelObjects)
@oluseyi
oluseyi / gist:8744dcdfbdf34c6f9da2
Created March 5, 2015 02:39
Interop between Swift and Cocoa remains grody in many places…
class DocumentController: NSDocumentController {
@IBOutlet weak var toolsPanelController: NSWindowController?
@IBOutlet weak var timelinePanelController: NSWindowController?
@IBOutlet weak var layersPanelController: NSWindowController?
override init() {
super.init()
var topLevelObjects:NSArray? = []
NSBundle.mainBundle().loadNibNamed("panels", owner: self, topLevelObjects:&topLevelObjects)