Skip to content

Instantly share code, notes, and snippets.

@NeoTeo
NeoTeo / HHGTTG intro
Last active August 29, 2015 14:06
Douglas Adams' comments on Apple Pay and Apple Watch.
Far out in the uncharted backwaters of the unfashionable end
of the Western Spiral arm of the Galaxy lies a small
unregarded yellow sun.
Orbiting this at a distance of roughly ninety-two million
miles is an utterly insignificant little blue green planet whose
ape-descended life forms are so amazingly primitive that
they still think digital watches are a pretty neat idea.
This planet has – or rather had – a problem, which was
@NeoTeo
NeoTeo / project-Prefix.pch
Created January 8, 2015 15:39
Cocoa/Objective-C Macro for tagged debug logging.
// Here are the definitions of the tags used to toggle the various debug logs.
//#define TGLOG_ALL
#define TGLOG_TMP
#define TGLog(tag, msg, ...) TGLog_eval_(TGLog_do_, tag, msg, ## __VA_ARGS__)
#define TGLog_eval_(macro, ...) macro(__VA_ARGS__)
#define TGLog_do_(tag, msg, ...) \
(#tag[0] == 0 || #tag[0] == '1') ? NSLog(@"%@",[NSString stringWithFormat:msg, ## __VA_ARGS__]) : (void)0;
@NeoTeo
NeoTeo / crashBang
Last active August 29, 2015 14:13
Crashes compiler with "Global is external, but doesn't have external or weak linkage!"
import Cocoa
class foo {
var baz = false
func test() {
var bar: Int = 1 {
didSet {
if baz == true && bar == 2 {

Notes on "Making your own ipfs service"

Update (HT Cryptix): If we make sure we have the net/context package from github by running

go get golang.org/x/net/context

and then change the import statements in the server and client source from

import ( "code.google.com/p/go.net/context" )
MUTHR:tmp teo$ ./test.sh
Note: checking out 'c79dddd'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
@NeoTeo
NeoTeo / CodeExecutionTimer
Created May 18, 2015 12:00
Time code execution in Swift.
let methodStart = NSDate()
/* ... Do whatever you need to do ... */
let methodFinish = NSDate()
let executionTime = methodFinish.timeIntervalSinceDate(methodStart)
println("executionTime = \(executionTime)")
@NeoTeo
NeoTeo / WaitForAsync
Created May 18, 2015 12:05
Wait for async call using semaphores.
let sema = dispatch_semaphore_create(0)
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
// Do async stuff
// When finished, signal to continue below.
dispatch_semaphore_signal(sema)
}
// Wait for the load to complete.
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER)
@NeoTeo
NeoTeo / issue.swift
Created August 11, 2015 12:24
Protocol type constraint issue
import Cocoa
protocol ThingId { }
protocol Thing {
func getId<A: ThingId>() -> A
}
struct MyThingId: ThingId { }
@NeoTeo
NeoTeo / associated.swift
Created August 11, 2015 15:41
Using associated types in protocols
import Cocoa
protocol ThingId { }
protocol Thing {
typealias IdType
func getId() -> IdType
}
struct MyThingId: ThingId { }
@NeoTeo
NeoTeo / JsonType.swift
Created November 9, 2015 09:00
For type classifying JSON
/// Utilities for (eventually) dealing with
/// To be able to map a dictionary we extend it (from thoughtbot/Argo project)
// pure merge for Dictionaries
func + <T, U>(var lhs: [T: U], rhs: [T: U]) -> [T: U] {
for (key, val) in rhs {
lhs[key] = val /// Potential loss: Same key will lose existing lhs value.
}