View LearningIterators.class
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
// ================LearningIterators.class ================= | |
// class version 52.0 (52) | |
// access flags 0x31 | |
public final class LearningIterators { | |
// access flags 0x19 | |
public final static main()V | |
L0 | |
LINENUMBER 2 L0 |
View statuscode.swift
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
struct StatusCode: CustomStringConvertible, Equatable { | |
let code: Int | |
var description: String | |
static let ok = StatusCode(code: 200, description: "Success") | |
static let unauthorized = StatusCode(code: 403, description: "Unauthorized") | |
static let invalidCredentials = StatusCode(code: 401, description: "Invalid credentials") | |
static func == (lhs: Int, rhs: StatusCode) -> Bool { |
View apierror.swift
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
struct APIError: Error, Decodable, CustomStringConvertible { | |
let code: Int | |
let message: String | |
let errors: [String] = [] // May be dictionary?? | |
static let genericResponseError = APIError(code: 500, message: "Error getting response") | |
static let noResponseError = APIError(code: 500, message: "No response from server") |
View scrollviewinsets.swift
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
let scrollView = UIScrollView() | |
scrollView.backgroundColor = .systemGreen | |
scrollView.contentInset = UIEdgeInsets(top: 100, left: 100, bottom: 100, right: 100) | |
scrollView.contentSize = self.view.bounds.size | |
scrollView.translatesAutoresizingMaskIntoConstraints = false | |
self.view.addSubview(scrollView) | |
let views = ["scrollview": scrollView] | |
NSLayoutConstraint.activate([ | |
NSLayoutConstraint.constraints(withVisualFormat: "H:|[scrollview]|", metrics: nil, views: views), |
View peripheral-delegate.swift
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
// Implement peripheral callback methods | |
extension SocialService: CBPeripheralDelegate { | |
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { | |
// Discover characteristics | |
} | |
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { | |
// Request for TraceCharacteristic value -- TraceToken | |
} |
View central.swift
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
// Initialize central manager, set self as delegate | |
centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey: TraceService.CMRestoreIdentifierKey]) | |
// Provide implementation for delegate callback methods | |
extension TraceService: CBCentralManagerDelegate { | |
func centralManager(_ central: CBCentralManager, willRestoreState dict: [String: Any]) { ... } | |
func centralManagerDidUpdateState(_ central: CBCentralManager) { | |
// When .poweredOn, scan for Peripherals |
View peripheral.kt
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
// Starts GattServer to serve remote Central requests | |
private val gattServer: BluetoothGattServer by lazyNone { | |
bluetoothManager.openGattServer(this.applicationContext, GattServerCallback()) | |
} | |
private class GattServerCallback : BluetoothGattServerCallback() { | |
override fun onConnectionStateChange(device: BluetoothDevice, status: Int, newState: Int) { ... } | |
override fun onCharacteristicReadRequest(device: BluetoothDevice, requestId: Int, offset: Int, characteristic: BluetoothGattCharacteristic) { |
View advertise.kt
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
// Advertisement data: only has Trace UUID to enable filtering | |
val advertiseData: AdvertiseData = AdvertiseData.Builder() | |
.addServiceUuid(Services.TRACE.serviceUUID) | |
.build() | |
// Advertise | |
bleAdvertiser.startAdvertising(advertiseSettings, advertiseData, adCallback) | |
// Advertisement callback - delivers advertising operation status | |
private inner class AdCallback : AdvertiseCallback() { |
View lazynone.kt
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
/** | |
* Initialize lazily without thread synchronization | |
* | |
* @param initializer Initializer block | |
* @return [Lazy] instance | |
*/ | |
fun <T> lazyNone(initializer: () -> T): Lazy<T> = lazy(LazyThreadSafetyMode.NONE, initializer) |
View handlerthreadusage.kt
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 NQueensActivity : AppCompatActivity() { | |
private val handlerThread = HandlerThread("NQueens").also { it.start() } | |
private val handler = Handler(handlerThread.looper) | |
private var queens = 1 | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
solveButton.setOnClickListener { |
NewerOlder