Skip to content

Instantly share code, notes, and snippets.

View el-hoshino's full-sized avatar
🏠
Working from home

Elvis Shi el-hoshino

🏠
Working from home
View GitHub Profile
@el-hoshino
el-hoshino / AssociativeComparisonPrecedence.swift
Last active February 5, 2024 22:40
AssociativeComparison
precedencegroup AssociativeComparisonPrecedence {
associativity: left
higherThan: ComparisonPrecedence
lowerThan: NilCoalescingPrecedence
}
infix operator <: AssociativeComparisonPrecedence
infix operator <=: AssociativeComparisonPrecedence
public func < <V: Comparable>(lhs: V, rhs: V) -> (Bool, V) {
@el-hoshino
el-hoshino / Collection+.swift
Created December 8, 2023 13:21
Collection Interpolation in Swift
extension Collection {
func interpolated(by interpolation: (_ previous: Element, _ current: Element) throws -> Element) rethrows -> [Element] {
var iterator = makeIterator()
var result = [Element]()
guard var previous = iterator.next() else {
return []
}
@el-hoshino
el-hoshino / csv_converter_from_race_chrono_pro_to_telemetry_overlay.py
Last active September 1, 2023 22:10
A converting python script that converts a CSV file produced from RaceChrono Pro format to general Telemetry Overlay format. Created with ChatGPT: https://chat.openai.com/share/7c8e8f2c-60ee-4024-86cd-bc82a3b3c06c
import pandas as pd
import argparse
def process_file(input_file_path, output_file_path):
# Read the file line by line until we find the header row starting with 'timestamp'
with open(input_file_path, 'r') as file:
lines = file.readlines()
# Get the line number where 'timestamp' is found
@el-hoshino
el-hoshino / Badge.swift
Created April 5, 2020 15:40
A weird behavior in SwiftUI when using a GeometryReader in a ZStack
import SwiftUI
struct Badge<V: View>: ViewModifier {
let badge: V
func body(content: Content) -> some View {
ZStack {
content
GeometryReader { [self] geometry in
#!/bin/bash
set -e
echo " => Creating a temporary directory for codesigndoc ..."
temp_dir="$(mktemp -d -t codesigndocXXXXXX)"
codesigndoc_bin_path="${temp_dir}/codesigndoc"
version_to_use="2.3.1"
if [ "$1" != "" ] ; then
version_to_use="$1"
@el-hoshino
el-hoshino / CodePiece.swift
Created September 7, 2019 03:01
まじだ! #CodePiece #iosdc #b
let a: Int = 1
let b: Double = 1
let aa: AnyHashable = a
let ab: AnyHashable = b
aa == ab // true
@el-hoshino
el-hoshino / CodePiece.swift
Created July 3, 2019 08:37
Xcode 11.0 beta 3の画面SceneDelegate地味に変わってる👀beta 2まではwindow = UIWindow(frame:) だったけど、これからはwindow = UIWindow(windowScene:)に #CodePiece
// Xcode 11.0 beta 2 まで
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
// Use a UIHostingController as window root view controller
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIHostingController(rootView: ContentView(model: model))
self.window = window
@el-hoshino
el-hoshino / CodePiece.swift
Created July 2, 2019 11:57
Viewにassign(_, to:)メソッド作ってみた #swiftui #CodePiece
import UIKit
import SwiftUI
import Combine
protocol UsecaseProtocol: AnyObject {
var intPublisher: AnyPublisher<Int, Never> { get }
func reset()
}
struct ContentView : View {
@el-hoshino
el-hoshino / CodePiece.swift
Created March 27, 2018 09:08 — forked from takasek/CodePiece.swift
ポプテピピックが完成したら竹書房を破壊するSwiftコード #CodePiece
enum PopTeamEpic: String {
case po = "ポ"
case p = "プ"
case teame = "テピ"
case pic = "ピック"
}
struct 蒼井翔太: Sequence, IteratorProtocol {
mutating func next() -> PopTeamEpic? {
switch arc4random_uniform(4) {
case 0: return .po
@el-hoshino
el-hoshino / Lazy.swift
Created March 5, 2018 07:45
Declaring a lazy-initialized object with `let` in Swift
class Lazy <T> {
private var t: T?
private let initializer: () -> T
private let semaphore = DispatchSemaphore(value: 1)
init(_ initializer: @escaping () -> T) {
self.initializer = initializer