Skip to content

Instantly share code, notes, and snippets.

View alekseypotapov-dev's full-sized avatar

Aleksey Potapov alekseypotapov-dev

View GitHub Profile
@alekseypotapov-dev
alekseypotapov-dev / FoldersMerger.swift
Created September 2, 2020 07:05
Merging files using FileManager in swift
let merger = FoldersMerger(actionType: .copy, conflictResolution: .keepSource)
merger.merge(atPath: sourceFolder, toPath: destinationFolder)
class FoldersMerger {
enum ActionType { case move, copy }
enum ConflictResolution { case keepSource, keepDestination }
private let fileManager = FileManager()
import UIKit
// [^] Negated set - Match any character that is not in the set.
// @ Character - Matches "@" character (char code 64).
// * Quantifier - Match 0 or more of pending token.
// $ End - Matches the end of the string, or the end of a line if the multiline flag (m) is enabled. This matches a position, not a character.
func matchesRegex(_ regex: String, in text: String) -> String {
do {
let regex = try NSRegularExpression(pattern: regex)
@alekseypotapov-dev
alekseypotapov-dev / lldb-commands.md
Created January 7, 2020 11:48
List of commands that are useful during development

ignore asserts

process handle -p true -s false SIGSTOP
func drawTableHeaderTitles(titles: [String], drawContext: CGContext, pageRect: CGRect) {
// prepare title attributes
let textFont = UIFont.systemFont(ofSize: 16.0, weight: .medium)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .left
paragraphStyle.lineBreakMode = .byWordWrapping
let titleAttributes = [
NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: textFont
]

Low Quality Answer

Welcome to Stack Overflow. Thanks for writing the answer! However, while answering the question please try to be more explicit and provide some more details e.g. code samples, output, documentation links, screenshots. I would recommend you to check SO's [official How to Answer article](https://stackoverflow.com/help/how-to-answer).

Low Quality Question

Welcome to Stack Overflow. Your question should have your effort to solve the task. Here you post abstract question which people will likely delete rather answer. Code is good, environment, screenshots, error codes if any. I would recommend you to check SO's [official How to Ask article](https://stackoverflow.com/help/how-to-ask).

Code as image

@alekseypotapov-dev
alekseypotapov-dev / unzip.txt
Created December 5, 2019 13:12
Terminal command to unzip archive where files have bad encoding names.
ditto -V -x -k --sequesterRsrc --rsrc FILENAME.ZIP DESTINATIONDIRECTORY
@alekseypotapov-dev
alekseypotapov-dev / rotate-pdfs.py
Last active January 15, 2020 17:34
Rotate all PDFs in a folder and put into another one
#!/usr/bin/env python3
import PyPDF2
import re
import sys
import os
import shutil
dir_path = os.getcwd()
rotatedDir_path = dir_path + '/rotated'
@alekseypotapov-dev
alekseypotapov-dev / whereAreTheBooks.txt
Created September 6, 2019 06:57
paths to iBooks folder
If you’ve enabled iCloud, they’re stored in Mobile Documents folder.
Here’s the full path to books you've added:
~/Library/Mobile Documents/iCloud~com~apple~iBooks/Documents/
Here's the full path to books purchased through the iBooks store:
~/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks
The path is only accessible via Terminal. Going through Finder will only redirect you to the iCloud folder. So open up Terminal:
@alekseypotapov-dev
alekseypotapov-dev / darth-vader-legacy.scpt
Created September 4, 2019 09:29
Apple Script to toggle between the Dark/Light mode on macOS
tell application "System Events" to tell appearance preferences to set dark mode to not dark mode
Start by adding a label to your LaunchScreen.storyboard:
Format the label however you like. I like to use something subtle that you can read when you need to but that isn’t very noticeable otherwise.
Set Document/Label to APP_VERSION. You will use this value in the Build Phase script.
Continue by adding the custom Build Phase:
Select your project in the upper-left-hand corner of Xcode.