Skip to content

Instantly share code, notes, and snippets.

View levi's full-sized avatar

Levi McCallum levi

View GitHub Profile
@levi
levi / riot_esports_api.md
Last active November 8, 2023 16:38
Riot LoL eSports Unofficial API Documentation
@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

//
// 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 / 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°)
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;
};
@levi
levi / gist:4083325
Created November 16, 2012 02:15
Private Members and Privileged Methods in Constructors and Objects
function Animal() {
var name = 'Lion';
// privileged method
this.getName = function() {
return name;
};
}
var lion = new Animal();
@levi
levi / namespace.js
Created November 16, 2012 01:42
Dynamic Namespaces
var APP = {};
APP.namespace = function(path) {
var parts = path.split('.'),
parent = APP;
if (parts[0] === 'APP') parts = parts.slice(1);
for (var i = 0, len = parts.length; i < len; i++) {
if (typeof parent[parts[i]] === 'undefined') {