Skip to content

Instantly share code, notes, and snippets.

@pcantrell
pcantrell / Gemfile
Created November 29, 2011 17:42
Get app profiling straight from the browser. Usage: (1) http://localhost:3000/rubyprof/start (2) Exercise slow requests (3) http://localhost:3000/rubyprof/stop (be patient) to get a report.
gem 'ruby-prof'
@pcantrell
pcantrell / ruby-closures.rb
Created January 8, 2012 21:07
Closures in Ruby
# CLOSURES IN RUBY Paul Cantrell http://innig.net
# Email: username "cantrell", domain name "pobox.com"
# I recommend executing this file, then reading it alongside its output.
#
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments,
# then trying to guess the output of the code!
# A closure is a block of code which meets three criteria:
@pcantrell
pcantrell / gist:4113853
Created November 19, 2012 21:01
Property observers in Javascript
// Model with property observers:
Model = function() {}
Model.prototype.observe = function(prop, observer) {
this._observers = this._observers || {}
if(!this._observers[prop]) {
this._observers[prop] = []
class Recording < ActiveRecord::Base
has_many :artistic_contributions, dependent: :destroy, include: [:artistic_role, :artist]
has_many :artists, through: :artistic_contributions
has_many :editions, class_name: 'RecordingEdition', dependent: :destroy
has_many :blog_posts, foreign_key: :podcast_recording_id
validates :title, :base_file_name, presence: true
before_save :refresh_editions

Study these screenshots:

https://innig.net/tmp/nr-screenshots/

Fork this gist (one fork per team).

Sketch out an object model for this application. Don't worry about view, network, database, etc.; your concern is only to represent the essential information of this application as classes and attributes. You can use the following attribute types:

  • numbers, strings, dates
  • other model classes
//
// KittenTest.swift
// KittenTest
//
// Created by Paul on 2015/9/13.
// Copyright © 2015 Kodama Software. All rights reserved.
//
import Foundation
@pcantrell
pcantrell / Siesta+SwiftyJSON.swift
Created November 6, 2015 19:00
Siesta SwiftyJSON integration
extension TypedContentAccessors {
/**
Adds a `.json` convenience property to resources that returns a SwiftyJSON `JSON` wrapper.
If there is no data, then the property returns `JSON([:])`.
Note that by default, Siesta parses data based on content type. This accessor is only a way
of conveniently donwcasting and defaulting the data that Siesta has already parsed. (Parsing
happens off the main thread in a GCD queue, never in response one of these content accessors.)
To produce a custom data type that Siesta doesn’t already know how to parse as a Siesta
resource’s content, you’ll need to add a custom `ResponseTransformer`.
protocol Tensor {
static var numberOfDims: Int { get }
}
struct NestedTensor<Element: Tensor>: Tensor {
static var numberOfDims: Int {
return 1 + Element.numberOfDims
}
// ...etc...
@media (-webkit-min-device-pixel-ratio: 2) {
img {
image-rendering: -webkit-optimize-contrast;
image-rendering: optimize-contrast;
}
}

Proposed changes to Siesta’s API before it hits the 1.0 freeze. Please post your feedback on this document to the accompanying Github issue.

Argument names

“Prefer to follow the language’s defaults for the presence of argument labels”

  • These changes seem good:

    • Entity.init(_:_:) → init(response:content:)
  • Error.init(_:_:_:userMessage:) → init(response:content:cause:userMessage:)