Skip to content

Instantly share code, notes, and snippets.

View jarsen's full-sized avatar

Jason Larsen jarsen

View GitHub Profile
// .-'
// '--./ / _.---.
// '-, (__..-` \
// \ . |
// `,.__. ,__.--/
// '._/_.'___.-`
import Foundation
import CoreData
// .-'
// '--./ / _.---.
// '-, (__..-` \
// \ . |
// `,.__. ,__.--/
// '._/_.'___.-`
import Foundation
import ReactiveCocoa
import Orcinus
//: Playground - noun: a place where people can play
import UIKit
enum JSONError : ErrorType {
case NoValueForKey(String)
case TypeMismatch
}
public class JSONObject {
//: Playground - noun: a place where people can play
import UIKit
enum JSONError : ErrorType {
case NoValueForKey(String)
case TypeMismatch
}
public class JSONObject {
//: Playground - noun: a place where people can play
import UIKit
struct Address {
var street: String
}
struct Person {
var name: String
@jarsen
jarsen / dict_update.swift
Created May 31, 2015 14:49
Dictionary Update
extension Dictionary {
mutating func update(key: Key, initial: Value, update:Value->Value) {
if let x = self[key] {
self[key] = update(x)
}
else {
self[key] = initial
}
}
}
@jarsen
jarsen / ticker_node.ex
Last active August 29, 2015 14:20
run TickerNode.start in multiple linked nodes and they link together and count!
import :timer, only: [sleep: 1]
defmodule TickerNode do
@interval 2000 # 2 seconds
@name :ticker
def start do
pid = spawn(__MODULE__, :run, [nil, nil])
if :global.whereis_name(@name) == :undefined do
IO.puts "Spawning as root node"
public protocol Section {
typealias U
var count: Int { get }
func itemAtRow(row: Int) -> U
subscript(index: Int) -> U { get }
}
public struct ArraySection<T>: Section {
typealias U = T
@jarsen
jarsen / tests.swift
Created April 14, 2015 20:49
cool swift unit test expectation syntax
func expect<T: Equatable>(value: T, file: String = __FILE__, line: Int = __LINE__) -> (T, String, Int) {
return (value, file, line)
}
func ==<T: Equatable>(lhs: (T, String, Int), rhs: T) {
if lhs.0 != rhs {
XCTFail("Expected \(rhs), but got \(lhs.0) instead", file: lhs.1, line: UInt(lhs.2))
}
}
@jarsen
jarsen / playing.jl
Created March 20, 2015 20:23
just playing with julia data
Pkg.add("Gadfly")
using Gadfly
# Random cool meta stuff
print(code_typed(print, ()))
:(2 + 2) # quote expressions to see AST
print(code_lowered(print, ())) # see the lowered AST
# returns an array because some functions return multiple values
Pkg.add("Cairo")