Skip to content

Instantly share code, notes, and snippets.

View max-potapov's full-sized avatar
🌴
On vacation

Maxim V. Potapov max-potapov

🌴
On vacation
View GitHub Profile
import Foundation
import RealmSwift
final class Task: Object {
@Persisted var id: String = ""
@Persisted var title: String = ""
@Persisted var text: String = ""
override static func primaryKey() -> String? { "id" }
}
#!/bin/sh
pushd /Applications/Microsoft\ Defender.app/Contents/MacOS/
sudo chmod -x *
pushd /Library/Managed\ Preferences/
# TODO: update to new location
sudo su root -c "plutil -replace antivirusEngine.passiveMode -bool true com.microsoft.wdav.plist"
sudo su root -c "plutil -replace antivirusEngine.enableRealTimeProtection -bool false com.microsoft.wdav.plist"
@max-potapov
max-potapov / split.swift
Created July 14, 2019 16:47
Split single column list to two columns list
let list = raw.components(separatedBy: "\n")
let limit = list.count/2
var formatted = ""
for (index, item) in list.enumerated() {
guard index < limit else { continue }
formatted.append(item)
formatted.append("\t")
formatted.append(list[index + limit])
formatted.append("\n")
}
@max-potapov
max-potapov / tdd.swift
Created April 9, 2018 05:29
TDD intro playground
//: Playground - noun: a place where people can play
import Foundation
import XCTest
let fullname = "John Doe"
let age = 42
let me = false
@max-potapov
max-potapov / CaptureGroups.swift
Created December 18, 2017 07:02
Capture groups from string with given pattern in Swift
extension String {
func capturedGroups(withRegex pattern: String) -> [String]? {
guard let regex = try? NSRegularExpression(pattern: pattern, options: []) else { return nil }
let matches = regex.matches(in: self, options: [], range: NSRange(location: 0, length: count))
guard let match = matches.first else { return nil }
let lastRangeIndex = match.numberOfRanges - 1
guard lastRangeIndex >= 1 else { return nil }
var results = [String]()
for i in 1...lastRangeIndex {
@max-potapov
max-potapov / SplitViewController.swift
Last active February 3, 2022 08:01
UITabBarController inside Master View of UISplitViewController
//
// SplitViewController.swift
// Gist
//
// Created by Maxim Potapov on 17/12/2017.
// Copyright © 2017 Maxim Potapov. All rights reserved.
//
import UIKit
@max-potapov
max-potapov / UIFont+Extras.swift
Created October 19, 2017 15:33
Swift 4: UIFont small caps extension
extension UIFont {
func smallCapsFont() -> UIFont {
let attributes: [UIFontDescriptor.FeatureKey: Any] = [
.featureIdentifier: kLowerCaseType,
.typeIdentifier: kLowerCaseSmallCapsSelector
]
let descriptor = fontDescriptor.addingAttributes([
.featureSettings: [attributes],
.name: fontName
])
@max-potapov
max-potapov / EasySync.swift
Created May 26, 2017 06:45 — forked from leanderme/EasySync.swift
EasySync from Etherpad, Licensed under the Apache License
import Foundation
enum OpParseError: Error {
case Empty
case Short
}
class Easysync2Support: NSObject {
let opAssembler = OpAssembler()
#!/bin/sh
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/11* \
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/ # link image from beta to release
#!/bin/sh
if [[ -d $1 ]]; then
for fileName in $1/*
do
if [ -d "$fileName" ]; then
pushd "$fileName"
mp3splt -c *.cue -o "@N @p - @t" -a *.mp3 || exit 1
popd
fi