Skip to content

Instantly share code, notes, and snippets.

View yneear's full-sized avatar
🏠
Working from home

yneear yneear

🏠
Working from home
View GitHub Profile
@yneear
yneear / GoogleSignin.vue
Last active September 13, 2023 10:44
Custom Google Sign-in Button Component for Nuxt 3
<template>
<div @click.self="promptGoogleLogin">
<span>Sign-in with Google</span>
<div style="opacity: 0;height: 0;" ref="invisibleSigninBtn"></div>
</div>
</template>
<script lang="ts" setup>
// pnpm add -D @types/google.accounts
/// <reference types='google.accounts' />
@yneear
yneear / PageViewContainer.swift
Last active February 4, 2023 09:31
The PageViewController that has a tab with animation line bar. (SwiftUI interfacing with UIKit)
import SwiftUI
struct TabGeoData: Identifiable {
let idx: Int
let geoData: GeoData
var id: Int { idx }
}
struct GeoData: Equatable {
@yneear
yneear / View+isEmpty.swift
Created January 25, 2023 03:02
SwiftUI View replace EmptyView with defaultView extension
extension View {
@ViewBuilder func isEmpty (
@ViewBuilder defaultView: () -> some View
) -> some View {
if self is EmptyView {
defaultView()
} else {
self
}
}
@yneear
yneear / NSAttributedString+attributedStringWithResizedImages.swift
Created January 19, 2023 05:59
NSAttributedString with resized images
extension NSAttributedString {
func attributedStringWithResizedImages(with maxWidth: CGFloat) -> NSAttributedString {
let text = NSMutableAttributedString(attributedString: self)
text.enumerateAttribute(
.attachment,
in: NSMakeRange(0, text.length),
using: { (value, range, _) in
if let attachement = value as? NSTextAttachment {
let image = attachement.image(
forBounds: attachement.bounds,