Skip to content

Instantly share code, notes, and snippets.

View Maxatma's full-sized avatar
💻
clean and clear

Zaporozhchenko Oleksandr Maxatma

💻
clean and clear
  • remote
  • Ukraine
View GitHub Profile
@Maxatma
Maxatma / .swift
Created February 12, 2018 22:29
Cannot convert return expression of type 'Date' to return type 'Date'
class Date {
class func from(year: Int, month: Int , day: Int ) -> Date {
let gregorianCalendar = NSCalendar(calendarIdentifier: .gregorian)!
var dateComponents = DateComponents()
dateComponents.year = year
dateComponents.month = month
dateComponents.day = day
@Maxatma
Maxatma / custom thrift install
Last active April 10, 2018 00:25
Custom Apache Thrift installation guide
To install custom thrift ( like swift 3 from https://github.com/apocolipse/thrift),
u will need do all this things probably, otherwise just use
brew install thrift
1. Install homewbrew: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. Install all needed from this: http://thrift.apache.org/docs/install/
3. Be sure u installed bison, pkg-config, automake@1.15
4. do ./bootstrap.sh, if 'automake command not found' - check if u using needed version, if it linked. Try unlink and link again.
5. Check if all needed linked, if not do for example: brew link automake
6. If u got fatal error: 'openssl/err.h' file not found, do: ./configure LDFLAGS='-L/usr/local/opt/openssl/lib' CPPFLAGS='-I/usr/local/opt/openssl/include'
@Maxatma
Maxatma / histogram
Created March 9, 2020 17:27
Figure out appearance count of each element in array
extension Array where Element: Hashable {
var histogram: [Element: Int] {
return self.reduce(into: [:]) { counts, elem in counts[elem, default: 0] += 1 }
}
}
@Maxatma
Maxatma / IntrinsicTableView.swift
Created March 25, 2020 03:28
Self-resizing tableview
class IntrinsicTableView: UITableView {
override var contentSize: CGSize {
didSet {
self.invalidateIntrinsicContentSize()
}
}
override var intrinsicContentSize: CGSize {
self.layoutIfNeeded()
extension UIView {
func add(_ subviews: UIView...) {
subviews.forEach(addSubview)
}
}
@Maxatma
Maxatma / DumbTest.playground
Created January 9, 2019 11:47
Swift switch enum problem
import UIKit
enum DumbTest {
case get(user: String)
case get(pony: String, tail: String)
func getSome() -> String {
switch self {
case .get(let user):