Skip to content

Instantly share code, notes, and snippets.

@dimroc
dimroc / Prediction.playground.linkerError.txt
Last active August 12, 2018 21:36
Crowd Count Prediction.playground spurious linker errors: https://github.com/dimroc/count/tree/master/ios
error: Couldn't lookup symbols:
type metadata for CrowdCountApiMac.FriendlyClassification
CrowdCountApiMac.MultiArray.copy() -> CrowdCountApiMac.MultiArray<A>
CrowdCountApiMac.MultiArray.image(offset: A, scale: A) -> Swift.Optional<__C.NSImage>
CrowdCountApiMac.FriendlyPredictor.predictAllPromise(image: __C.NSImage, on: __C.OS_dispatch_queue) -> Promises.Promise<Swift.Array<CrowdCountApiMac.FriendlyPrediction>>
protocol witness table for Swift.Double : CrowdCountApiMac.MultiArrayType in CrowdCountApiMac
__swift_FORCE_LOAD_$_swiftCoreMedia
__swift_FORCE_LOAD_$_swiftCoreAudio
CrowdCountApiMac.FriendlyPredictor.DensityMapWidth.unsafeMutableAddressor : Swift.Int
type metadata accessor for CrowdCountApiMac.FriendlyPredictor
@dimroc
dimroc / Realm.Configuration+migrations.swift
Created August 3, 2018 15:32
Lightweight management of Realm migrations
//
// RealmConfiguration+extensions.swift
// CrowdCount
//
// Created by Dimitri Roche on 8/3/18.
// inspired by https://medium.com/@shenghuawu/realm-lightweight-migration-4559b9920487
// Copyright © 2018 Dimitri Roche. All rights reserved.
//
import Foundation
@dimroc
dimroc / faster.log
Last active July 24, 2019 14:02
Huge speed discrepancy between the two methods while running CoreML. Why?
image from sample buffer took: 1.54ms
image from sample buffer took: 0.87ms
image from sample buffer took: 1.86ms
image from sample buffer took: 2.25ms
classify took: 152.14ms
image from sample buffer took: 1.12ms
@dimroc
dimroc / ClassificationViewModel.swift
Last active July 21, 2018 14:51
Confident concurrency in swift: reactive, MVVM, lean
//
// ClassificationViewModel.swift
// CrowdCount
//
// Created by Dimitri Roche on 7/21/18.
// Copyright © 2018 Dimitri Roche. All rights reserved.
//
import Foundation
import RxSwift
import UIKit
import AVFoundation
protocol FrameExtractorDelegate: class {
func captured(image: UIImage)
}
class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
private let position = AVCaptureDevice.Position.front
package main
import (
"github.com/gin-gonic/contrib/sessions"
"github.com/gin-gonic/gin"
"log"
"net/http"
"strings"
)
@dimroc
dimroc / 00-dragndrop.swift
Created July 4, 2018 18:27 — forked from erica/00-dragndrop.swift
Building an OSX Drag and Drop Playground: Throw the dragndrop.swift into shared Sources and then test out the examples in individual playgrounds. Make sure the assistant is open and set to the timeline. I prefer vertical assistant stacking for this.
import Cocoa
// Support Foundation calls on String
public extension String { public var ns: NSString {return self as NSString} }
/// Custom Labeled Playground-Based Drag-and-Drop window
public class DropView: NSTextField {
// Default action handler
public var handler: ([String]) -> Void = { paths in Swift.print(paths) }
@dimroc
dimroc / kuberake
Last active October 3, 2017 02:49
Kubernetes rake <arbitrary tasks> job runner
#!/bin/bash
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
template=`cat ./jobs/rake.yaml`
joined=$(join_by \",\" $@)
args=[\"$joined\"]
job="${template//"\$\$RAKECMD"/$args}"
echo "$job" | kubectl create -f -
kubectl get pods -a

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@dimroc
dimroc / git-mv-with-history
Created July 14, 2017 21:15 — forked from emiller/git-mv-with-history
git utility to move/rename file or folder and retain history with it.
#!/bin/bash
#
# git-mv-with-history -- move/rename file or folder, with history.
#
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
#
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.