Skip to content

Instantly share code, notes, and snippets.

@NeoTeo
NeoTeo / gist:138bccbddb02b9cc2f12583ab9b9cf32
Created February 12, 2017 12:33
contents of .ipfs/blocks/CIQAG/
total 65808
drwxr-xr-x 150 teo staff 5100 Feb 12 13:29 .
drwxr-xr-x 514 teo staff 17476 Feb 12 13:29 ..
-rw------- 1 teo staff 262158 Jun 14 2016 CIQAG2GJV22PEMFGP3333POWTK7JC7GWQFZCSC35SOYR3TWUJJY464A.data
-rw------- 1 teo staff 87 Apr 27 2016 CIQAG2JGKTPVE2L6ZQHRXBDQ3QEUBTD2CDUVYYYGLN5MVM2KOEX7DKQ.data
-rw------- 1 teo staff 262158 Jun 14 2016 CIQAG2OWJJ56CFHQNRJOOLDMND3QBZQFXSZBUGPCHXERPE2YSQL6YWY.data
-rw------- 1 teo staff 262158 Jun 14 2016 CIQAG2Q3BKI27HSE7FSBJID3GMPZG7E6BHDM3TM65V4XKXTQQXDSJKY.data
-rw------- 1 teo staff 262158 Jun 14 2016 CIQAG2R2GPLKTCBFZYEXU2O7ND4E4JABBSEHZLOFK74RNWWXXW4GZUY.data
-rw------- 1 teo staff 262158 Oct 26 2015 CIQAG2S227HDNN55AWTMXQJAOUMRTMW2Y5K3IARNP5ZQMZ6FOOECQYY.data
-rw------- 1 teo staff 262158 Jun 14 2016 CIQAG2WSPPG7EEFGEKPGUIAFU6X2JWAUP2U6YUZMX3GNQ57U3RF73KA.data
@NeoTeo
NeoTeo / gist:88202380f727674d547dc7287c14adea
Created February 12, 2017 12:10
IPFS datastore migration 4 -> 5 error log
teo@muthr-2 ~/D/go-ipfs> ipfs daemon
Initializing daemon...
Adjusting current ulimit to 1024...
Successfully raised file descriptor limit to 1024.
Found outdated fs-repo, migrations need to be run.
Run migrations now? [y/N] y
=> Looking for suitable fs-repo-migrations binary.
=> None found, downloading.
=> Running: /var/folders/qx/gcnhmzf529gdkndv2wbz57n00000gn/T/go-ipfs-migrate108616551/fs-repo-migrations -to 5 -y
Found fs-repo version 4 at /Users/teo/.ipfs
@NeoTeo
NeoTeo / gist:8735057e63b08a869e39
Last active February 10, 2016 16:28
Swift variable assignment and check for nil in one operator to match the constant assignment expression.
//: Gist by Mike Ash to show how to achieve what Swift has chosen not to.
//: So Swift allows us to assign to a constant from a function that returns an optional and
//: check that it did indeed return a value by using either
//: if let x = funcReturningOptional() { ... }
//: or
//: guard let x = funcReturningOptional() else { ... }
//: But Swift does not provide the ability to do the same for variables, so instead of doing
//: if x = funcReturningOptional() { ... }
@NeoTeo
NeoTeo / .tmux.conf
Created January 3, 2016 19:29
My config file for tmux
set -g prefix C-a # Set ctrl-a to be the new prefix
unbind C-b # Unbind the default prefix
set -sg escape-time 1 # Remove command delay
# r to reload config
bind r source-file ~/.tmux.conf \; display "Configuration reloaded."
bind C-a send-prefix # Send prefix through on second use.
bind | split-window -h # Vertical split on |
bind - split-window -v # Horiz split on -
# Bind pane selection keys to vim movement keys.
@NeoTeo
NeoTeo / UDPSendReceive.swift
Last active November 7, 2021 13:32
A minimal implementation of a Posix UDP server and client in Swift.
/// This playground shows how to send and receive packets with low-level Posix UPD protocol API.
import Foundation /// Used for NSUTF8StringEncoding
import XCPlayground
/// Ensure the playground doesn't stop executing at the end of the main thread.
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
/** Workaround for Swift not having access to the htons, htonl, and other C macros.
This is equivalent to casting the value to the desired bitsize and then
@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.
}
@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 / 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 / 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 / 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)")