Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Our base Coffee class, which has a cost, array of ingredients,
* and getters/setters. Note that this class is not extended or
* implemented, and decorators don't modify Coffee objects.
*/
class Coffee {
private $cost;
private $ingredients = array();
@thelowlypeon
thelowlypeon / EWG Handling Proposal.md
Created November 6, 2014 17:31
Proposal for EWG API/App Exceptions, validation, and error handling

Here's what I propose for our API validation, which comes almost entirely from Dingo.

For a store route (eg ListingsLocationsController::store()), we'd throw a StoreResourceFailedException:

# app/controllers/ListingsLocationsController.php
public function store($listingId) {
  $input = Input::all();
  $input['listing_id'] = $listingId;
  $location = new Location($input);
@thelowlypeon
thelowlypeon / sampledata
Created January 26, 2015 23:45
Data being posted to showingInviteTickets/in
[eventKey: -Jgc8G_FBf8tcNKYfgnX, clients: {
"-JdsuQwohqfQtISBiRSq" = {
email = "[email protected]";
first = Bob;
last = Labla;
};
"-JeziQkmysDpD0uSBtLQ" = {
email = asdadsasdadsads;
first = asads;
last = asdads;
@thelowlypeon
thelowlypeon / init.d unicorn_server service
Last active March 26, 2017 00:38
Scripts to starting, stopping, restarting, or rotating a unicorn server
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn app server
# Description: starts unicorn using start-stop-daemon
import Foundation
import UIKit
public class ObservableProperty<T> {
public var value: T {
didSet { notifyObservers() }
}
private var observers = [(T) -> Void]()
public init(_ initialValue: T) {
import Foundation
import UIKit
public class Person: NSObject {
@objc public dynamic var firstName: String
@objc public dynamic var middleInitial: String?
@objc public dynamic var lastName: String
public init(firstName: String, middleInitial: String?, lastName: String) {
self.firstName = firstName
import Foundation
import UIKit
public class Event<T> {
public typealias EventHandler = (T) -> Void
private var eventHandlers = [EventHandler]()
public func addHandler(handler: @escaping EventHandler, withInitialEvent initialEvent: T? = nil) {
eventHandlers.append(handler)
if let event = initialEvent {