Skip to content

Instantly share code, notes, and snippets.

View CTMacUser's full-sized avatar

Daryle Walker CTMacUser

View GitHub Profile
@mcroydon
mcroydon / nntpd.js
Created February 2, 2011 05:45
A minimal NNTP implementation in node.js
var net = require('net');
var END = '\r\n';
var groups = ['nodejs.test'];
var articles = {
'<1@127.0.0.1>' : {body : 'An article.'},
'<2@127.0.0.1>' : {body : 'Another article.'},
};
@ole
ole / update_storyboard_strings.sh
Last active April 4, 2022 06:11
Automatically extract translatable strings from Xcode storyboards and update .strings files. Original version by MacRumors forum user mikezang (http://forums.macrumors.com/showpost.php?p=16060008&postcount=4). Slightly updated by Ole Begemann. NOTE: this Gist moved to a regular repo at https://github.com/ole/Storyboard-Strings-Extraction.
# (File moved to https://github.com/ole/Storyboard-Strings-Extraction)
protocol ContextError : ErrorType {
mutating func addContext<T>(type: T.Type)
}
protocol Contextualizable {}
extension Contextualizable {
func addContext(var error: ContextError) -> ContextError {
error.addContext(self.dynamicType)
return error
}
@hectr
hectr / MRManagedObjectContext.h
Created August 20, 2015 00:33
Core Data stack with read-only main context
// Copyright (c) 2013, Héctor Marqués
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
@reckenrode
reckenrode / json.swift
Created June 23, 2017 14:25
Decoding arbitrary JSON with the new Decoder in Swift 4
enum JSON: Decodable {
case bool(Bool)
case double(Double)
case string(String)
indirect case array([JSON])
indirect case dictionary([String: JSON])
init(from decoder: Decoder) throws {
if let container = try? decoder.container(keyedBy: JSONCodingKeys.self) {
self = JSON(from: container)
@jjrscott
jjrscott / BidirectionalCollection+RegularExpressions.swift
Created July 15, 2020 21:01
Reimplementation of Brian Kernighan's Regular Expression Matcher on BidirectionalCollection
//
// RegularExpression.swift
// RegularExpressions
//
// Created by John Scott on 15/07/2020.
//
// Original matching implementation Brian Kernighan : https://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html
// Swift port Ben Cohen : https://github.com/apple/swift/blob/a9eee38e109e3d99f103a9bee71bed4422fbb6fd/benchmark/single-source/StringMatch.swift
import Foundation
@d-ronnqvist
d-ronnqvist / Thoughts on removedOnCompletion in SparkRecordingCircle.md
Last active May 16, 2020 02:51
What I think is wrong with the Spark Recording Circle code and why

There was [a tweet][tweetSoto] a couple of days ago that resulted in a discussion/question about what it wrong with the usage of removedOnCompletion = NO in the [SparkRecordingCircle code][code] for that [Subjective-C post][post].

We all kept saying that the explanation doesn't fit in a tweet, so here is my rough explanation about the issues.

But, let me first say that I think that the Subjective-C articles are reallt cool and useful to learn from. This is trying to reason about the general usage of removedOnCompletion = NO, using that code as an example, since that was what was discussed on twitter.


The root problem, as [Nacho Soto pointed out][rootProblem], is that removedOnCompletion = NO in combination with fillMode = kCAFillModeForwards is almost always used when you are not updating the model layer. This means that after the animation has finished, what you see on screen is not reflected in the property of the layer. The biggest issue that this can cause is that all the

@rxwei
rxwei / upstreaming-swift-autodiff.md
Last active January 28, 2020 11:06
Upstreaming Swift AutoDiff

Upstreaming Swift AutoDiff

Author: Richard Wei (rxwei@google.com) on behalf of the Swift for TensorFlow team

Last updated: October 2, 2019

Overview

The differentiable programming feature (AutoDiff) has been incubated in the 'tensorflow' branch of apple/swift since December 2017 and released as part of the Swift for TensorFlow toolchains. The Differentiable Programming Mega-Proposal, which serves as a manifesto, received general positive feedback from the community, but there is a long way between receiving conceptual approval and obtaining Swift Evolution approval of such a large feature. We would like to merge the pieces into the 'master' branch under a gate to further development and bake the feature on master, just like Apple develops its major features

@pyrtsa
pyrtsa / gist:2275320
Created April 1, 2012 13:27
C++11 metaprogramming
// Here are a few tricks I've used with the trunk versions of clang and libc++
// with C++11 compilation turned on. Some might be obvious, some not, but at
// least they are some kind of improvement over their C++03 counterparts.
//
// Public domain.
// =============================================================================
// 1) Using variadic class templates recursively, like in the definitions for
// "add<T...>" here:
// @discardableResult to be added
// @noescape needs to move to type annotation
// needs to add _ for item
public func with<T>(item: T, @noescape update: (inout T) throws -> Void) rethrows -> T {
var this = item; try update(&this); return this
}