Skip to content

Instantly share code, notes, and snippets.

View dnedrow's full-sized avatar

David Nedrow dnedrow

View GitHub Profile
@dnedrow
dnedrow / delete_git_submodule.md
Created April 4, 2022 18:40 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@dnedrow
dnedrow / build.gradle
Created August 17, 2019 22:18 — forked from ari/build.gradle
Docbook gradle build
/*
Copyright 2015 Aristedes Maniatis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@dnedrow
dnedrow / git.migrate
Created February 26, 2019 17:10 — forked from niksumeiko/git.migrate
Moving git repository and all its branches, tags to a new remote repository keeping commits history
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
@dnedrow
dnedrow / RandomNumbers.swift
Created October 2, 2018 21:17 — forked from jstn/RandomNumbers.swift
generate random numbers for 64-bit types while mitigating modulo bias
/*
`arc4random_uniform` is very useful but limited to `UInt32`.
This defines a generic version of `arc4random` for any type
expressible by an integer literal, and extends some numeric
types with a `random` method that mitigates for modulo bias
in the same manner as `arc4random`.
`lower` is inclusive and `upper` is exclusive, thus:
//
// UIViewAdditions.swift
//
// Created by Daniel Tartaglia on 04/15/15.
// Copyright © 2016. MIT License.
//
import UIKit

Two Level Type Erasing in Swift 3

Recently I converted a project of mine to Swift 3 (https://github.com/dtartaglia/XStreamSwift) and I had to deal with a problem that I couldn't find an answer for. This article is about the problem and the solution I discovered.

There are lots of articles on the web about type erasing in Swift, but all the ones I found only dealt with a single level. I will recap the concept quickly:

protocol Listener
{

associatedtype ListenerValue

//
// UIImage+Extensions.swift
//
// Created by Daniel Tartaglia on 4/25/16.
// Copyright © Daniel Tartaglia. MIT License.
//
import UIKit
@dnedrow
dnedrow / Signal.swift
Created September 22, 2018 12:35 — forked from danielt1263/Signal.swift
Swift replacement for KVO
//
// Signal.swift
//
// Created by Daniel Tartaglia on 9/6/15.
// Copyright © 2016 Daniel Tartaglia. MIT License.
//
public protocol Disposable {
func dispose()
}
@dnedrow
dnedrow / doOnce.swift
Created May 15, 2018 14:48 — forked from samsonjs/doOnce.swift
A function that only executes once. Good Swift or over-clever?
// Swift3 gets rid of dispatch_once and recommends replacing it with a lazy global.
// That's very straightforward when dispach_once is used to initialize something, but
// isn't an exact match when you want something to execute once, and then become a noop
// in a thread-safe way.
// The following approach seems completely "correct" and I guess actually a bit elegant,
// if by "elegant" you mean "terse and not immediately obvious to the reader, which makes
// you look very clever."
var doOnce: () -> Void = {
@dnedrow
dnedrow / doOnce.swift
Created May 15, 2018 14:46 — forked from rnapier/doOnce.swift
A function that only executes once. Good Swift or over-clever?
// Swift3 gets rid of dispatch_once and recommends replacing it with a lazy global.
// That's very straightforward when dispach_once is used to initialize something, but
// isn't an exact match when you want something to execute once, and then become a noop
// in a thread-safe way.
// The following approach seems completely "correct" and I guess actually a bit elegant,
// if by "elegant" you mean "terse and not immediately obvious to the reader, which makes
// you look very clever."
var doOnce: () -> Void = {