Skip to content

Instantly share code, notes, and snippets.

View u10int's full-sized avatar

Nicholas Shipes u10int

View GitHub Profile
@u10int
u10int / Cacher.swift
Created December 14, 2016 20:03 — forked from raulriera/Cacher.swift
Code sample for Medium article about Caching and Protocols
public protocol Cachable {
var fileName: String { get }
func transform() -> Data
}
final public class Cacher {
let destination: URL
private let queue = OperationQueue()
public enum CacheDestination {
@u10int
u10int / FRP iOS Learning resources.md
Created October 25, 2016 00:44 — forked from JaviLorbada/FRP iOS Learning resources.md
The best FRP iOS resources.

Videos

Hacking UIView animation blocks for fun and profit

In this article, I'm going to explore a way that we can create views that implement custom Core Animation property animations in a natural way.

As we know, layers in iOS come in two flavours: Backing layers and hosted layers. The only difference between them is that the view acts as the layer delegate for its backing layer, but not for any hosted sublayers.

In order to implement the UIView transactional animation blocks, UIView disables all animations by default and then re-enables them individually as required. It does this using the actionForLayer:forKey: method.

Somewhat strangely, UIView doesn't enable animations for every property that CALayer does by default. A notable example is the layer.contents property, which is animatable by default for a hosted layer, but cannot be animated using a UIView animation block.

extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
// Playground - noun: a place where people can play
import Cocoa
struct Regex {
let pattern: String
let expressionOptions: NSRegularExpressionOptions
let matchingOptions: NSMatchingOptions
init(pattern: String, expressionOptions: NSRegularExpressionOptions, matchingOptions: NSMatchingOptions) {

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep -H UI_APPEARANCE_SELECTOR ./* | sed 's/ __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;//'

UIActivityIndicatorView

@u10int
u10int / iOS_API+Blocks.h
Created December 11, 2012 17:10 — forked from puppybits/iOS_API+Blocks.h
Replace common iOS delegate APIs with blocks
//
// iOS_API+Blocks.h
//
// Created by Bobby Schultz on 12/1/11.
@interface UIAlertView (PBBlocks)
+ (id) alertWithTitle:(NSString*)title
message:(NSString*)message
clickedBlock:(void(^)(NSInteger))buttonIndexClickedBlock
@u10int
u10int / gist:4199467
Created December 4, 2012 00:46
Outputting Aeris Data in HW3
%%CODE __
$response = file_get_contents("http://api.aerisapi.com/observations/closest?p=%%zipcode%%&client_id= CLIENT_ID &client_secret= CLIENT_SECRET "); __
$json = json_decode($response); __
if ($json->success == true) { __
$Country = $json->response[0]->place->country; __
$cond = $json->response[0]->ob; __
echo ("<tr><td width='100%' colspan='2' align='center'><img src='%%hwvImagesPath%%" . ($tIcon=(!empty($cond->icon)) ? $cond->icon : "na.gif") . "' alt='" . $cond->weather . "' width='%%hwvImgWidth%%' height='%%hwvImgHeight%%' /></td></tr>"); __
echo ("<tr><td width='100%' colspan='2' align='center'><span class='Wx'>" . ($tWxshort=(!empty($cond->weatherShort)) ? $cond->weatherShort : "N/A") . "</span></td></tr>"); __
echo ("<tr><td valign='top'><span class='Temp'>Temp:</span></td><td valign='top' align='right'><span class='Temp'>" . ($tTemp=(!empty($cond->tempF)) ? (($Country == 'us') ? $cond->tempF : $cond->tempC) . "&deg;" : "N/A") . "</span></td></tr>"); __
echo ("</table></td><td valign='top' al
@implementation MKMapView (ZoomLevel)
- (NSUInteger) zoomLevel {
return (21 - round(log2(self.region.span.longitudeDelta * MERCATOR_RADIUS * M_PI / (180.0 * self.bounds.size.width))));
}
@end
@u10int
u10int / ISOCountryCodes.csv
Created November 29, 2012 15:41 — forked from jacobbubu/ISOCountryCodes.csv
iOS Country Codes
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
AD Andorra
AE United Arab Emirates
AF Afghanistan
AG Antigua and Barbuda
AI Anguilla
AL Albania
AM Armenia
AN Netherlands Antilles
AO Angola
AQ Antarctica