Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠

monotone mntone

🏠
View GitHub Profile
@mntone
mntone / test.swift
Last active Dec 27, 2021
Copyright (C) 2021 mntone. All right reserved. This source code is under MIT license.
View test.swift
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
func coloredPrimaryColor(localized: String.LocalizationValue) -> AttributedString {
var attributedString: AttributedString = AttributedString(localized: localized)
guard let firstBoldRange = attributedString.range(of: "**") else { return attributedString }
let orig: AttributedString = attributedString
attributedString.removeSubrange(firstBoldRange)
guard let nextBoldRange = attributedString.range(of: "**") else { return orig }
attributedString.removeSubrange(nextBoldRange)
@mntone
mntone / EmphasizableToken.swift
Last active Dec 27, 2021
Copyright (C) 2021 mntone. All right reserved. This source code is under MIT license.
View EmphasizableToken.swift
import Foundation
enum EmphasizableToken {
case plain(String)
case toggleEmphasize
}
@mntone
mntone / BorderedProminentButtonModifier.swift
Last active Dec 12, 2021
Copyright (C) 2021 mntone. All right reserived. This source code is under MIT license.
View BorderedProminentButtonModifier.swift
import SwiftUI
struct BorderedProminentButtonModifier: ViewModifier {
@Environment(\.deviceMetrics)
private var deviceMetrics: WatchDeviceMetrics
func body(content: Content) -> some View {
if #available(watchOS 8.0, *) {
content.tint(.accentColor)
.buttonStyle(.borderedProminent)
@mntone
mntone / PinCodeFactory.swift
Last active Dec 1, 2020
何かの残骸。正しく動作しません。ただ,クラス実装は何かに流用できる可能性があります。🌟under MIT license
View PinCodeFactory.swift
import CommonCrypto
import CryptoKit
import Foundation
protocol PinCodeFactory {
mutating func update(by timeStep: Int32)
mutating func update(by timeStep: Int32, at baseTime: Int32)
mutating func update(using counter: Int64)
mutating func getPincode(to digits: Int) -> Int32
@mntone
mntone / uint16x8_t.hpp
Last active Dec 26, 2019
ゴリ押しやった記念。もっといい書き方あったので本番コードはそれを採用。でもこれだけ並んでるのも楽しいよね。 // MIT License
View uint16x8_t.hpp
typedef __m128i uint16x8_t;
template<> inline uint16x8_t uint16x8_swizzle<0, 1, 2, 3, 4, 5, 6, 7>(uint16x8_t a) { return a; }
static inline uint16x8_t _mm_alignr_epi8_sse2(uint16x8_t a, uint16x8_t b, int align) {
return _mm_or_si128(_mm_slli_si128(a, 16 - 2 * align), _mm_srli_si128(b, 2 * align));
}
#if defined(_SIMD_X86_SSSE3)
template<> inline uint16x8_t uint16x8_swizzle<7, 0, 1, 2, 3, 4, 5, 6>(uint16x8_t a) { return _mm_alignr_epi8(a, a, 2); }
@mntone
mntone / uint16x4_t.h
Created Dec 25, 2019
MMXで64-bit処理のためのuint16x4_t作ろうとしたけど命令数足りなさすぎて実用的じゃないので,SSE 128-bit最小単位にするように設計変更。ご自由にどうぞ。 >> under MIT License <<
View uint16x4_t.h
#ifndef _SIMD_UINT16X4_H
#define _SIMD_UINT16X4_H
#include "simd_base.h"
#ifdef __cplusplus
extern "C" {
#endif
// ---
@mntone
mntone / Array+Median.swift
Created Sep 18, 2019
Array+Median.swift under MIT license
View Array+Median.swift
// Copyright (C) 2019 mntone. All rights reserved.
// MIT license
extension Array where Array.Element: Numeric & Comparable {
@inlinable
public func medianFast() -> Element {
return sorted(by: <)[count / 2]
}
}
View OldPOColor.swift
import struct PostoneCore.Settings
#if os(macOS)
import AppKit
public typealias POColor = NSColor
#else
import UIKit
public typealias POColor = UIColor
#endif
View PageViewControllerSegmentedAdapter.swift
import UIKit
final class PageViewControllerSegmentedAdapter: NSObject {
private unowned let pageViewController: UIPageViewController
private unowned let segmentControl: UISegmentedControl
private let viewControllers: [UIViewController]
private var selectedIndex: Int
init(pageViewController: UIPageViewController, segmentControl: UISegmentedControl, viewControllers: [UIViewController], at selectedIndex: Int = 0) {
@mntone
mntone / UIFont+Traits.swift
Created Aug 15, 2019
Apply font style (bold / italic) & features (monospaced digit).
View UIFont+Traits.swift
import CoreText
import class UIKit.UIFont
import class UIKit.UIFontDescriptor
extension UIFont {
public func asBold() -> UIFont? {
return asTraits(.traitBold)
}
public func asItaric() -> UIFont? {