Skip to content

Instantly share code, notes, and snippets.

View ohtwo's full-sized avatar
🌙
° ☾ ☆ ¸. ¸ ★ :.  . • ○ ° ★

Kang Byeonghak ohtwo

🌙
° ☾ ☆ ¸. ¸ ★ :.  . • ○ ° ★
View GitHub Profile
@brennanMKE
brennanMKE / BytesPlayground.swift
Last active December 16, 2023 18:30
Copy bytes from Data with Swift
import Foundation
let size = MemoryLayout<Int16>.stride
let data = Data(bytes: [1, 0, 2, 0, 3, 0]) // little endian for 16-bit values
let int16s = data.withUnsafeBytes { (bytes: UnsafePointer<Int16>) in
Array(UnsafeBufferPointer(start: bytes, count: data.count / size))
}
let length = data.count * MemoryLayout<Int16>.stride
import Foundation
// Inspired by https://gist.github.com/mbuchetics/c9bc6c22033014aa0c550d3b4324411a
struct JSONCodingKeys: CodingKey {
var stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
}
@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.

@reckenrode
reckenrode / codeableEnum.swift
Created June 23, 2017 19:49
Implement Codable on an enum
struct User: Codable {
var name: String
var email: String
var id: String
var metadata: [String: MetadataType]
enum CodingKeys: String, CodingKey {
case name, email, id, metadata
}
}
@alexmx
alexmx / table-view-fill-footer.m
Created April 7, 2017 13:30
Adjust UITableView footer view to fill the whole remaining part of the screen.
@DmitryBespalov
DmitryBespalov / EmbedFrameworksScript.sh
Last active June 11, 2021 21:10
Embed frameworks script
#!/bin/sh
set -e
# set your Frameworks path here
FRAMEWORKS_DIR="${SRCROOT}/../Frameworks/${PLATFORM_NAME}"
echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
@AGmakonts
AGmakonts / README.md
Last active February 5, 2022 18:42
Automatic GitHub release notes and built package from Circle CI

Automatic GitHub release notes and built package from Circle CI

This config uses github-release and github-release-notes to automatically update release with required artifacts and compose release notes based on commit messages. Follow documentation of thos etwo packages to configure it to your needs.

exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
@jooyunghan
jooyunghan / monad-in-java.md
Last active November 17, 2023 04:54
한글번역 - Functor and monad examples in plain Java

Functor and monad examples in plain Java

이 글은 우리가 쓴 책, 'Reactive Programming with RxJava' 의 부록이었다. Reactive programming과 관련이 깊은 주제긴 하지만 모나드를 소개한다는 게 책과 썩 어울리지는 않았다. 그래서 나는 따로 블로그에 올리기로 했다. 프로그래밍을 다루는 블로그에서 *"반은 맞고 반은 틀릴 지 모르는 나만의 모나드 설명"*이란 것이 새로운 *"Hello World"*라는 점을 나도 잘 안다. 하지만 이 글은 펑터(functor)와 모나드(monad)를 자바 자료 구조와 라이브러리라는 각도에서 바라보고 있으며, 이는 공유할 정도의 가치는 있을거라 생각했다.

func ==<U: Equatable, T: protocol<RawRepresentable, Equatable> where T.RawValue == U>(lhs: U, rhs: T) -> Bool {
return lhs == rhs.rawValue
}
func !=<U: Equatable, T: protocol<RawRepresentable, Equatable> where T.RawValue == U>(lhs: U, rhs: T) -> Bool {
return lhs != rhs.rawValue
}