Skip to content

Instantly share code, notes, and snippets.

View artemkrachulov's full-sized avatar

Artem Krachulov artemkrachulov

View GitHub Profile
import Foundation
// Very slightly adapted from http://stackoverflow.com/a/30141700/106244
// 99.99% Credit to Martin R!
// Mapping from XML/HTML character entity reference to character
// From http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
private let characterEntities : [String: Character] = [
// XML predefined entities:
extension ObservableType {
func flatMap<A: AnyObject, O: ObservableType>(weak obj: A, selector: @escaping (A, Self.E) throws -> O) -> Observable<O.E> {
return flatMap { [weak obj] value -> Observable<O.E> in
try obj.map { try selector($0, value).asObservable() } ?? .empty()
}
}
func flatMapFirst<A: AnyObject, O: ObservableType>(weak obj: A, selector: @escaping (A, Self.E) throws -> O) -> Observable<O.E> {
return flatMapFirst { [weak obj] value -> Observable<O.E> in
@artemkrachulov
artemkrachulov / ContentView.swift
Created April 4, 2022 14:50 — forked from mshafer/ContentView.swift
Slide-over card (like in Maps or Stocks) using SwiftUI
import SwiftUI
struct ContentView : View {
var body: some View {
ZStack(alignment: Alignment.top) {
MapView()
SlideOverCard {
VStack {
CoverImage(imageName: "maitlandbay")
Text("Maitland Bay")
@artemkrachulov
artemkrachulov / memoryAddress.swift
Created November 2, 2023 17:53 — forked from matsuda/memoryAddress.swift
Get memory address in Swift
///
/// https://stackoverflow.com/a/29741007
///
let s = Struct() // Struct
withUnsafePointer(to: s) {
print(String(format: "%p", $0)
}
///
/// http://stackoverflow.com/a/36539213/226791
@artemkrachulov
artemkrachulov / ResultPublisher.swift
Created November 20, 2023 07:54 — forked from aduuub/ResultPublisher.swift
A Publisher that turns a completion with Result into a Combine Publisher
import Foundation
import Combine
public struct ResultPublisher<Success, Failure>: Publisher where Failure: Error {
public typealias Output = Success
public typealias Failure = Failure
public typealias ResultCallback = (Result<Success, Failure>) -> Void