Skip to content

Instantly share code, notes, and snippets.

View kirilltitov's full-sized avatar

Kirill Titov kirilltitov

View GitHub Profile
@kirilltitov
kirilltitov / xctest_async_test.swift
Created March 3, 2021 10:36
XCTest + async/await
import XCTest
import _Concurrency
extension XCTestCase {
func asyncTest(
expectationDescription: String? = nil,
timeout: TimeInterval = 3,
file: StaticString = #file,
line: Int = #line,
closure: @escaping () async throws -> ()
import FDB
import NIO
enum E: Error {
case recordExists
}
let fdb = FDB()
let key = "somekey".bytes
import NIO
public protocol SyncStorage {
associatedtype Key: Hashable
associatedtype Value
var eventLoops: [EventLoop] { get }
func getOrSet(
by key: Key,
import Foundation
public extension Dictionary where Key == String, Value == Any {
fileprivate func _get<T>(path: [String]) -> T? {
var root = self
for idx in 0 ..< path.count - 1 {
guard let _root = root[path[idx]] as? [String: Any] else {
return nil
}
@kirilltitov
kirilltitov / HTTPServer.swift
Created May 17, 2019 12:58
LGNC HTTPHandler
import Foundation
import LGNCore
import LGNP
import LGNPContenter
import LGNS
import NIO
import NIOHTTP1
public extension LGNC {
struct HTTP {
@kirilltitov
kirilltitov / main.swift
Last active July 10, 2018 12:48
Swift 4 Any to Bytes (and back again) conversion (Foundationless! No Data or NSData!)
// Notice no Foundation :3
typealias Byte = UInt8
typealias Bytes = [Byte]
func getBytes<Input>(_ input: Input) -> Bytes {
return withUnsafeBytes(of: input) { Bytes($0) }
}
// You must be ABSOLUTELY SURE about input bytes, or enjoy your fresh and crispy BAD_ACCESS runtime error
#ifndef FDB_C_OPTIONS_G_H
#define FDB_C_OPTIONS_G_H
#pragma once
/*
* FoundationDB C API
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
@kirilltitov
kirilltitov / test.c
Last active July 9, 2018 11:07
FoundationDB memory leak test
#define FDB_API_VERSION 520
#include "foundationdb/fdb_c.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
void checkError(fdb_error_t errorNum)
@kirilltitov
kirilltitov / libfdb.pc
Created July 5, 2018 10:29
FoundationDB pkgconfig (macOS specific)
prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: fdb
Description: FoundationDB macOS library
Version: 5.2.5
Cflags: -I${includedir}
Libs: -L${libdir} -lfdb_c
@kirilltitov
kirilltitov / ip.swift
Created June 19, 2018 18:31
Swift IP string to UInt32 and backward
func stringIpToInt(_ input: String) -> UInt32 {
var result: UInt32 = 0
var i = 0
for part in input.split(separator: ".") {
result |= UInt32(part)! << ((3 - i) * 8)
i += 1
}
return result
}