Skip to content

Instantly share code, notes, and snippets.

public Observable<Rates> getRates() {
String accessToken = getAuthenticationTokens().getAccessToken();
return networking.getRates(accessToken)
.flatMap(new Func1<Response<Rates>, Observable<Rates>>() {
@Override
public Observable<Rates> call(Response<Rates> response) {
if (response.isSuccess()) {
Rates rates = response.body();
return Observable.just(rates);
}
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/backgroundImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/backgroundImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/backgroundImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
let todoResources = Resource(middleware: recovery, contentNegotiaton) { todo in
todo.index { _ in
let todos = try app.getAllTodos()
return Response(content: ["todos": todos.content])
}
todo.create(mappingTo: Todo.self) { request, todo in
let todo = try app.createTodo(todo)
return Response(content: todo)
}

S4 - Server Side Swift Standards

Byte

The Byte type represents a byte.

public typealias Byte = UInt8
import Dispatch
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
func delay(duration: Double, closure: Void -> Void) {
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(duration * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue(), closure)
}
@paulofaria
paulofaria / Package.swift
Last active March 18, 2016 22:52
Alias for packages
import PackageDescription
let package = Package(
name: "S4",
dependencies: [
.Package(url: "https://github.com/swiftx/http.git", majorVersion: 0, minor: 1, alias: "SwiftXHTTP"),
.Package(url: "https://github.com/Zewo/HTTP.git", majorVersion: 0, minor: 1, alias: "ZewoHTTP")
]
)
public typealias Byte = UInt8
public struct Data {
public var bytes: [Byte]
public init(_ bytes: [Byte]) {
self.bytes = bytes
}
}
do {
let ip = try IP(localAddress: "127.0.0.1", port: 8080)
let serverSocket = try TCPServerSocket(ip: ip)
serverSocket.accept { getClientStream in
do {
let clientStream = try getClientStream()
clientStream.receive(length: Int.max) { getData in
do {
let data = try getData()