Skip to content

Instantly share code, notes, and snippets.

@emin-grbo
emin-grbo / decodeOrReport.swift
Created February 13, 2024 10:39
DecodeOrReport
// Used to detect specific issue with JSON decoding
func decodeOrReport(data: Data) {
do {
let _ = try JSONDecoder().decode(WidgetResponse.self, from: data)
print("\n\n👍ALL GOOD\n\n")
} catch DecodingError.keyNotFound( let key, let context) {
print("\n\n⛔️FAILED TO DECODE\n\n")
print("could not find key \(key) in JSON: \(context.debugDescription)")
} catch DecodingError.valueNotFound( let type, let context) {
print("\n\n⛔️FAILED TO DECODE\n\n")
@dkun7944
dkun7944 / CDView.swift
Last active January 14, 2024 23:45
SwiftUI + Swift.Shader CD
//
// CDView.swift
// CD
//
// Created by Daniel Kuntz on 7/3/23.
//
import SwiftUI
struct ShapeWithHole: Shape {
@kepano
kepano / obsidian-web-clipper.js
Last active May 7, 2024 17:33
Obsidian Web Clipper Bookmarklet to save articles and pages from the web (for Safari, Chrome, Firefox, and mobile browsers)
javascript: Promise.all([import('https://unpkg.com/turndown@6.0.0?module'), import('https://unpkg.com/@tehshrike/readability@0.2.0'), ]).then(async ([{
default: Turndown
}, {
default: Readability
}]) => {
/* Optional vault name */
const vault = "";
/* Optional folder name such as "Clippings/" */
@SpectralDragon
SpectralDragon / PreviewContextMenu.swift
Created April 8, 2020 19:22
Simple way to implement preview context menu for SwiftUI
//
// ContentView.swift
// PreviewSwiftUI
//
// Created by v.prusakov on 4/8/20.
// Copyright © 2020 v.prusakov. All rights reserved.
//
import SwiftUI
//
// BottomSheetView.swift
//
// Created by Majid Jabrayilov
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
fileprivate enum Constants {
static let radius: CGFloat = 16
@mshafer
mshafer / ContentView.swift
Last active May 3, 2023 13:37
Slide-over card (like in Maps or Stocks) using SwiftUI
import SwiftUI
struct ContentView : View {
var body: some View {
ZStack(alignment: Alignment.top) {
MapView()
SlideOverCard {
VStack {
CoverImage(imageName: "maitlandbay")
Text("Maitland Bay")
@JosephDuffy
JosephDuffy / ExampleViewController.swift
Last active November 30, 2022 18:28
Animates changing the brightness of a `UIScreen`
import UIKit
final class ExampleViewController: UViewController {
private var usersBrightness = UIScreen.main.brightness
private var willEnterForegroundWasCalled = false
private var viewWillDisappearWasCalled = false
override func viewDidLoad() {
@andreyvit
andreyvit / UIPickerView_SelectionBarLabelSupport.h
Created October 23, 2009 01:08
UIPickerView category that allows to easily recreate the look and feel of UIDatePicker labeled components (HIG calls them “translucent bar labels”)
// UIPickerView_SelectionBarLabelSupport.h
//
// This file adds a new API to UIPickerView that allows to easily recreate
// the look and feel of UIDatePicker labeled components.
//
// Copyright (c) 2009, Andrey Tarantsov <andreyvit@gmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.