This file contains hidden or 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
#!/usr/bin/swift | |
/* | |
* Command line script that draws an evenly spaced grid over an image and labels each grid square. | |
*/ | |
import Foundation | |
// Function to run a shell command and capture the output | |
func runShellCommand(_ command: String, printCommand: Bool) -> Int32 { |
This file contains hidden or 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
// BEGIN GDSCRIPT - Takes >9000ms. | |
extends TextureRect | |
const map_dimension: int = 1024 | |
enum MapType { AIR = 0, ROCK = 1 } | |
var map_array: PackedInt32Array | |
var temp_array: PackedInt32Array |
This file contains hidden or 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
#!/usr/bin/swift | |
// Best starters according to 3 Blue 1 Brown are "Trace" and "Crate". | |
// https://www.youtube.com/watch?v=fRed0Xmc2Wg | |
// This script, given the entire Wordle word list, chooses the following: | |
// TARES - 6.196031220185254 | |
// LARES - 6.151215692838039 | |
// RALES - 6.116011613563718 | |
// RATES - 6.098037836330005 |
This file contains hidden or 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 Foundation | |
// Get the Unix list of all words. | |
let words = try! String(contentsOfFile: "/usr/share/dict/words") | |
.split(whereSeparator: \.isNewline).map({ $0.uppercased() }) | |
// Calculate frequencies of each letter in the above corpus of words. | |
var wordFrequencies:[String.Element: Int] = [:] | |
for word in words { | |
// Only look at 5-letter words. | |
if word.count != 5 { |
This file contains hidden or 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
BOOL isCurrentlyDaytimeInNYC() | |
{ | |
static CGFloat const latitudeNYC = 40.7831; | |
static CGFloat const longitudeNYC = 73.9712; | |
return isCurrentlyDaytime(latitudeNYC, | |
longitudeNYC); | |
} |
This file contains hidden or 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
BOOL isCurrentlyDaytime(CGFloat latitude, CGFloat longitude) | |
{ | |
// http://users.electromagnetic.net/bu/astro/iyf-calc.php | |
// http://aa.quae.nl/en/reken/zonpositie.html | |
static NSUInteger const secondsPerDay = 60*60*24; | |
static NSTimeInterval const julianLeap = 0.0009; | |
static double const degreeToRadian = M_PI/180.0; | |
static double const radianToDegree = 180.0/M_PI; | |
This file contains hidden or 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 UIKit | |
class ViewController: UIViewController { | |
@IBOutlet var buttonA:UIButton! | |
@IBOutlet var buttonB:UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() |
This file contains hidden or 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
class TraitViewController: UIViewController { | |
//this function comes from the UITraitEnvironment protocol | |
override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) { | |
let horizontalSize = traitCollection.horizontalSizeClass | |
let verticalSize = traitCollection.verticalSizeClass | |
let previousHorizontalSize = previousTraitCollection.horizontalSizeClass | |
let previousVerticalSize = previousTraitCollection.verticalSizeClass |
This file contains hidden or 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
let testView = view.viewWithStringTag("testView") | |
println("TEST VIEW: \(testView)") |
This file contains hidden or 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
private var stringTagHandle: UInt8 = 0 | |
extension UIView { | |
//use Objective C Associated Object API to add this property to UIView | |
@IBInspectable public var stringTag:String? { | |
get { | |
if let object = objc_getAssociatedObject(self, &stringTagHandle) as? String { | |
return object | |
} |
NewerOlder