Skip to content

Instantly share code, notes, and snippets.

View gatherheart's full-sized avatar
🤗
Always Gather Heart

Milkybean gatherheart

🤗
Always Gather Heart
View GitHub Profile
@emiller
emiller / git-mv-with-history
Last active April 17, 2024 21:06
git utility to move/rename file or folder and retain history with it.
#!/bin/bash
#
# git-mv-with-history -- move/rename file or folder, with history.
#
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
#
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.
@miguelmota
miguelmota / nodejs-directory-structure.md
Last active December 2, 2023 08:47
Node.js MVC directory structure example.
Node.js MVC directory structure example.
├── app
│   ├── controllers
│   │   ├── admin
│   │   │   ├── posts.js
│   │   │   └── users.js
│   │   ├── posts.js
│ │ ├── session.js
@bnickel
bnickel / RestorationDefender.swift
Last active January 12, 2023 09:47
A few friendly methods to help you detect state restoration problems in your non-storyboard apps.
// USAGE:
// Call RestorationDefender.printViewControllerClassesThatAreProbablyNotRestorable() to print a list of view controllers that will probably not return from state restoration.
// Call RestorationDefender.crashWhenViewControllersDoNotImplementStateRestoration() to crash your app when a view controller appears without setting restorationIdentifier and restorationClass.
// Call RestorationDefender.shoutWhenViewControllersDoNotImplementStateRestoration() to print a big message when a view controller appears without setting restorationIdentifier and restorationClass.
import Foundation
private func objc_getClassList() -> [AnyClass] {
let expectedClassCount = objc_getClassList(nil, 0)
var allClasses = UnsafeMutablePointer<AnyClass?>.alloc(Int(expectedClassCount))
@misbell
misbell / gist:fa7ecd562a9b0d9c1237eed5e1a6d89e
Created October 16, 2016 01:43
example Swift 3 withMemoryRebound
so A and B are structurally identical
C reverses the order of the 8 and 32 bit Ints
and D substitutes a string for the Int8
then I try to read aaaa’s bits using B C and D overlays 😊
C is printing the 8 bits of the A integer j and then the first 8 bits of integer k but somehow that still works out to one
when I hit D it doesn’t find a string so prints a blank
but the important point is: it doesn’t check anything, and doesn’t crash
@dduan
dduan / runCommand.swift
Last active May 5, 2024 12:55
How to fork()+execv() in Swift
import Foundation
func withCStrings(_ strings: [String], scoped: ([UnsafeMutablePointer<CChar>?]) throws -> Void) rethrows {
let cStrings = strings.map { strdup($0) }
try scoped(cStrings + [nil])
cStrings.forEach { free($0) }
}
enum RunCommandError: Error {
case WaitPIDError
@godrm
godrm / swift_api_guideline.md
Last active July 15, 2024 13:21
스위프트 API 가이드라인

1. 스타일/문법 리뷰

1-1 스위프트 API 디자인 가이드라인

https://swift.org/documentation/api-design-guidelines/

  • 사용할 때 기준으로 명확하게 작성하는 게 가장 중요한 지향점이다. 메소드나 프로퍼티 같은 개발 요소는 한 번만 선언하고 반복적으로 사용한다. API를 만들 때는 사용하기 명확하고 편하게 만들어야 한다. 설계를 검증할 때 선언 부분을 읽는 것만으로는 부족하다. 그 대신 사용하는 상황에서 맥락에 맞고 명확한 지 늘 고려해야 한다.

  • 명확한 표현이 압축한 간결성보다 더 중요하다. 스위프트 코드는 압축해서 간결하게 작성할 수 있지만, 단지 글자수를 줄여서 가장 짧은 코드를 만드는 게 목표는 아니다. 스위프트 코드의 간결성은 자연스럽게 반복적으로 재사용하는 코드(boilerplate)를 줄이는 기능과 강한 타입 시스템의 부수효과로 드러날 뿐이다.

@cjnevin
cjnevin / UIView+Accessibility.swift
Last active June 6, 2022 08:31
Automatically add Accessibility Labels/Identifiers to all components that extend UIView
import UIKit
private func isExcluded(_ kind: AnyClass) -> Bool {
let name = String(describing: kind)
return (name.count > 2 && name.prefix(2) == "UI") ||
(name.count > 3 && name.prefix(3) == "_UI")
}
extension UIControl {
override open var accessibilityIdentifier: String? {
import Foundation
class ReadValue {
var successClosure : ((String)->())? = nil
var value : String = "" {
didSet {
if let closure = successClosure {
closure(value)
}
}
}
class ReadValue {
private var thread : Thread? = nil
init(with handler: @escaping (String) -> ()) {
thread = Thread(block: {
while(true) {
let value = readLine() ?? ""
handler(value)
}
})
thread?.start()
@loganpowell
loganpowell / graphql-args-passing.md
Last active June 8, 2023 17:51
GraphQL Passing Arguments (parent, args, context, info)