Skip to content

Instantly share code, notes, and snippets.

@steipete
steipete / ios-xcode-device-support.sh
Last active December 12, 2023 03:36
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
import Cocoa
// Missing isWord
func isWord(string: String) -> Bool {
if let _ = Int(string) { return false }
let range = NSSpellChecker.shared().checkSpelling(of: string, startingAt: 0)
return range.location == NSNotFound
}
/*:
import UIKit
// Swift rewrite challenge
// Starting point: https://gist.github.com/jkereako/200342b66b5416fd715a#file-scale-and-crop-image-swift
func scaleAndCropImage(
image: UIImage,
toSize size: CGSize,
fitImage: Bool = true
) -> UIImage {
import Foundation
// Extend String to support regex searching by conforming
// to CustomStringConvertible
extension String: CustomStringConvertible {
public var description: String {return self}
}
// Regex support for keys
public extension Dictionary where Key: CustomStringConvertible {
@tiann
tiann / auto_switch_kb.py
Created December 2, 2015 06:51
auto switch keyboard to english in specific applications
#! /usr/bin/env python
# coding: utf-8
'''
auto switch keyboard between different applications
if you want to change the app list, modify the var 'ignore_list'
'''
from AppKit import NSWorkspace, NSWorkspaceDidActivateApplicationNotification, NSWorkspaceApplicationKey
import Cocoa
// Note: use of enumeration var in generic is instadeath
// Note: use of static var in generic is not yet supported
public protocol EnumConvertible: Hashable {
init?(hashValue hash: Int)
static func countMembers() -> Int
static func members() -> [Self]
}
@erica
erica / pggrep.swift
Last active November 30, 2018 08:52
Find files in playgrounds, which are otherwise not indexed by spotlight
//
// main.swift
// pggrep - updated 12/4/15
// Created by Erica Sadun on 6/17/15.
// Copyright © 2015 Erica Sadun. All rights reserved.
//
import Foundation
extension String {
@DivineDominion
DivineDominion / ValueTransformation.swift
Created March 1, 2015 19:27
Paste this into a playground and see what happens with the two client code examples at the bottom. Should work out of the box.
import Cocoa
/// A wrapper around any type to make Result compile
class Box<T> {
let unbox: T
init(_ value: T) {
self.unbox = value
}
}
@staltz
staltz / introrx.md
Last active April 25, 2024 04:18
The introduction to Reactive Programming you've been missing
#! /usr/bin/env python3
'''pyCookieCheat.py
2015022 Now its own GitHub repo, and in PyPi.
- For most recent version: https://github.com/n8henrie/pycookiecheat
- This gist unlikely to be maintained further for that reason.
20150221 v2.0.1: Now should find cookies for base domain and all subs.
20140518 v2.0: Now works with Chrome's new encrypted cookies.
See relevant post at http://n8h.me/HufI1w