Skip to content

Instantly share code, notes, and snippets.

View ekurutepe's full-sized avatar

Engin Kurutepe ekurutepe

View GitHub Profile
import SwiftUI
struct ContentView: View {
@State private var showSheetView = false
var body: some View {
VStack(spacing: 0) {
topBar
Color.blue
}
@ekurutepe
ekurutepe / 5-letter-word-letter-frequencies.swift
Last active January 8, 2022 23:48
Letter frequencies ~12k common English five letter words.
import Foundation
extension String {
var letters: [String] {
map { "\($0)" }
}
}
func topLetterFrequencies(letters: [String], top n: Int = 10) -> [(key: String, value: Int)] {
var letterFrequencies = [String: Int]()
@ekurutepe
ekurutepe / ApproximateConversion.swift
Last active May 18, 2020 09:06
Conversions in Measurement too accurate for you? Here take this…
import Foundation
extension Measurement where UnitType: Dimension {
func approximatelyConverted(to otherUnit: UnitType) -> Measurement<UnitType> {
switch (unit, otherUnit) {
case (UnitLength.meters, UnitLength.feet):
return Measurement(value: value * 3, unit: otherUnit)
case (UnitLength.feet, UnitLength.meters):
return Measurement(value: value * 3 / 10, unit: otherUnit)
case (UnitSpeed.knots, UnitSpeed.metersPerSecond):
private func configureMicrophone() -> Bool {
session.beginConfiguration()
defer {
session.commitConfiguration()
}
session.usesApplicationAudioSession = true
session.automaticallyConfiguresApplicationAudioSession = false
do {
@ekurutepe
ekurutepe / FlippedTableView.swift
Created April 24, 2019 14:37
UITableView with flipped y-axis to easy scroll to bottom.
//
// FlippedTableView.swift
// translate
//
// Created by Engin Kurutepe on 26.12.18.
// Copyright © 2018 Fifteen Jugglers Software UG. All rights reserved.
//
import UIKit
@ekurutepe
ekurutepe / NSScanner+Swift.swift
Last active November 29, 2016 20:59 — forked from natecook1000/NSScanner+Swift.swift
Swift-friendly NSScanner methods. Updated with Swift 3.0 syntax.
// NSScanner+Swift.swift
// A set of Swift-idiomatic methods for NSScanner
//
// (c) 2015 Nate Cook, licensed under the MIT license
import Foundation
extension Scanner {
// MARK: Strings
@ekurutepe
ekurutepe / gist:7994d725af6975f1d035
Last active August 29, 2015 14:13
How to extract an email out of an ABRecord using Swift…
var unmanagedEmails = ABRecordCopyValue(person, property);
let emails: ABMultiValueRef =
Unmanaged.fromOpaque(unmanagedEmails.toOpaque()).takeUnretainedValue() as NSObject as ABMultiValueRef
let index = ABMultiValueGetIndexForIdentifier(emails, identifier)
var unmanagedEmail = ABMultiValueCopyValueAtIndex(emails, index);
let email: String = Unmanaged.fromOpaque(unmanagedEmail.toOpaque()).takeUnretainedValue() as NSObject as String
@ekurutepe
ekurutepe / gist:519bd73bdb622d7301dd
Created July 24, 2014 12:06
View Lifecycle and window property
2014-07-24 14:05:07.735 test[18888:60b] viewDidLoad window: (null)
2014-07-24 14:05:07.736 test[18888:60b] viewWillAppear: window: (null)
2014-07-24 14:05:08.245 test[18888:60b] viewDidAppear: window: <UIWindow: 0x8f40320; frame = (0 0; 320 480); autoresize = W+H; gestureRecognizers = <NSArray: 0x8f34860>; layer = <UIWindowLayer: 0x8f34780>>
2014-07-24 14:05:09.894 test[18888:60b] viewWillDisappear: window: <UIWindow: 0x8f40320; frame = (0 0; 320 480); autoresize = W+H; gestureRecognizers = <NSArray: 0x8f34860>; layer = <UIWindowLayer: 0x8f34780>>
2014-07-24 14:05:10.399 test[18888:60b] viewDidDisappear: window: (null)
@ekurutepe
ekurutepe / gist:1116107
Created July 30, 2011 22:46
Ingredients 1.1b1 Crash on Lion
Process: Ingredients [8187]
Path: /Applications/Ingredients.app/Contents/MacOS/Ingredients
Identifier: net.fileability.ingredients
Version: 1.1b1 (1.0)
Code Type: X86-64 (Native)
Parent Process: launchd [207]
Date/Time: 2011-07-31 00:44:54.349 +0200
OS Version: Mac OS X 10.7 (11A511)
Report Version: 9