Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠

monotone mntone

🏠
View GitHub Profile
@mntone
mntone / clock.lua
Last active Jul 1, 2022
Sets a text source to act as a clock when the source is active. The format matches `strftime`. Use only in OBS Studio 21.0 and later!
View clock.lua
obs = obslua
source_name = ""
tick = 1000
last_text = ""
format = ""
activated = false
local s_unit = 1000 * 1000 * 1000 -- [ns]
@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 / 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 / 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 / int24_t.hpp
Created Jun 24, 2015
int24_t for C++
View int24_t.hpp
#pragma once
#pragma pack(push, 1)
using int24_t = struct _int24_t
{
int32_t data : 24;
_int24_t(int8_t integer)
: data(integer)
{ }
_int24_t(uint8_t integer)
@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