Skip to content

Instantly share code, notes, and snippets.

@natecook1000
natecook1000 / DictionaryObjectsForKeys.swift
Last active December 9, 2015 18:43
Initializers for Dictionary like NSDictionary +dictionaryWithObjects:forKeys:
// (c) 2015 Nate Cook, licensed under the MIT license
//
// Initializers for Dictionary like NSDictionary +dictionaryWithObjects:forKeys:
public extension Dictionary {
/// Creates a new Dictionary from the given `keys` and `values` collections.
///
/// More efficient than the sequence version because it can reserve the correct
/// capacity before filling the dictionary. Returns `nil` if the lengths of the
/// two collections differ.
@fbartho
fbartho / xcode-toggle.bash
Last active August 29, 2015 14:27
Bash implementation
#!/bin/bash
`xcode-select -p | grep -i beta > /dev/null`
if [ $? -eq 0 ]
then
echo "Using beta. Switching to release."
sudo xcode-select -s /Applications/Xcode.app
else
echo "Using release. Switching to beta."
sudo xcode-select -s /Applications/Xcode-beta.app
@kennwhite
kennwhite / vpn_psk_bingo.md
Last active February 24, 2024 12:19
Most VPN Services are Terrible

Most VPN Services are Terrible

Short version: I strongly do not recommend using any of these providers. You are, of course, free to use whatever you like. My TL;DR advice: Roll your own and use Algo or Streisand. For messaging & voice, use Signal. For increased anonymity, use Tor for desktop (though recognize that doing so may actually put you at greater risk), and Onion Browser for mobile.

This mini-rant came on the heels of an interesting twitter discussion: https://twitter.com/kennwhite/status/591074055018582016

@mbaranowski
mbaranowski / NSObject + injected
Created February 13, 2015 17:02
Give every NSObject a typesafe dependency injection class method (injected)
//
// NSObject+injected.h
//
#import <Foundation/Foundation.h>
#import <JInjector.h>
@interface NSObject (injected) <JInjectable>
+(instancetype)injected;
@end
@andymatuschak
andymatuschak / MultiDirectionAdjudicatingScrollView.swift
Created January 26, 2015 19:31
Source for the Khan Academy app's unusual scrolling interactions
//
// MultiDirectionAdjudicatingScrollView.swift
// Khan Academy
//
// Created by Andy Matuschak on 12/16/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
import UIKit.UIGestureRecognizerSubclass
@jedi4ever
jedi4ever / gist:7677d62f1414c28a1a8c
Last active November 20, 2020 07:28
Some notes on travisci remote debugging via ssh or screenshot or remote desktop of Mac VM builds
Some notes on remote debugging mac builds on Travisci. It's hard to tell when something hangs what the cause it. Trial and error via commits is tedious. And on Mac , sometimes it's the gui asking for input. So I worked my around to get the access I needed for faster debugging a build.
#################################################
# Enable remote ssh access to travisci build for debugging
#################################################
# Add a key so we can login to travisci vm
- cat ssh/travisci.pub >> ~/.ssh/authorized_keys
- chmod 600 ssh/travisci
# Install netcat
@rnapier
rnapier / gist:8eda179689d9d61c2bfb
Last active August 29, 2015 14:04
And autoclosure saves(?) the day for generic recursive enums
// Creating a generic recursive data structure with autoclosure. (READ ALL NOTES; THIS MAY NOT DO WHAT YOU WANT.)
// Closures are reference types, so the size is known (? I think ?)
// Note that this is just because of unimplemented features in the compiler in Beta5
// There's no reason to think this is a long-term requirement.
// IMPORTANT: the closure will run every time you access this value, so if that has
// side effects, this won't work. It's only possible on pure value types.
// But the fact that this works as expected is actually kind of incredible.
// Think about what is required for it to work out the type for NestedList.Elem("first").
@nicklockwood
nicklockwood / Hacking UIView Animation Blocks.md
Last active January 12, 2024 06:15
This article was originally written for objc.io issue 12, but didn't make the cut. It was intended to be read in the context of the other articles, so if you aren't familiar with concepts such as CALayer property animations and the role of actionForKey:, read the articles in that issue first.

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.

@lilyball
lilyball / gist:0928f2474cab04db18f4
Created July 8, 2014 00:36
Summary of Swift stdlib differences from b2 to b3
Interesting differences in the Swift standard library from b2 to b3:
A bunch of internal stuff got tweaked. That's all omitted here.
posix_read() / posix_write() have been deleted. I think the Darwin module's read()/write()/ are the same thing though.
+= operators for ArrayType + rhs have been removed, in favor of operators where the lhs is either Array<T>, ContiguousArray<T>, or Slice<T>. As those are the 3 builtin classes that implement ArrayType, this shouldn't make a difference to anyone. === and !== remain defined in terms of ArrayType.
a..b has been replaced with a..<b.
@kylesluder
kylesluder / AsyncAwait.swift
Last active May 15, 2020 06:01
A C#-style Async/Await implementation in Swift
// A much better version of C#-style Async/Await. It can return values!
import Cocoa
struct Await<T> {
// private
let group: dispatch_group_t
let getResult: () -> T
// public
func await() -> T { return getResult() }