The following is a nice Swift pattern to make a vanilla Swift state machine:
class Machine {
enum State {
case foo
case bar(String)
case baz(Int)
// Run any SwiftUI view as a Mac app. | |
import Cocoa | |
import SwiftUI | |
NSApplication.shared.run { | |
VStack { | |
Text("Hello, World") | |
.padding() | |
.background(Capsule().fill(Color.blue)) |
// | |
// CAMediaTimingFunction.swift | |
import UIKit | |
extension CAMediaTimingFunction { | |
static let linear = CAMediaTimingFunction(name: .linear) | |
static let easeOut = CAMediaTimingFunction(name: .easeOut) |
# Use this script to test that your Telegram bot works. | |
# | |
# Install the dependency | |
# | |
# $ gem install telegram_bot | |
# | |
# Run the bot | |
# | |
# $ ruby bot.rb | |
# |
//Using IP Sidekick for geolocation in Numbers.app | |
//hboon@motionobj.com | |
//https://ipsidekick.com | |
//Instructions: | |
//1. Save this file as using-ipsidekick-with-numbers-app.scpt in Script Editor.app | |
//2. In Numbers app, open your spreadsheet and select the cells with IP address | |
//..you want to lookup and run this script in Script Editor.app | |
import Foundation | |
import WebKit | |
final class WebCacheCleaner { | |
class func clean() { | |
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast) | |
print("[WebCacheCleaner] All cookies deleted") | |
WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in |
JavaScriptCore is a built-in iOS library that enables you to use JavaScript in apps alongside Objective-C and Swift. It lets developers read JavaScript from a string, execute it from Objective-C or Swift, and share data structures and functions across languages. We JavaScriptCore to share code between Web and iOS.
# Add this snippet to the top of your playbook. | |
# It will install python2 if missing (but checks first so no expensive repeated apt updates) | |
# gwillem@gmail.com | |
- hosts: all | |
gather_facts: False | |
tasks: | |
- name: install python 2 | |
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal) |
/* | |
Basically what we are going to do is use and profit from NSURLRequests being conformant to NSCoding, | |
and a little known API from NSURLProtocol which allows us attach info to requests. | |
*/ | |
//Step 0: For the purpose of this gist, we'll already have a background session setup and assume a bunch of stuff. | |
NSURLSession *bgSession = [NSURLSession magicMethodWhichGivesMeTheAlreadySetupSession]; //Geeez, Methods are long in Obj-C. | |
//IMPORTANT: Request must be mutable in order for this to work. Got an immutable one. Make a copy. Can't? Well, Make it so!. | |
//Step 1: Setup your basic request. |
def build_path | |
"build/iPhoneOS-7.0-Release/" | |
end | |
def ipa_name | |
"APP_FILE_NAME.ipa" | |
end | |
def dsym_name | |
"APP_FILE_NAME.app.dSYM" |