This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
pbcopy.ps1 — A PowerShell function to mimic macOS `pbcopy` | |
📌 Usage: | |
"Hello world" | pbcopy | |
pbcopy # then type text, Ctrl+Z + Enter | |
📁 Install: | |
- Save this file somewhere on disk, e.g. C:\Scripts\pbcopy.ps1 | |
- Open your PowerShell profile: notepad $PROFILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension View { | |
/// Conditionally displays the view based on the provided Boolean condition. | |
/// | |
/// This modifier allows you to show or hide a view depending on the value of `condition`. | |
/// If `condition` is `true`, the view is displayed as is. | |
/// If `condition` is `false`, the view is replaced by an `EmptyView`, which effectively removes it from the layout. | |
/// | |
/// - Parameter condition: A Boolean value that determines whether the view should be displayed. If `true`, the view is shown; if `false`, it is hidden. | |
/// - Returns: Either the view itself, or an `EmptyView` if the condition is `false`. | |
/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension URLResponse { | |
/// Returns casted `HTTPURLResponse` | |
var http: HTTPURLResponse? { | |
return self as? HTTPURLResponse | |
} | |
} | |
extension HTTPURLResponse { | |
/// Returns `true` if `statusCode` is in range 200...299. | |
/// Otherwise `false`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// taken 2018-03-19 from wikipedia. https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes | |
public enum Iso639_1: String { | |
case ab = "AB" | |
case aa = "AA" | |
case af = "AF" | |
case ak = "AK" | |
case sq = "SQ" | |
case am = "AM" | |
case ar = "AR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Check whether active window is in fullscreen mode. | |
/// - Parameter processIdentifier: the pid given by "NSWorkspace.shared.frontmostApplication?.processIdentifier" | |
/// - Returns: true if fullscreen, false if windowed | |
func isFullScreen(processIdentifier: pid_t) -> Bool { | |
if let winArray: CFArray = CGWindowListCopyWindowInfo(.excludeDesktopElements, kCGNullWindowID) { | |
for i in 0..<CFArrayGetCount(winArray) { | |
if let window: [String : Any] = unsafeBitCast(CFArrayGetValueAtIndex(winArray, i), to: CFDictionary.self) as? [String : Any] { | |
if let pid = window["kCGWindowOwnerPID"] as? Int32 { | |
if pid == processIdentifier { | |
if let bounds: [String : Any] = window["kCGWindowBounds"] as? [String : Any], let boundsWidth = bounds["Width"] as? CGFloat, let boundsHeight = bounds["Height"] as? CGFloat { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension AnyView { | |
/// Return UIHostingController for a SwiftUI View. | |
/// - Usage: let vc = AnyView( YourSwiftUIViewHere() ).asUIHostingController() | |
/// - Created by Michel Storms. | |
/// - Returns: UIHostingController ready to use with UIKit. | |
func asUIHostingController() -> UIHostingController<AnyView> { | |
return UIHostingController(rootView: self) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIViewController { | |
var previousViewController: UIViewController? { | |
guard let navigationController = navigationController else { return nil } | |
let count = navigationController.viewControllers.count | |
return count < 2 ? nil : navigationController.viewControllers[count - 2] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSManagedObject { | |
/// Print content of object to console. | |
func printContent() { | |
print("\nNSManagedObjectID: \(self.objectID) - key/value dump:") | |
for key in self.entity.attributesByName.keys { | |
print("\(key): \(self.value(forKey: key) ?? "nil")") | |
} | |
print("\n") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def createFolder(directory): | |
try: | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
except OSError: | |
print ('Error: Creating directory. ' + directory) | |