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
// To be able to use strings as caching keys, we have to use | |
// NSString here, since NSCache is only compatible with keys | |
// that are subclasses of NSObject: | |
let cache = NSCache<NSString, MyClass>() | |
//Problem: | |
//can only store class instances, and it’s only compatible with NSObject-based keys | |
//NSCache simple use here: | |
//https://www.hackingwithswift.com/example-code/system/how-to-cache-data-using-nscache |
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 | |
let stockPrices:[Int] = [10, 7, 5, 8, 11, 9] | |
func getMaxProfit(from: [Int]) -> Int { | |
var bestProfit: Int = 0 | |
var newSell: Int = 0 | |
var newBuy: Int = Int.max | |
var newSpread: Int = 0 | |
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 RxSwift | |
import RxCocoa | |
class BaseViewModel<NavigationStep, FromView, Output>: ViewModelType { | |
let bag = DisposeBag() | |
// Small type wrapping a RxSwift PublishSubject, that we notify about navigation, passing | |
// a contextual `NavigationStep` which typically is an enum, modelling all possible | |
// outgoing navigation steps we can take from this scene. | |
let navigator = Stepper<NavigationStep>() |
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
// Simulates n colored point lights (LEDs) shining at a wall from a distance wd. | |
// Wall distance; increase for more fuzzy lights, | |
// decrease for sharper point lights. | |
float wd = 0.15f; | |
const int nLights = 4; | |
const vec3 lights[nLights] = vec3[]( | |
vec3(1.0f, 0.0f, 0.0f), | |
vec3(0.0f, 1.0f, 0.0f), |
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
disabled_rules: # rule identifiers to exclude from running | |
- variable_name | |
- nesting | |
- function_parameter_count | |
opt_in_rules: # some rules are only opt-in | |
- control_statement | |
- empty_count | |
- trailing_newline | |
- colon | |
- comma |
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
/// This playground shows how to send and receive packets with low-level Posix UPD protocol API. | |
import Foundation /// Used for NSUTF8StringEncoding | |
import XCPlayground | |
/// Ensure the playground doesn't stop executing at the end of the main thread. | |
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true | |
/** Workaround for Swift not having access to the htons, htonl, and other C macros. | |
This is equivalent to casting the value to the desired bitsize and then |
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
post_install do |installer_representation| | |
installer_representation.pods_project.targets.each do |target| | |
target.build_configurations.each do |config| | |
if config.to_s == 'Beta' | |
config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = 'iPhone Distribution' | |
elsif config.to_s == 'Release' | |
config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = 'iPhone Distribution' | |
end | |
end | |
end |
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
const int trigPin = 4; | |
const int echoPin = 2; | |
void setup(){ | |
Serial.begin(9600); | |
pinMode(trigPin, OUTPUT); | |
pinMode(echoPin, INPUT); | |
} | |
void loop() |
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
package crappyBird; | |
import java.awt.Graphics; | |
import java.awt.Rectangle; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.awt.image.BufferedImage; | |
import java.io.IOException; | |
import java.net.URL; |