Skip to content

Instantly share code, notes, and snippets.

View rhysforyou's full-sized avatar

Rhys Powell rhysforyou

View GitHub Profile
import XCTest
@testable import GameBro
class CPUTests : XCTestCase {
func testLD() {
var cpu = CPU(memory: Memory())
cpu.LD(&cpu.A, UInt8(20)) // LD A, 20
cpu.LD(&cpu.B, cpu.A) // LD B, A
import XCTest
@testable import GameBro
class CPUTests : XCTestCase {
func testLD() {
var cpu = CPU(memory: Memory())
cpu.LD(&cpu.A, UInt8(20)) // LD A, 20
cpu.LD(&cpu.B, cpu.A) // LD B, A
//
// Localization.swift
// Pokedex
//
// Created by Rhys Powell on 3/03/2016.
// Copyright © 2016 Rhys Powell. All rights reserved.
//
import Foundation
import RealmSwift

My Beefs With Realm

I've been working on an app recently using Realm's Swift SDK as my data store, and while it's leagues ahead of Core Data, I've run into some issues with it.

So in this app I've got a fairly large data set that's been localised into a bunch of different languages. To handle that, we replace any property on an object that needs to be localised with a list of objects that conform to a Localizable protocol. So let's say we have a Person object that looks like so:

class Person : Object {
  dynamic var name = ""
  dynamic var greeting = ""
(source_file
(import_decl 'Foundation')
(import_decl 'Alamofire')
(import_decl 'ReactiveCocoa')
(struct_decl "Nirvash" type='Nirvash.Type' access=public
(enum_decl "Method" type='Nirvash.Method.Type' access=public
(enum_case_decl
(enum_element_decl "GET" type='Nirvash.Method.Type -> Nirvash.Method' access=public)
(enum_element_decl "POST" type='Nirvash.Method.Type -> Nirvash.Method' access=public)
(enum_element_decl "PUT" type='Nirvash.Method.Type -> Nirvash.Method' access=public)
//: Playground - noun: a place where people can play
import Foundation
enum EditOperation<Element> {
case Insert(position: Int, value: Element)
case Delete(position: Int, value: Element)
case Replace(position: Int, value: Element)
case Move(fromPosition: Int, toPosition: Int, value: Element)
}
@rhysforyou
rhysforyou / partial_application.swift
Last active January 19, 2016 02:56
Partial application in Swift
//: Playground - noun: a place where people can play
import Foundation
func apply<A, B>(fn: (A) -> B, _ a: A) -> B {
return fn(a)
}
func apply<A, B, C>(fn: (A, B) -> C, _ a: A) -> B -> C {
#import <Foundation/Foundation.h>
@interface NSArray (FunctionalPrimitives)
- (NSArray *)flatten;
- (NSArray *)reverse;
- (NSArray *)map:(id (^)(id))transform;
- (NSArray *)filter:(BOOL (^)(id))predicateBlock;
- (NSArray *)foldRightWithStart:(id)start reduce:(id (^)(id item, id result))reduce;
- (NSArray *)foldRightWithStart:(id)start reduce:(id (^)(id item, id result))reduce;
@rhysforyou
rhysforyou / unfuckgestures.fish
Created January 4, 2016 01:58
fixes broken trackpad gestures
function unfuckgestures
pmset displaysleepnow
sleep 5
caffeinate -u -t 1
end
defmodule mylist do
def reverse([]), do: []
def reverse([ head | tail ]), do: reverse(tail) ++ [head]
end