Skip to content

Instantly share code, notes, and snippets.

Christian Tietze DivineDominion

Block or report user

Report or block DivineDominion

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View test-descriptions-for-fizz-buzz.js
// I have some testing framework in the scope
// Questions below:
// 1. Should the description be like it is here, in first `it`, or with `only` word added:
// "should return Fizz when the number is divisible only by 3"
// That would imply that the number is divisible by 3 only, which is technically not true, as it is divisible
// by 1 as well, and some numbers, e.g. 6, 9, and so on, are divisible by themselves.
it('should return Fizz when the number is divisible by 3', () => {
// 2. Is that name enough, having `any` in it, to be complete in what numbers are producing `fizz`.
// There is also a matter of adding `only` (similar to case #1) having `anyNumberDivisibleOnlyBy3`.
@IanKeen
IanKeen / Decodable+Random.swift
Last active Mar 8, 2019
Custom Decoder that can be used to create Decodable instances that are populated with random values
View Decodable+Random.swift
import Foundation
extension Decodable {
public static func randomInstance() throws -> Self {
let decoder = RandomDecoder()
return try Self(from: decoder)
}
}
private class RandomDecoder: Decoder {
@DivineDominion
DivineDominion / cocoaconv.rb
Last active Sep 28, 2018
Convert libMultiMarkdown enums to Swift-bridgeable NS_ENUMs. Pass the path to libMultiMarkdown.h to the script when running.
View cocoaconv.rb
#!/usr/bin/env ruby
require 'optparse'
CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
FALLBACK_PATH = File.join(CURRENT_PATH, "..", "build-xcode", "Debug", "include", "libMultiMarkdown", "libMultiMarkdown.h")
options = {:mode => :nsenum}
OptionParser.new do |parser|
parser.banner = "Usage: #{$0} [options] path/to/libMultiMarkdown.h"
@AliSoftware
AliSoftware / SwiftCopying.swift
Last active Aug 24, 2017
TypeSafe copy()/mutableCopy() (NSCopying/NSMutableCopying) in Swift
View SwiftCopying.swift
import Foundation
//: Swift type-safe protocol versions of (Mutable)Copying
protocol SwiftCopying {
associatedtype NonMutableType = Self
func clone() -> NonMutableType
}
extension SwiftCopying where Self: NSCopying {
func clone() -> NonMutableType {
return self.copy() as! NonMutableType
@sjoerdvisscher
sjoerdvisscher / minimal.swift
Created Jun 28, 2017
Using Decodable to generate a minimal value
View minimal.swift
struct MinimalDecoder : Decoder {
var codingPath = [CodingKey?]()
var userInfo = [CodingUserInfoKey : Any]()
public func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
return KeyedDecodingContainer(MinimalKeyedDecodingContainer<Key>(decoder: self))
}
public func unkeyedContainer() throws -> UnkeyedDecodingContainer {
return DecodingContainer(decoder: self)
@mminer
mminer / MyService.swift
Last active Aug 8, 2019
Components of XPC service.
View MyService.swift
import Foundation
class MyService: NSObject, MyServiceProtocol {
func upperCaseString(_ string: String, withReply reply: @escaping (String) -> Void) {
let response = string.uppercased()
reply(response)
}
}
@darrensapalo
darrensapalo / rxswift3networkcalltoobject
Last active Jul 8, 2019
Swift 3 example of a network request wrapped as an RxSwift Observable and converted into a class object
View rxswift3networkcalltoobject
import Foundation
import RxSwift
let networkQueue = DispatchQueue(label: "com.appName.networkQueue")
class Queue {
var name: String
public init (_ name: String) {
self.name = name
View EmbedFrameworksScript.sh
#!/bin/sh
set -e
# set your Frameworks path here
FRAMEWORKS_DIR="${SRCROOT}/../Frameworks/${PLATFORM_NAME}"
echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
@khanlou
khanlou / Quicksort.swift
Created Dec 9, 2016
Quicksort - the only use for partition(by:) I could find
View Quicksort.swift
import Foundation
extension Array where Element: Comparable {
mutating func quickSort() {
self[self.indices].quickSort()
}
}
extension ArraySlice where Element: Comparable {
mutating func quickSort() {
View print_progress.py
# -*- coding: utf-8 -*-
# Print iterations progress
def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100):
"""
Call in a loop to create terminal progress bar
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
You can’t perform that action at this time.