Skip to content

Instantly share code, notes, and snippets.

View WorldDownTown's full-sized avatar
🍺
working with beers

Keisuke Shoji WorldDownTown

🍺
working with beers
  • Tokyo, Japan
View GitHub Profile
@WorldDownTown
WorldDownTown / swift-format.yml
Last active June 28, 2024 02:01
Pull Request の差分に対して swift-format でフォーマットして commit & push する GitHub Actions の設定
# Pull Request の差分に対して swift-format でフォーマットして commit & push
name: swift-format
on:
pull_request:
branches:
- main
paths:
- "**/*.swift"
extension Sequence where Iterator.Element: Hashable {
var unique: [Iterator.Element] {
var checked: Set<Iterator.Element> = []
return filter { checked.insert($0).inserted }
}
}
extension Sequence where Iterator.Element: Equatable {
var unique: [Iterator.Element] {
reduce([]) { $0.contains($1) ? $0 : $0 + [$1] }
@WorldDownTown
WorldDownTown / say_with_volume.sh
Last active May 7, 2020 09:43
volume-configured say command
#!/bin/sh
# ~/say_with_volume.sh "hello world" # default volume is 20
# ~/say_with_volume.sh "hello world" 30
volume=`osascript -e "output volume of (get volume settings)"`
default_volume=20
say_volume=$2
if [ $volume = "0" ]; then
#!/bin/sh
/opt/cisco/anyconnect/bin/vpn disconnect
#!/bin/sh
# setting
COMMAND=/opt/cisco/anyconnect/bin/vpn
GROUP=''
USER=''
SERVICE='Cisco AnyConnect'
PASS=`security find-generic-password -a "${USER}" -s "${SERVICE}" -w`
PASS2=''
HOST=''
@WorldDownTown
WorldDownTown / ContrastRatio.swift
Last active December 28, 2023 06:01
Get contrast ratio between two UIColors
// https://www.w3.org/TR/WCAG20/
// Contrast ratio
// Relative luminance
import UIKit
extension UIColor {
convenience init(hex: UInt, alpha: CGFloat = 1) {
self.init(red: CGFloat((hex & 0xff0000) >> 16) / 255,
green: CGFloat((hex & 0x00ff00) >> 8) / 255,
@WorldDownTown
WorldDownTown / RippleCheckmark.swift
Last active February 24, 2020 13:17
Checkmark with ripple animation
import PlaygroundSupport
import UIKit
final class RippleCheckmark: UIView {
private let circleLayer: CAShapeLayer = .init()
private let rippleLayer: CAShapeLayer = .init()
private let checkmarkLayer: CAShapeLayer = .init()
private var completion: (() -> Void)?
var fillColor: UIColor = .blue {
didSet { update() }
@WorldDownTown
WorldDownTown / GoogleLoadingIndicator.swift
Last active February 24, 2020 13:19
Loading indicator like Google's Application
import PlaygroundSupport
import UIKit
final class GoogleLoadingIndicator: UIView {
var colors: [UIColor] = []
private var index: Int = 0
private let totalDuration: TimeInterval = 2
private let movingAngle: CGFloat = 5 / 6 * .pi2
private let rotationCount: Int = 6
private let minimumAngle: CGFloat = .pi2 / 24
@WorldDownTown
WorldDownTown / LoadingIndicator.swift
Last active February 24, 2020 13:08
Loading circle indicator
import PlaygroundSupport
import UIKit
final class LoadingIndicator: UIView {
var color: UIColor = .blue
private var index: Int = 0
private let lap: TimeInterval = 2
private let movingAngle: CGFloat = 5 / 6 * .pi2
private let rotationCount: Int = 6
private let minimumAngle: CGFloat = .pi2 / 24
@WorldDownTown
WorldDownTown / TimerIndicator.swift
Last active January 31, 2020 07:10
Timer Indicator
import UIKit
import PlaygroundSupport
import UIKit
final class TimerIndicator: UIView {
deinit {
displayLink?.invalidate()
}