Skip to content

Instantly share code, notes, and snippets.

View radex's full-sized avatar
🚀
Full reusability

Radek Pietruszewski radex

🚀
Full reusability
View GitHub Profile
@Duder-onomy
Duder-onomy / State Bounding Boxes
Created December 1, 2018 01:57
State Bounding Boxes
'Alabama': [
[-84.8882446289062, 35.0080299377441],
[-88.4731369018555, 30.1375217437744],
],
'Alaska': [
[-129.9795, 71.4410],
[-179.1505, 51.2097],
],
'Arizona': [
[-109.045196533203, 37.0042610168457],
@krzysztofzablocki
krzysztofzablocki / template.stencil
Last active January 14, 2017 15:22
AutoEquatable template
// swiftlint:disable file_length
fileprivate func compareOptionals<T>(lhs: T?, rhs: T?, compare: (_ lhs: T, _ rhs: T) -> Bool) -> Bool {
switch (lhs, rhs) {
case let (lValue?, rValue?):
return compare(lValue, rValue)
case (nil, nil):
return true
default:
return false
@mackuba
mackuba / wwdc16.md
Last active March 5, 2023 21:28
New stuff from WWDC 2016

Following the tradition from last year, here's my complete list of all interesting features and updates I could find in Apple's OSes, SDKs and developer tools that were announced at this year's WWDC. This is based on the keynotes, the "What's New In ..." presentations and some others, Apple's release notes, and blog posts and tweets that I came across in the last few weeks.

If for some reason you haven't watched the talks yet, I really recommend watching at least the "State of the Union" and the "What's New In" intros for the platforms you're interested in. The unofficial WWDC Mac app is great way to download the videos and keep track of what you've already watched.

If you're interested, here are my WWDC 2015 notes (might be useful if you're planning to drop support for iOS 8 now and start using some iOS 9 APIs).


OSX → macOS 10.12 Sierra

@odrobnik
odrobnik / gist:a02ac1e49ff90ec4f8a7
Last active January 4, 2018 17:37
Upload progress reporting NSProgress for NSURLSessionTask
import Foundation
public class UploadProgress: NSProgress
{
var sessionTask: NSURLSessionTask!
required public init(sessionTask: NSURLSessionTask)
{
super.init(parent: nil, userInfo: nil)
@orta
orta / Podfile.ruby
Created October 22, 2015 07:42
make frameworks the same as your bundle id
post_install do |installer|
app_plist = "Emergence/Info.plist"
plist_buddy = "/usr/libexec/PlistBuddy"
version = `#{plist_buddy} -c "Print CFBundleShortVersionString" #{app_plist}`.split
puts "Updating CocoaPods' version numbers to #{version}"
installer.pods_project.targets.each do |target|
`#{plist_buddy} -c "Set CFBundleShortVersionString #{version}" "Pods/Target Support Files/#{target}/Info.plist"`
end
end
@mackuba
mackuba / wwdc15.md
Last active August 6, 2022 17:28
New stuff from WWDC 2015

Here's my own list of the interesting stuff announced during this year's WWDC, collected from the keynotes, various Apple docs, blog posts and tweets.

If you're planning to watch the videos, I really recommend this Mac app that helps you download and watch them: https://github.com/insidegui/WWDC.

OS X El Capitan

http://www.apple.com/osx/elcapitan-preview/

  • split view - two apps side by side on full screen
@chriseidhof
chriseidhof / json.swift
Last active March 21, 2019 07:45
Reflection
import Cocoa
struct Person {
var name: String = "John"
var age: Int = 50
var dutch: Bool = false
var address: Address? = Address(street: "Market St.")
}
struct Address {
@rnapier
rnapier / gist:dbffbf54274a880a6ac7
Last active July 12, 2016 01:29
More exploration of guard/try and crazy operator idea
// This is pretty clean, but I often dislike chains of temporary variables
// They tend to lead to little bugs when you use the wrong one. Swift's warnings
// and 'let' reduce problems, though.
func pagesFromOpenSearchData(data: NSData) throws -> [Page] {
let json = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions())
guard let array = json as? [JSON] else { throw JSONError.BadArray(json) }
guard case let value = array[1] where array.count >= 2 else { throw JSONError.OutOfRange }
guard let titles = value as? [String] else { throw JSONError.BadStringList(json) }
@chriseidhof
chriseidhof / Main.swift
Last active March 11, 2016 06:59
Protocol Extensions
protocol OptionalType {
typealias T
var optional: T? { get }
}
extension Optional : OptionalType {
var optional: T? { return self }
}
extension SequenceType where Generator.Element: OptionalType {
Your goals are to reduce the number of things that you have to keep in your head at any given moment, and to rely as little as possible on your own ability to consistently do things right.
If you make a thing immutable ('let' in swift), you never have to think about what happens if it changes, or what other parts of the code you'll effect if you change it.
If you split complex functions into several smaller functions that only interact by passing arguments or getting return values, then you limit the amount of code you need to consider when hunting for a bug, and you can test each small piece separately.
If you understand what things must be true in your code (aka invariants, for example "a person's age must be greater than 0"), and either provide no function that can cause them to be untrue, or check and crash immediately when they're untrue, then you don't have to debug issues caused by incorrect assumptions.
If you remove possibilities (for example, Swift removes the possibility of things being nil unless