Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

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

Oleksandr Glagoliev fewlinesofcode

🏠
Working from home
View GitHub Profile
@fewlinesofcode
fewlinesofcode / Date2Str.swift
Created February 20, 2020 17:41
Human readable Date to String
let dcf = DateComponentsFormatter()
dcf.unitsStyle = .abbreviated
dcf.includesApproximationPhrase = false
dcf.includesTimeRemainingPhrase = true
dcf.allowedUnits = [.day, .hour, .minute, .second]
let past = Date().advanced(by: -10)
let now = Date()
let humanReadableString = dcf.string(from: past, to: now)
print(humanReadableString!)
@fewlinesofcode
fewlinesofcode / RedBlackTree.swift
Created February 10, 2020 16:14
Red-Black Tree implementation in Swift
//
// main.swift
// Beachline
//
// Created by Oleksandr Glagoliev on 1/4/20.
// Copyright © 2020 Oleksandr Glagoliev. All rights reserved.
//
import Foundation
@fewlinesofcode
fewlinesofcode / ChangsAlgorithm.swift
Created September 20, 2019 04:47
Changs algorithm. Calculate and return the convex hull of a given sequence of points O(*n* log *n*)
import Foundation
public func cross(_ o: CGPoint, _ a: CGPoint, _ b: CGPoint) -> CGFloat {
let lhs = (a.x - o.x) * (b.y - o.y)
let rhs = (a.y - o.y) * (b.x - o.x)
return lhs - rhs
}
/// Calculate and return the convex hull of a given sequence of points.
///
@fewlinesofcode
fewlinesofcode / AugmentedIntevalTree.swift
Last active February 15, 2023 14:18
Augmented Interval Search tree
//
// Created by @fewlinesofcode on 9/6/18.
// Copyright (c) 2018 Oleksandr Glagoliev. All rights reserved.
//
public class Interval<T: Comparable> {
private (set) var start: T
private (set) var end: T
var max: T
@fewlinesofcode
fewlinesofcode / CodeReviewChecklistV0.md
Last active July 17, 2019 06:28
Code review checklist

Code review checklist

Basic

  • No conflicts
  • No warnings
  • Builds

Tests

  • Tests passing
/**
* The $1 Unistroke Recognizer
*
* Jacob O. Wobbrock, Ph.D.
* The Information School
* University of Washington
* Seattle, WA 98195-2840
* wobbrock@uw.edu
*
* Andrew D. Wilson, Ph.D.
@fewlinesofcode
fewlinesofcode / CGVectorArithmetics.swift
Last active April 12, 2021 18:02
2d Vector Arithmetics Swift 5
//
//
// CGVectorArithmetics.swift
//
// Created by fewlinesofcode.com on 2/6/19.
// Copyright © 2019 fewlinesofcode.com All rights reserved.
//
import Foundation
import CoreGraphics
@fewlinesofcode
fewlinesofcode / Vector2D.swift
Last active April 12, 2021 17:57
Some useful operations on 2d vectors
//
// Vector2D.swift
//
// Created by fewlinesofcode.com on 2/6/19.
// Copyright © 2019 fewlinesofcode.com All rights reserved.
//
import Foundation
struct Vector2D {
@fewlinesofcode
fewlinesofcode / TypeErasure.swift
Created November 9, 2018 17:11
Playground code for the article
import Foundation
protocol CustomProtocol {
associatedtype AssociatedType
func foo(argument: AssociatedType)
}
//let array = [CustomProtocol]() // Gives error: Protocol 'CustomProtocol' can only be used as a generic constraint because it has Self or associated type requirements
public struct AnyCustomProtocol<T>: CustomProtocol {
@fewlinesofcode
fewlinesofcode / PlaceholderTextView.swift
Last active November 6, 2018 14:52
The idea was to make the simplest possible solution which allows to use placeholders of different colors, resizes to placeholders size, will not overwrite a `delegate` meanwhile keeping all `UITextView` functions work as expected.
//
// Created by Oleksandr Glagoliev on 05/11/2018.
// Copyright © 2018 Oleksandr Glagoliev. All rights reserved.
//
import UIKit
class PlaceholderTextView: UITextView {
var placeholderColor: UIColor = .lightGray
var defaultTextColor: UIColor = .black