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)
| /* Taken zigmob's (http://forums.macrumors.com/showthread.php?t=1742566) workaround a step further | |
| And added some triggers to clean up these dodgy character combinations (ff, fi, fl). | |
| Still crashes on initial message read but saves having to manually run the sql query eve time a message contains the character combinations */ | |
| -- Working well for me so far -- | |
| CREATE TRIGGER insert_Ff AFTER INSERT ON ZWAMESSAGE | |
| BEGIN | |
| UPDATE ZWAMESSAGE | |
| SET ZTEXT = replace( ZTEXT, 'ff', 'f f') | |
| WHERE ZWAMESSAGE.ZTEXT like '%ff%'; |
| env = if ENV['dev'] == '1' | |
| 'dev' | |
| elsif ENV['adhoc'] == '1' | |
| 'adhoc' | |
| else | |
| 'dev' #default | |
| end | |
| if env == 'dev' | |
| app.codesign_certificate = 'iPhone Developer: Hwee Boon Yar (something)' |
| Steve Wozniak, Apple alumni and all-around amazing person - @stevewoz | |
| Victor Agreda, Jr., TUAW - @superpixels | |
| Mike T. Rose, TUAW - @miketrose | |
| John Gruber, Daring Fireball - @gruber | |
| Arnold Kim, MacRumors - @arnoldkim | |
| Jason Snell, Macworld - @jsnell | |
| Josh Lowensohn, CNET - @josh | |
| Chris O'Brien, LA Times - @obrien | |
| Mark Gurman, 9to5Mac - @markgurman | |
| Matthew Panzarino, TNW - @panzer |
| /* | |
| 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" |
| //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 | |
| class OpenStruct < BasicObject | |
| def initialize(hash) | |
| @struct = ::Struct.new(*hash.keys.map { |k| k.to_sym }) | |
| @struct = @struct.new(*hash.values) | |
| end | |
| def ==(other) | |
| to_h == other.to_h | |
| end |
| #!/usr/bin/env ruby | |
| # $ gem install CFPropertyList | |
| require 'cfpropertylist' | |
| path = File.expand_path '~/Library/Safari/Bookmarks.plist' | |
| plist = CFPropertyList::List.new file: path | |
| list = plist.value.value["Children"].value.select do |item| | |
| if title = item.value["Title"] | |
| title.value == 'com.apple.ReadingList' |
| // Let's define a basic Swift class. | |
| class Fruit { | |
| var type=1 | |
| var name="Apple" | |
| var delicious=true | |
| } | |
| // We can get at some info about an instance of an object using reflect(), which returns a Mirror. | |
| reflect(Fruit()).count | |
| reflect(Fruit())[1].0 |