Skip to content

Instantly share code, notes, and snippets.

import Foundation
import XCTest
class Ref {
var success = false
}
import UIKit
let attr = NSAttributedString(string: "Hello, playground", attributes: [NSBackgroundColorAttributeName:UIColor.redColor()])
var shouldBeOne = 1
attr.enumerateAttribute(NSBackgroundColorAttributeName, inRange: NSMakeRange(0, attr.length), options:[]) { (value, range, stop) -> Void in
shouldBeOne += 1
}
print(shouldBeOne) //<- prints "1"
import UIKit
class AsyncOperation : NSOperation{
enum State{
case Waiting, Executing, Finished
}
@jemmons
jemmons / StateMachine.swift
Last active March 13, 2023 14:59
A Simple Swift State Machine
import Foundation
class StateMachine<P:StateMachineDelegateProtocol>{
private unowned let delegate:P
private var _state:P.StateType{
didSet{
delegate.didTransitionFrom(oldValue, to:_state)
}
}
@jemmons
jemmons / top_level.swift
Created November 22, 2014 21:31
`returning` for Swift
func returning<T>(object:T, block:(_:T)->Void)->T{
block(object)
return object
}
@jemmons
jemmons / understanding light table.cljs
Last active August 29, 2015 14:01
Getting Started Programming Light Table
(ns reverb.lighttable
(:require lt.object)
(:require-macros lt.macros))
(lt.object/object* ::my-template-name :tags [:my-tag-name] :some-nebulous-state [], :other-state-like-thing {})
(lt.object/->def ::my-template-name)
(lt.object/create ::my-template-name)
(lt.object/instances-by-type ::my-template-name)
def self.with_memory_db
old_db_config = ActiveRecord::Base.connection_config
ActiveRecord::Base.establish_connection :adapter=>"sqlite3", :database=>":memory:"
yield(ActiveRecord::Base.connection) if block_given?
ensure
ActiveRecord::Base.establish_connection old_db_config
end
@jemmons
jemmons / config.ru
Created March 20, 2013 17:36
Rackup without tabs
require 'bundler/setup'
Bundler.require(:default)
module Fred; module Barny; module Wilma; def self.betty; "hello, bedrock!" end end end end
app = proc do |env| [200, { 'Content-Type' => 'text/html' }, Fred::Barny::Wilma.betty()]; end
run app
@jemmons
jemmons / test.rb
Created March 20, 2013 17:03
Tabs shouldn't matter
module Foo
module Bar
class Baz
def self.quux
puts "hello, world" end end end end
Foo::Bar::Baz.quux()
module Fred
-(IBAction)show:(id)sender{
CGRect frame = [aView frame];
frame.origin.y = [[self view] bounds].size.height;
[aView setFrame:frame];
[[self view] addSubview:aView];
[UIView beginAnimations:@"slide up" context:NULL];
frame.origin.y = [[self view] bounds].size.height - frame.size.height;
[aView setFrame:frame];
[UIView commitAnimations];