Skip to content

Instantly share code, notes, and snippets.

View levi's full-sized avatar

Levi McCallum levi

View GitHub Profile
@levi
levi / Dockerfile
Created March 26, 2026 01:29
Minimal repro for Cloudflare Sandbox local startup failure (proxy-everything exits with setsockoptint: protocol not available)
FROM docker.io/cloudflare/sandbox:0.7.20
WORKDIR /workspace
//
// CurrencyDelegate.swift
// TextFieldDelegate
//
// Created by Timothy Isenman on 12/10/17.
// Copyright © 2017 Timothy Isenman. All rights reserved.
//
import Foundation
import UIKit
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if let digit = Int(string) {
amount = amount * 10 + digit
textField.text = String(describing: currencyAmount()!)
} else if string == "" {
amount = amount / 10
textField.text = String(describing: currencyAmount()!)
}
//: Implementation of a redux-like pattern in swift. Its current form lacks subscriptions.
import UIKit
/*:
## The Message
A message sent to the store's reducer to perform internal state mutation.
This is a protocol to provide significant flexibility in the types of Messages the app layer can provide the store. The most common case is an enum type with associated values.
@levi
levi / documentation.markdown
Last active November 29, 2019 16:06
AsyncDisplayKit Layout Transition API

AsyncDisplayKit Layout Transition API

Animating between layouts

The layout transition API makes it easy to animate between a node's generated layouts in response to some internal state change in a node.

Imagine you wanted to implement this sign up form and animate in the new field when tapping the next button:

Imgur

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
[layout prepareLayout];
CGSize size = [layout collectionViewContentSize];
CGRect rect = CGRectMake(0, 0, size.width, size.height);
NSArray *layoutAttributes = [layout layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes *attributes in layoutAttributes) {
switch (attributes.representedElementCategory) {
case UICollectionElementCategoryCell:
NSLog(@"Cell");
break;
@levi
levi / gist:b97ded2b8ec4f20931b7
Last active February 22, 2016 18:20
CGFloat Degrees to Radians Operator (Option+Shift+8)
postfix operator ° {}
postfix func ° (degrees: CGFloat) -> CGFloat {
return degrees * CGFloat(M_PI / 180.0)
}
// Example usage
let view = UIView()
view.transform = CGAffineTransformMakeRotation(45°)
@levi
levi / riot_esports_api.md
Last active March 24, 2026 15:16
Riot LoL eSports Unofficial API Documentation
Component = React.createClass
render: ->
`<ExampleComponent videos={this.props.videos} />`
@levi
levi / method.js
Created November 16, 2012 03:44
Playing with method() Method
if (typeof Function.prototype.method !== 'function') {
Function.prototype.method = function(name, implementation) {
this.prototype[name] = implementation;
return this;
};
}
var Person = function() {
this.name = name;
};