Skip to content

Instantly share code, notes, and snippets.

View vladimir-anisimov's full-sized avatar
🏠
Working from home

vladimir-anisimov

🏠
Working from home
  • Warsaw, Poland
View GitHub Profile
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: ViewController, context: Context) {
}
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
@vladimir-anisimov
vladimir-anisimov / starship.toml
Created February 4, 2023 01:01
starship.toml config
format = """
$username\
$hostname\
$directory\
$git_branch\
$git_state\
$git_status\
$git_metrics\
$fill\
$nodejs\
@vladimir-anisimov
vladimir-anisimov / .zchrc
Created February 4, 2023 01:01
.zchrc oh-my-zsh
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME=""
plugins=(
git
zsh-syntax-highlighting
zsh-autosuggestions
pod
)
extension Array {
mutating func removeFirst(where shouldBeRemoved: ((Element) -> Bool)) -> Element? {
for (index, element) in self.enumerated() {
let shouldBeRemoved: Bool = shouldBeRemoved(element)
if shouldBeRemoved == true {
return self.remove(at: index)
}
}
extension URLRequest {
/**
Configures the URL request for `multipart/form-data`. The request's `httpBody` is set, and a value is set for the HTTP header field `Content-Type`.
- Parameter parameters: The form data to set.
- Parameter encoding: The encoding to use for the keys and values.
- Throws: `MultipartFormDataEncodingError` if any keys or values in `parameters` are not entirely in `encoding`.
extension UIImage {
class func with(fileNamed: String,
withExtension fileExtension: String = ".png") -> UIImage {
guard let url = Bundle.main.url(forResource: fileNamed, withExtension: fileExtension) else { return UIImage() }
guard let data = try? Data(contentsOf: url) else { return UIImage() }
return UIImage(data: data) ?? UIImage()
}
}
extension Date {
static var appInstallDate: Date {
let urlToDocumentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!
let installDate = (try! FileManager.default.attributesOfItem(atPath: urlToDocumentsFolder.path)[FileAttributeKey.creationDate]) as! Date
return installDate
}
}
extension TimeInterval {
static var second: TimeInterval {
return 1.0
}
static var minute: TimeInterval {
return second * 60.0
}
static var hour: TimeInterval {
extension UIColor {
var redValue: CGFloat{ return CIColor(color: self).red }
var greenValue: CGFloat{ return CIColor(color: self).green }
var blueValue: CGFloat{ return CIColor(color: self).blue }
var alphaValue: CGFloat{ return CIColor(color: self).alpha }
convenience init(r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat = 1) {
self.init(red: r / 255, green: g / 255, blue: b / 255, alpha: a)
}
}
extension String {
var isBlank: Bool {
return self.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
func replace(string:String, replacement:String) -> String {
return self.replacingOccurrences(of: string, with: replacement, options: NSString.CompareOptions.literal, range: nil)
}
func removeWhitespace() -> String {
return self.replace(string: " ", replacement: "")