Skip to content

Instantly share code, notes, and snippets.

View sgbasaraner's full-sized avatar
💭
Y = λ f . (λ x . f (x x)) (λ x . f (x x ))

Sarp Güney Başaraner sgbasaraner

💭
Y = λ f . (λ x . f (x x)) (λ x . f (x x ))
View GitHub Profile
@sgbasaraner
sgbasaraner / main.kt
Created October 21, 2019 18:06
Coroutines Example
import kotlinx.coroutines.*
import kotlinx.coroutines.experimental.*
import kotlin.system.measureTimeMillis
fun main() {
println("start")
println(bunchOfRequests().toString())
println("stop")
}
@sgbasaraner
sgbasaraner / subviews.swift
Last active July 24, 2019 15:49
Find a subview that satisfies a predicate recursively
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 {
@sgbasaraner
sgbasaraner / Collection.swift
Created September 9, 2018 03:53
Rust-like nth() method in Swift
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
}
}
@sgbasaraner
sgbasaraner / yee.rs
Created March 6, 2018 08:54
rust search broadcast
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)
};
@sgbasaraner
sgbasaraner / yee.py
Created March 6, 2018 08:52
python search broadcast
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)
@sgbasaraner
sgbasaraner / allFonts.swift
Created February 10, 2018 09:26
print all available fonts in iOS with Swift 4
for family in UIFont.familyNames {
print(family)
for name in UIFont.fontNames(forFamilyName: family.description) {
print(" \(name)")
}
}
@sgbasaraner
sgbasaraner / titlecase.swift
Created November 29, 2017 08:32
Title Case Extension for Swift 4
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")