Skip to content

Instantly share code, notes, and snippets.

@klaas
klaas / UIView+Orientation.swift
Last active January 31, 2016 21:29
View orientation
// Swift version of: https://gist.github.com/smileyborg/a5d1355773ad2ba6bb1e
public enum ViewOrientation {
case Portrait
case Landscape
}
extension UIView {
public class func viewOrientationForSize(size:CGSize) -> ViewOrientation {
return (size.width > size.height) ? .Landscape : .Portrait
@smileyborg
smileyborg / convert_imports.rb
Last active June 26, 2017 11:10
A script to convert textual imports to framework imports. Useful when converting static libraries to dynamic frameworks.
#!/usr/bin/env ruby
require 'set'
UMBRELLA_HEADER_PATH = ARGV[0] # The path to the umbrella header containing all the headers
SOURCE_ROOT_PATH = ARGV[1] # The path containing the source files to convert (will be recursively searched)
FRAMEWORK_NAME = File.basename(UMBRELLA_HEADER_PATH, ".*") # Assumes that the framework name is the same as the umbrella header filename (e.g. "MyFramework" for "MyFramework.h")
UMBRELLA_IMPORT_REGEX = /#import\s+<#{FRAMEWORK_NAME}\/.+\.h>/ # Matches "#import <FrameworkName/Header.h>"
FRAMEWORK_HEADER_REGEX = /(?<=<#{FRAMEWORK_NAME}\/).+\.h(?=>)/ # Matches "Header.h" in "<FrameworkName/Header.h>"
@smileyborg
smileyborg / Xcode7Macros.h
Last active May 26, 2020 12:08
Backwards compatible macros for Objective-C nullability annotations and generics
/**
* The following preprocessor macros can be used to adopt the new nullability annotations and generics
* features available in Xcode 7, while maintaining backwards compatibility with earlier versions of
* Xcode that do not support these features.
*/
#if __has_feature(nullability)
# define __ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
# define __ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
# define __NULLABLE nullable
@smileyborg
smileyborg / UIView+Orientation.h
Last active February 2, 2021 14:57
Migrating Rotation Code to iOS 8
//
// UIView+Orientation.h
//
#import <UIKit/UIKit.h>
// These macros should only be used if you MUST know the interface orientation for the device itself, for example when displaying a new UIWindow.
// This should be very rare; generally you should only look at the immediate parent view's size (or "view orientation" using the category below).
#define StatusBarOrientationIsPortrait UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])
#define StatusBarOrientationIsLandscape UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])
@smileyborg
smileyborg / detect_evil_merge.sh
Last active August 16, 2023 04:00
Two scripts that can be used to detect evil merges in Git. See http://stackoverflow.com/questions/27683077
#!/bin/bash
# A shell script to provide a meaningful diff output for a merge commit that can be used to determine whether the merge was evil.
# The script should be run from outside the git repository, with two arguments:
# 1 - the directory of the git repository
# 2 - the SHA for the merge commit to inspect
# The script will output one file:
# - the merge redone fresh without any conflicts resolved, diff'ed to the actual merge
output_file="diff.txt"
@andymatuschak
andymatuschak / CollectionViewDataSource.swift
Last active February 12, 2021 09:44
Type-safe value-oriented collection view data source
//
// CollectionViewDataSource.swift
// Khan Academy
//
// Created by Andy Matuschak on 10/14/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
@eternalstorms
eternalstorms / Apple Evangelists.txt
Created June 12, 2013 09:07
Apple Evangelists (WWDC 2013)
UI- and App Frameworks Evangelist - Jake Behrens, [email protected], twitter: @Behrens
- What's new in Cocoa
- Accessibility in iOS
- Building User Interfaces for iOS 7
- Getting Started with UIKit Dynamics
- What's new in Cocoa Touch
- What's New With Multitasking
- Best Practices for Cocoa Animation
- Improving Power Efficiency with App Nap
- Introducing Text Kit
@darktable
darktable / app.yaml
Created March 16, 2011 19:10
GAE: App.yaml designed for serving a static site on Google App Engine (Python). Copy your static html and files into a folder called "static" next to app.yaml. Contains a bunch of mimetype declarations from html5boilerplate's .htaccess. May not be neces
application: you-app-name-here
version: 1
runtime: python
api_version: 1
default_expiration: "30d"
handlers:
- url: /(.*\.(appcache|manifest))
mime_type: text/cache-manifest