Skip to content

Instantly share code, notes, and snippets.

View diagrams.swift
//
// Diagrams.swift
// DiagramsSample
//
// Created by Chris Eidhof on 16.12.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import SwiftUI
View protocols-vs-values.swift
import PlaygroundSupport
import Foundation
struct Resource<A> {
var request: URLRequest
var parse: (Data) throws -> A
}
protocol Loadable {
static var request: URLRequest { get }
@floriankugler
floriankugler / AutoLayoutHelpers.swift
Last active May 5, 2020
Very simple key path based Auto Layout helpers
View AutoLayoutHelpers.swift
import UIKit
typealias Constraint = (UIView, UIView) -> NSLayoutConstraint
func equal<L, Axis>(_ to: KeyPath<UIView, L>, constant: CGFloat = 0) -> Constraint where L: NSLayoutAnchor<Axis> {
return equal(to, to, constant: constant)
}
func equal<L, Axis>(_ from: KeyPath<UIView, L>, _ to: KeyPath<UIView, L>, constant: CGFloat = 0) -> Constraint where L: NSLayoutAnchor<Axis> {
return { view1, view2 in
View PropertiesDecoder.swift
import Cocoa
public final class PropertiesDecoder: Decoder {
static func decode<T: Decodable>(_ type: T.Type) throws -> [String] {
let d = PropertiesDecoder()
_ = try T(from: d)
return d.fields
}
public var codingPath: [CodingKey] { return [] }
View libyaml.swift
// gem install cocoapods-playgrounds
// pod playgrounds LibYAML
// Paste in the following:
import LibYAML
struct YAMLError: ErrorType {
let problem: String
let problemOffset: Int
@floriankugler
floriankugler / gist:8767926
Created Feb 2, 2014
NSStringGenderRuleType example
View gist:8767926
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>congratulate %@ to %d(his/her) birthday</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>Congratulate %@ to %#@pronoun@ birthday</string>
<key>pronoun</key>
<dict>
@floriankugler
floriankugler / gist:6870499
Last active Aug 3, 2021
Mapping of NSURLConnection to NSURLSession delegate methods. Created by Mattt Thompson.
View gist:6870499
NSURLConnection | NSURLSession
------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------
NSURLConnectionDelegate connectionShouldUseCredentialStorage: |
------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------
NSURLConnectionDelegate connection:willSendRequestForAuthenticationChallenge: | NSURLSessionDelegate URLSession:didReceiveChallenge:completionHandler:
| N
View gist:5760217
In order for this to work you need ffmpeg. I tried with version 1.2.1.
1) Play the video you want to download in the browser
2) Inspect the video element on the page
3) Copy the video url from the page source (something like http://devstreaming.apple.com/videos/wwdc/2013/.../101/ref.mov)
4) In this url replace "ref.mov" with "iphone_c.m3u8" (for 960x540 resolution) or "atp.m3u8" if you want more (probably 720p?)
5) Execute `ffmpeg -y -i http://devstreaming.apple.com/videos/wwdc/2013/.../101/iphone_c.m3u8 output.mp4`
6) There is your video :)
@floriankugler
floriankugler / gist:1483323
Created Dec 15, 2011
garcon build definition
View gist:1483323
// buildfile.js -----------------------------------------
var garcon = require('garcon');
var SproutCore = require('frameworks/sproutcore/buildfile');
module.exports = MyProject;
var MyProject = garcon.Project.extend({
View gist:1453301
var tools = require('../tools');
var Handler = require("./handler").Handler;
var Join, HandlerSet;
Join = Handler.extend({
data: null,
handle: function(file,request,callback){