Skip to content

Instantly share code, notes, and snippets.

View RobertKoval's full-sized avatar
🏠
Working from home

Robert Koval RobertKoval

🏠
Working from home
  • Kyiv, Ukraine
View GitHub Profile
@RobertKoval
RobertKoval / gist:3ebd7c39dd28b83873df3e0d745a74aa
Last active December 7, 2023 09:43
Advent of Code inputs
sdpgz3five4seven6fiveh
876mbxbrntsfm
fivek5mfzrdxfbn66nine8eight
554qdg
ninevsgxnine6threesix8
4fivehmg614five
three6sdnttwothree3
two26four2
586dntdbtmfourrjnjdzptcfrpr3
dgkclmseven8
@RobertKoval
RobertKoval / Combine2Sequence.swift
Created November 10, 2023 16:39
Combine 2 sequence in order to perform combination mapping (like for inside for)
public struct Combine2Sequence<Base1: Sequence, Base2: Sequence>: Sequence {
private let base1: Base1
private let base2: Base2
public init(_ base1: Base1, _ base2: Base2) {
self.base1 = base1
self.base2 = base2
}
public func makeIterator() -> Iterator {
@RobertKoval
RobertKoval / comparableArray.swift
Last active November 8, 2023 20:52
Swift Comparable Array extension
[3,2,1] > [2,1,0] // true
[3,2,1] > [2,10,1000] // true
[3,4,2] < [3,4,3] // true
[3,4,2] > [2,4] // true
[3,4,2] == [3,4,2] // true
extension Array: Comparable where Element: Comparable {
public static func < (lhs: Array<Element>, rhs: Array<Element>) -> Bool {
for (a, b) in zip(lhs, rhs) where a != b {
return a < b
@RobertKoval
RobertKoval / PartialApplication.swift
Created July 22, 2023 18:49
Generic partial application function using new Value and Type Parameter Packs
func partiallyApply<T, U, each V>(_ function: @escaping (T, repeat each V) -> U, with argument: T) -> (repeat each V) -> U {
return { (rest: repeat each V) in
return function(argument, repeat each rest)
}
}
int run_server() {
const char server_msg[25] = "Welocme to server!";
pthread_t pthread;
pthread_attr_t pthread_attr;
pthread_attr_init(&pthread_attr);
server_t server;