Skip to content

Instantly share code, notes, and snippets.

View nkmrh's full-sized avatar
🐧

Hajime Nakamura nkmrh

🐧
View GitHub Profile
@EnesKaraosman
EnesKaraosman / RandomColor.swift
Last active May 9, 2024 22:41
Generatin random color in SwiftUI & UIKit
#if canImport(UIKit)
import UIKit
extension UIColor {
static var random: UIColor {
return UIColor(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1)
)
@PaulWoodIII
PaulWoodIII / CurrentValueSubjectToBinding.swift
Last active January 9, 2024 01:20
Bindings over a CurrentValue subject allow you to use combine for side affects
//: [Previous](@previous)
import Foundation
import SwiftUI
import Combine
//: Current Value Subject is a value, a publisher and a subscriber all in one
let currentValueSubject = CurrentValueSubject<Bool, Never>(true)
print(currentValueSubject.value)
@lattner
lattner / async_swift_proposal.md
Last active April 21, 2024 09:43 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@RuiNelson
RuiNelson / Levenshtein.swift
Last active August 2, 2023 03:50
Levenshtein distance between two String for Swift 4.x
import Foundation
extension String {
subscript(index: Int) -> Character {
return self[self.index(self.startIndex, offsetBy: index)]
}
}
extension String {
public func levenshtein(_ other: String) -> Int {
@freak4pc
freak4pc / MKMultiPoint+Ext.swift
Last active April 25, 2024 04:38
Get a list of coordinates from a MKPolyline / MKRoute
public extension MKMultiPoint {
var coordinates: [CLLocationCoordinate2D] {
var coords = [CLLocationCoordinate2D](repeating: kCLLocationCoordinate2DInvalid,
count: pointCount)
getCoordinates(&coords, range: NSRange(location: 0, length: pointCount))
return coords
}
}
@nacyot
nacyot / LookUp.APPLESCRIPT
Last active March 2, 2022 15:10
OSX Dictionary Lookup History Service
on run {input, parameters}
set logPath to "Dropbox/Dictionary/words.txt"
set lookUpWord to quoted form of (input as string)
tell application "System Events" to tell (process 1 where frontmost is true)
set windowTitle to name
try
set windowTitle to windowTitle
set titleBar to name of window 1
end try
@josephg
josephg / 0dedict.py
Last active April 28, 2024 14:07
Apple dictionaries
# Thanks to commenters for providing the base of this much nicer implementation!
# Save and run with $ python 0dedict.py
# You may need to hunt down the dictionary files yourself and change the awful path string below.
# This works for me on MacOS 10.14 Mohave
from struct import unpack
from zlib import decompress
import re
filename = '/System/Library/Assets/com_apple_MobileAsset_DictionaryServices_dictionaryOSX/9f5862030e8f00af171924ebbc23ebfd6e91af78.asset/AssetData/Oxford Dictionary of English.dictionary/Contents/Resources/Body.data'
f = open(filename, 'rb')
@JaviLorbada
JaviLorbada / FRP iOS Learning resources.md
Last active May 29, 2024 07:33
The best FRP iOS resources.

Videos

@saiday
saiday / gist:7394795
Created November 10, 2013 06:58
UITabBarController disable Title, Image align center
.h
@interface TabViewController : UITabBarController
.m
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
@miminashi
miminashi / gist:5217195
Last active December 15, 2015 06:29
Storyboardでmerge conflictが発生した場合の対処方法

うまくいったのがあったら追記していきます。

inferredMetricsTieBreakersの中でconflictしていた場合

storyboardの末尾のほうにある以下の様な部分のお話ですね。

<inferredMetricsTieBreakers>
    <segue reference="YUa-1a-iG8"/>
    <segue reference="nKl-EP-JoK"/>