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 kotlinx.coroutines.* | |
import kotlinx.coroutines.experimental.* | |
import kotlin.system.measureTimeMillis | |
fun main() { | |
println("start") | |
println(bunchOfRequests().toString()) | |
println("stop") | |
} |
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
extension UIView { | |
/// Traverses subviews recursively with breadth first search, returns the first subview that | |
/// satisfies the predicate. | |
func firstSubview(where predicate: (UIView) -> Bool) -> UIView? { | |
var subviewsToTraverse = subviews | |
while subviewsToTraverse.count > 0 { | |
guard !predicate(subviewsToTraverse[0]) else { |
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
extension Collection { | |
/// Returns the element at the specified index if it is within bounds, otherwise nil. | |
func nth(_ index: Index) -> Element? { | |
return indices.contains(index) ? self[index] : nil | |
} | |
} |
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
use std::str; | |
use std::thread; | |
use std::net::UdpSocket; | |
fn main() { | |
let addr = "239.255.255.250:1982"; | |
let socket = match UdpSocket::bind(addr) { | |
Ok(s) => s, | |
Err(e) => panic!("couldn't bind socket: {}", e) | |
}; |
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 socket | |
import fcntl | |
# Socket for scanning | |
scan_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
# Lock the socket | |
fcntl.fcntl(scan_socket, fcntl.F_SETFL, os.O_NONBLOCK) | |
# Multicast address | |
address = ("239.255.255.250", 1982) |
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
for family in UIFont.familyNames { | |
print(family) | |
for name in UIFont.fontNames(forFamilyName: family.description) { | |
print(" \(name)") | |
} | |
} |
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
extension String { | |
func titlecased() -> String { | |
if self.count <= 1 { | |
return self.uppercased() | |
} | |
let regex = try! NSRegularExpression(pattern: "(?=\\S)[A-Z]", options: []) | |
let range = NSMakeRange(1, self.count - 1) | |
var titlecased = regex.stringByReplacingMatches(in: self, range: range, withTemplate: " $0") | |