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
#!/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 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 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 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 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 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
@IBOutlet weak var constraint1: NSLayoutConstraint! | |
@IBOutlet weak var constraint2: NSLayoutConstraint! | |
@IBAction func animateViews(sender: AnyObject) { | |
constraint1.constant = CGFloat(arc4random_uniform(200)) | |
constraint2.constant = CGFloat(arc4random_uniform(200)) | |
UIView.animateWithDuration(0.5, animations: { | |
self.view.setNeedsUpdateConstraints() | |
self.view.layoutIfNeeded() |
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
BOOL isCurrentlyDaytimeInNYC() | |
{ | |
static CGFloat const latitudeNYC = 40.7831; | |
static CGFloat const longitudeNYC = 73.9712; | |
return isCurrentlyDaytime(latitudeNYC, | |
longitudeNYC); | |
} |
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 UIKit | |
class ViewController: UIViewController { | |
@IBOutlet var buttonA:UIButton! | |
@IBOutlet var buttonB:UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() |
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
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 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
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext | |
{ | |
UIViewController* toController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; | |
UIViewController* fromController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; | |
UIView* container = [transitionContext containerView]; | |
//get rects that represent the top and bottom halves of the screen | |
CGSize viewSize = fromController.view.bounds.size; | |
CGRect topFrame = CGRectMake(0, 0, viewSize.width, viewSize.height/2); | |
CGRect bottomFrame = CGRectMake(0, viewSize.height/2, viewSize.width, viewSize.height/2); |
NewerOlder