Skip to content

Instantly share code, notes, and snippets.

View 2no's full-sized avatar
🤗

Kazunori Ninomiya 2no

🤗
View GitHub Profile
@morgyface
morgyface / add_the_categories.php
Created November 25, 2020 17:21
WordPress | Add categories programmatically on theme activation
<?php
// Sets the default categories
function add_the_categories() {
$categories = array(
'Case Study',
'Blog',
'Article'
);
foreach( $categories as $category ) {
$exists = term_exists( $category, 'category' );
@mecid
mecid / Calendar.swift
Last active May 5, 2024 08:43
SwiftUI Calendar view using LazyVGrid
import SwiftUI
extension Calendar {
func generateDates(
inside interval: DateInterval,
matching components: DateComponents
) -> [Date] {
var dates: [Date] = []
dates.append(interval.start)
@rizumita
rizumita / CodePiece.swift
Created February 8, 2020 23:40
Swiftにasync/awaitが無いのでCombineでなんちゃってasync/awaitを書いた。Swift5.2のcallAsFunctionを使うことでyieldが書きやすくなった。 #CodePiece
import Foundation
import Combine
public func async<T>(_ body: @escaping (Yield<T>) throws -> ()) -> Async<T> {
Async(body: body)
}
public func await<P>(_ publisher: P) throws -> P.Output where P: Publisher {
try publisher.await()
}
@T1T4N
T1T4N / CaseEquatable.swift
Created September 23, 2019 15:01
Enums with Associated Values: Protocol & example implementation of matching without taking the associated value into account
protocol CaseEquatable {
associatedtype Case: Equatable
var `case`: Case { get }
static func ~=(lhs: Self, rhs: Self) -> Bool
}
extension CaseEquatable {
static func ~=(lhs: Self, rhs: Self) -> Bool {
return lhs.case == rhs.case
@ytyubox
ytyubox / README.md
Last active December 21, 2021 08:31
UIControlSubscription.swift
@lisawolderiksen
lisawolderiksen / git-commit-template.md
Last active April 22, 2024 13:01
Use a Git commit message template to write better commit messages

Using Git Commit Message Templates to Write Better Commit Messages

The always enthusiastic and knowledgeable mr. @jasaltvik shared with our team an article on writing (good) Git commit messages: How to Write a Git Commit Message. This excellent article explains why good Git commit messages are important, and explains what constitutes a good commit message. I wholeheartedly agree with what @cbeams writes in his article. (Have you read it yet? If not, go read it now. I'll wait.) It's sensible stuff. So I decided to start following the

@darrarski
darrarski / CodableDecimalSpec.swift
Last active November 26, 2021 14:23
Swift Codable, Decimal <~> String encoding
import Quick
import Nimble
class CodableDecimalSpec: QuickSpec {
override func spec() {
context("encode Model to JSON") {
var model: Model!
var json: [String: String]?
beforeEach {
@calosth
calosth / UIView+Intersection.swift
Last active September 8, 2022 22:59
Extension of UIView to detect collisions between them, including rotated(transformed) views.
import UIKit
// Conform the `Polygon` protocol to specify the vertices of the polygon.
protocol Polygon {
var vertices: [CGPoint] { get }
}
// UIView conforms the protocol `Polygon` to specified the vertices of the rectangle.
extension UIView: Polygon {
import UIKit
import WebKit
// Disableing `WKWebView` user zooming by returning `nil` in `UIScrollViewDelegate`'s
// `viewForZooming` delegate method.
// On iOS 12, the delegate method only called when set the web view itself as the
// scroll view delegate.
class WebView: WKWebView {}
@keitaoouchi
keitaoouchi / KeyboardManager.swift
Last active December 2, 2020 02:38
まぁまぁ再利用しがちなキーボードマネージャー
import UIKit
/// キーボードイベントを監視し、キーボードの開閉に合わせてviewをtransformで上下移動させる
final class KeyboardManager {
private var view: UIView
/// キーボード開閉時に可能なら表示されるように画面スライド位置が調整されるビュー
/// 縦長フォームの一番下にあるサブミットボタンみたいなやつを想定
private var subFocusView: UIView?