Skip to content

Instantly share code, notes, and snippets.

@kevin-smets
kevin-smets / iterm2-solarized.md
Last active April 24, 2025 23:53
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

Github Two-Factor Authentication (2FA) for Brazil via SMS

The Github doesn't provide country code for Brazil (+55). To add this option, just run the code below in your console. The option Brazil +55 will be the first on the list, already selected:


🇧🇷 [pt-BR]

Autenticação em dois fatores (2FA) do GitHub para o Brasil via SMS

@juliensagot
juliensagot / UIImage+averageColor.swift
Last active November 16, 2024 19:18
Get the average color of a UIImage. (Swift 4.2, Xcode 10.0)
import UIKit
extension UIImage {
var averageColor: UIColor? {
guard let inputImage = self.ciImage ?? CIImage(image: self) else { return nil }
guard let filter = CIFilter(name: "CIAreaAverage", parameters: [kCIInputImageKey: inputImage, kCIInputExtentKey: CIVector(extent: inputImage.extent)])
else { return nil }
guard let outputImage = filter.outputImage else { return nil }
@juliensagot
juliensagot / SwiftUI_subpixel_issue.swift
Last active November 16, 2024 19:18
SwiftUI subpixel alignment stroke animation issue
import SwiftUI
struct TestCard: View {
private let cornerRadius: CGFloat = 12
@Environment(\.displayScale) private var displayScale
@State private var isSelected = false
var body: some View {
@tkashkin
tkashkin / PullToRefreshView.swift
Last active March 26, 2023 14:43
SwiftUI Pull to refresh view
import SwiftUI
struct PullToRefreshView: View
{
private static let minRefreshTimeInterval = TimeInterval(0.2)
private static let triggerHeight = CGFloat(100)
private static let indicatorHeight = CGFloat(100)
private static let fullHeight = triggerHeight + indicatorHeight
let backgroundColor: Color
import Foundation
import SwiftUI
// MARK: - Custom Button Style
struct MobileMeButtonStyle: ButtonStyle {
// MARK: Metrics
@ScaledMetric private var cornerRadius = 12
@ScaledMetric private var horizontalLabelPadding = 12
@ScaledMetric private var verticalLabelPadding = 8
@juliensagot
juliensagot / ValuePicker.swift
Last active April 12, 2025 23:57
Custom SwiftUI Picker
import SwiftUI
public struct ValuePicker<SelectionValue: Hashable, Content: View>: View {
private let title: LocalizedStringKey
private let selection: Binding<SelectionValue>
private let content: Content
public init(
_ title: LocalizedStringKey,
selection: Binding<SelectionValue>,
@juliensagot
juliensagot / VariableBlurView.swift
Last active April 15, 2025 21:17
SwiftUI variable blur view
import Foundation
import SwiftUI
import UIKit
extension UIBlurEffect {
public static func variableBlurEffect(radius: Double, imageMask: UIImage) -> UIBlurEffect? {
let methodType = (@convention(c) (AnyClass, Selector, Double, UIImage) -> UIBlurEffect).self
let selectorName = ["imageMask:", "effectWithVariableBlurRadius:"].reversed().joined()
let selector = NSSelectorFromString(selectorName)
@juliensagot
juliensagot / ResponsiveButtonStyle.swift
Last active November 22, 2024 13:04
Custom ButtonStyle boilerplate that doesn't take ages to update its `isPressed` state when using spring animations
struct ResponsiveButtonStyle: PrimitiveButtonStyle {
// Use this instead of `Configuration.isPressed`.
@State private var isPressed = false
func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(isPressed ? 0.9 : 1)
.animation(.spring, value: isPressed)
._onButtonGesture { isPressed in
self.isPressed = isPressed
@juliensagot
juliensagot / CustomButtonStyle.swift
Created October 10, 2024 17:37
SwiftUI custom ButtonStyle example
import SwiftUI
struct CapsuleButtonStyle: ButtonStyle {
enum Appearance {
case plain
case outlined
}
let appearance: Appearance