Skip to content

Instantly share code, notes, and snippets.

View MarcoSero's full-sized avatar

Marco Sero MarcoSero

View GitHub Profile
function lols {
random_num=$RANDOM
let "random_num %= 20"
if [ $random_num -eq 0 ]; then
alias hg="say hg && /usr/local/bin/hg"
else
alias hg="/usr/local/bin/hg"
fi
}
@vinhnx
vinhnx / timeZoneWithName.md
Last active December 17, 2015 09:43
NSTimeZone +timeZoneWithName:

For a list of known timezone supported in NSTimeZone, log:

[NSTimeZone knownTimeZoneNames]

The full list:

(lldb) po [NSTimeZone knownTimeZoneNames]
<__NSCFArray 0x7fba91903000>(
@nicklockwood
nicklockwood / gist:21495c2015fd2dda56cf
Last active August 13, 2020 13:57
Thoughts on Swift 2 Errors

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post:

@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 {
@rbobbins
rbobbins / protocols.md
Last active June 11, 2024 22:11
Notes from "Protocol-Oriented Programming in Swift"

PS: If you liked this talk or like this concept, let's chat about iOS development at Stitch Fix! #shamelessplug

Protocol-Oriented Programming in Swift

Speaker: David Abrahams. (Tech lead for Swift standard library)

  • "Crusty" is an old-school programmer who doesn't trust IDE's, debuggers, programming fads. He's cynical, grumpy.

  • OOP has been around since the 1970's. It's not actually new.

  • Classes are Awesome

    • Encapsulation
    • Access control
@lbrndnr
lbrndnr / gist:705946cb937fadeebca4
Created April 29, 2015 09:39
UIColor to init them using hex values: UIColor(0x8046A2)
extension UIColor {
convenience init(_ hexValue: Int) {
let r = (hexValue & 0xFF0000) >> 16
let g = (hexValue & 0x00FF00) >> 8
let b = hexValue & 0x0000FF
self.init(red: CGFloat(r)/255, green: CGFloat(g)/255, blue: CGFloat(b)/255, alpha: 1)
}
@JRHeaton
JRHeaton / zip3.swift
Created February 19, 2015 08:46
Implementing zip3 in Swift
struct Zip3Generator
<
A: GeneratorType,
B: GeneratorType,
C: GeneratorType
>: GeneratorType {
private var first: A
private var second: B
@jspahrsummers
jspahrsummers / GHRunLoopWatchdog.h
Created January 28, 2015 20:50
A class for logging excessive blocking on the main thread
/// Observes a run loop to detect any stalling or blocking that occurs.
///
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
@cabeca
cabeca / simulator_populator
Created September 23, 2014 21:30
This script removes and recreates all simulators in Xcode 6.
#!/usr/bin/env ruby
device_types_output = `xcrun simctl list devicetypes`
device_types = device_types_output.scan /(.*) \((.*)\)/
runtimes_output = `xcrun simctl list runtimes`
runtimes = runtimes_output.scan /(.*) \(.*\) \((com.apple[^)]+)\)$/
devices_output = `xcrun simctl list devices`
devices = devices_output.scan /\s\s\s\s(.*) \(([^)]+)\) (.*)/
@steipete
steipete / gist:d76549ec262430354e7c
Last active December 3, 2018 23:56
Our set of warnings in PSPDFKit
//
// Warnings.xcconfig
//
// The list of warnings we (don’t) use, and the reasons why.
//
// :MARK: Warnings in use:
// :MARK: -everything
// We want the best possible diagnostics, so we simply enable everything that exists, and then opt–out of what doesn’t make sense for us.
//
// :MARK: - Warnings not to be promoted: