Skip to content

Instantly share code, notes, and snippets.

Alexander von Below below

  • Deutsche Telekom AG
  • Köln, Germany
View GitHub Profile
@below
below / ProtocolPlayground.swift
Created Nov 8, 2016
Why does this work if I test for the class, and not for the protocol?
View ProtocolPlayground.swift
//: Playground - noun: a place where people can play
import Foundation
protocol MyProtocol {
var value: Int! { get set }
}
class MyClass : MyProtocol {
var value : Int!
@below
below / QueryPlayground.swift
Created Jul 26, 2016
Why is NSQueryItem not percent escaping "+" in a query?
View QueryPlayground.swift
import UIKit
let comps = NSURLComponents(string: "https://example.com")
comps?.queryItems = [NSURLQueryItem(name: "foobar", value: "foo+bar&something else")]
comps!.URL!
// Actual result:
// https://example.com?foobar=foo+bar%26something%20else
// As per https://tools.ietf.org/html/rfc3986#section-2.1 it
// appears that '+' should be escaped. What am I overlooking?
View Universal URLs
So my universal URLs are not working.
In order to track down the problem, I checked the embedded.mobileprovision file. And here I find:
<key>Entitlements</key>
<dict>
<!-- stuff -
<key>com.apple.developer.associated-domains</key>
<string>*</string>
@below
below / NEHotspotEnum.playground
Created Mar 3, 2016
Why is the NEHotspotHelperConfidence not nil if out of bounds?
View NEHotspotEnum.playground
import UIKit
import NetworkExtension
//: First a classical enum. As documented, it will be nil if initialized with a rawValue outside of bounds
//: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Enumerations.html
enum Foobar : Int {
case foo
case bar
}
@below
below / gist:cfc8ac57458cce66b137
Created May 14, 2015
I should admit that I don't regularly work in ruby, so I am pretty stuck here. I am trying to download a https url using NET::HTTP:get, and I get this error. Downloading the URL in curl (even if called from the script) works just fine. What to do?
View gist:cfc8ac57458cce66b137
/Users/below/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/http.rb:920:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
from /Users/below/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/http.rb:920:in `block in connect'
from /Users/below/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/timeout.rb:76:in `timeout'
from /Users/below/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/http.rb:920:in `connect'
from /Users/below/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/http.rb:863:in `do_start'
from /Users/below/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/http.rb:852:in `start'
from /Users/below/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/http.rb:583:in `start'
from /Users/below/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/http.rb:478:in `get_response'
from /Users/below/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/http.rb:455:in `get'
from export.rb:4:in `<main>'
View gist:2b9babcae6aee20c6bae
Dyld Error Message:
Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /private/var/mobile/Containers/Bundle/Application/AC0A08F8-3993-48F2-A1EF-9188AC8C19BA/XYZ.app/XYZ
Reason: no suitable image found. Did find:
/private/var/mobile/Containers/Bundle/Application/AC0A08F8-3993-48F2-A1EF-9188AC8C19BA/XYZ.app/Frameworks/libswiftCore.dylib: mmap() error 1 at address=0x1004E8000, size=0x0018C000 segment=__TEXT in Segment::map() mapping /private/var/mobile/Containers/Bundle/Application/AC0A08F8-3993-48F2-A1EF-9188AC8C19BA/XYZ.app/Frameworks/libswiftCore.dylib
Dyld Version: 353.12
View AAAND the IProgressMonitor
#include <boost/shared_ptr.hpp>
#include <configuration/api/IConfigurationReport.hpp>
namespace whisper
{
namespace configuration
{
using boost::shared_ptr;
using whisper::configuration::PConfigurationReport;
@below
below / gist:e57cfb9323a5ef360e93
Created Mar 23, 2015
No longer working in Swift 1.2
View gist:e57cfb9323a5ef360e93
// In Swift 1.1, I can use "let sideshow : Sideshow!". In Swift 1.2 it has to be a var
// Is this due to the change:
// "In an initializer, constant properties can now only assign a value once." ?
class Main {
var name : String
let sideshow : ImplicitlyUnwrappedOptional<Sideshow>
init (name : String, referenceName : String) {
self.name = name
self.sideshow = Sideshow(name: referenceName, ref: self)
View gist:475cdfd44550496e0aff
import UIKit
protocol myProtocol {
func dothatthing () -> Void
}
var array : [protocol<myProtocol>] = []
class A : myProtocol {
func dothatthing() {
@below
below / FileHandle.playground
Created Oct 28, 2014
Swift FileHandle Test
View FileHandle.playground
// Playground - noun: a place where people can play
import Cocoa
import XCPlayground
let path = XCPSharedDataDirectoryPath + "log.txt"
let fileURL = NSURL(fileURLWithPath: path)
if (fileURL != nil) {
var error : NSError? = nil;
let fileHandle = NSFileHandle(forWritingToURL: fileURL!, error:&error)
You can’t perform that action at this time.