This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var inStr:String | |
var outStr:String | |
// bad IP-literal (there are no square brackets around the address) | |
inStr = "2606:2800:220:1:248:1893:25c8:1946" | |
outStr = inStr.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)! | |
// outStr = "2606%3A2800%3A220%3A1%3A248%3A1893%3A25c8%3A1946" | |
// valid IP-literal (there are square brackets around the address) | |
inStr = "[2606:2800:220:1:248:1893:25c8:1946]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#for not running docker, use save: | |
docker save <dockernameortag> | gzip > mycontainer.tgz | |
#for running or paused docker, use export: | |
docker export <dockernameortag> | gzip > mycontainer.tgz | |
#load | |
gunzip -c mycontainer.tgz | docker load |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User: Codable { | |
var name: String | |
var email: String | |
var id: String | |
var metadata: [String: MetadataType] | |
enum CodingKeys: String, CodingKey { | |
case name, email, id, metadata | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MinimalDecoder : Decoder { | |
var codingPath = [CodingKey?]() | |
var userInfo = [CodingUserInfoKey : Any]() | |
public func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> { | |
return KeyedDecodingContainer(MinimalKeyedDecodingContainer<Key>(decoder: self)) | |
} | |
public func unkeyedContainer() throws -> UnkeyedDecodingContainer { | |
return DecodingContainer(decoder: self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class MyService: NSObject, MyServiceProtocol { | |
func upperCaseString(_ string: String, withReply reply: @escaping (String) -> Void) { | |
let response = string.uppercased() | |
reply(response) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
//===----------------------------------------------------------------------===// | |
// CSV Decoder | |
//===----------------------------------------------------------------------===// | |
/// `CSVDecoder` facilitates the decoding of CSV into semantic `Decodable` types. | |
/// structでなくclassなのは、JSONDecoderやPlistDecoderの場合にはoptionを適宜切り替えつつdecodeしていけるようにだと思う | |
/// 実際の Decoder プロトコルへの適合は、fileprivateな _CSVRowDecoder 型を通して行う。 | |
open class CSVDecoder { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
from StringIO import StringIO | |
from django.http import StreamingHttpResponse | |
class StreamCSV(object): | |
def __init__(self): | |
self._buffer = StringIO() | |
self._writer = csv.writer(self._buffer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MKMapViewZoomLevel.swift | |
// | |
// Created by Johannes Rudolph on 10.05.17. | |
// Based on http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/ | |
// | |
import Foundation | |
import MapKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Control: | |
file:/// => file:/// | |
file:///etc/ => file:///etc/ | |
~/ -- file:/// => ~/ -- file:/// | |
~/Desktop -- file:/// => ~/Desktop -- file:/// | |
~/.bash_profile -- file:/// => ~/.bash_profile -- file:/// | |
./ -- file:/// => ./ -- file:/// | |
../ -- file:/// => ../ -- file:/// | |
file:///etc/../ => file:///etc/../ | |
~/../ -- file:/// => ~/../ -- file:/// |