Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
struct ListAnimationsView: View {
struct Item: Identifiable {
var name: String
var id: String { name }
static var currentID = 0
static func new() -> Item {
currentID += 1
import Foundation
import PlaygroundSupport
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
@crayment
crayment / Observable.swift
Last active August 25, 2017 16:29
Observable
import Foundation
/**
Observable wraps an internal value providing a simple API for consumers to be notified of changes to the value.
You add an observation by specifying an `observer` which should be thought of as a lifetime object. When the `observer`
is deallocated the observation is removed and the closure will not be called again. It is possible to unsubscribe
earlier by passing the `observer` to `removeObserver(_:)`. Note though that this removes all observations added using
this `observer`.
import ObjectiveC
import UIKit
// MARK: - AutoScrollView
/**
A scroll view that automatically scrolls to first responders when the keyboard is shown.
Supports the `focusView` and `focusPadding` properties of the first responder if it conforms to `KeyboardAdjustingResponder`
Vertical scrolling support only.
*/
struct MasterResponse<T: JSONDecodable> {
let object: T?
let error: [String: JSON]?
}
extension MasterResponse: JSONDecodable {
init(json: JSON) throws {
guard case let .Dictionary(jsonDictionary) = json else {
let error = JSON.Error.ValueNotConvertible(value: json, to: MasterResponse.self)
throw error
/// Custom type for the error case which includes a value. Here I end up using JSON but you could easily decode to a model on error.
struct MyNetworkError<T> {
let response: Response<NSData, NSError>?
let error: ErrorType
let value: T?
var statusCode: HTTPStatusCode? {
guard let response = response?.response else { return nil }
return HTTPStatusCode(intValue: response.statusCode)
}

Keybase proof

I hereby claim:

  • I am crayment on github.
  • I am crayment (https://keybase.io/crayment) on keybase.
  • I have a public key whose fingerprint is AFD0 1E3D 1219 DD40 055E FF54 6D0A 8F14 ED43 F4BC

To claim this, I am signing this object:

SocketIOClient *socket = [SocketIOClient socketIOClientWithHost:@"www.marcelball.ca" port:8000 delegate:self];
NSDictionary *message = [NSDictionary
dictionaryWithObjects:
[NSArray arrayWithObjects:
@"handshake",
@"student@test.com",
@"a",
@"false", nil]
forKeys:[NSArray arrayWithObjects:
@"action",
NSDictionary *dictionary;
NSArray *words = [dictionary allKeys];
NSMutableString *javascript = @"addText(";
for (int i=0; i<[words count]; i++) {
[javascript appendString:@"%@", [words objectAtIndex:i]];
if(i<([words count]-1)) {
[javascript appendString:@", "];
}
}
class CheckoutsController < ApplicationController
def index
@categories = Category.all
end
end