Skip to content

Instantly share code, notes, and snippets.

View chriswilson1982's full-sized avatar

Chris Wilson chriswilson1982

View GitHub Profile
@davidsteppenbeck
davidsteppenbeck / Optional+Utilities.swift
Last active July 27, 2021 07:08
An infix operator for collections that returns the wrapped value of the optional only if the collection is not empty.
import Foundation
infix operator ???
extension Optional where Wrapped: Collection {
/// Performs a nil-coalescing operation, returning the wrapped value of an `Optional` instance
/// only if the wrapped value is not empty, otherwise returns a default value.
///
/// - Parameters:
@fxm90
fxm90 / CheckboxToggleStyle.swift
Last active March 31, 2023 17:38
A fully configurable toggle style for SwiftUI, making the Toggle look like a checkbox.
//
// CheckboxToggleStyle.swift
//
// Created by Felix Mau on 25.05.2021.
// Copyright © 2021 Felix Mau. All rights reserved.
//
/// A fully configurable toggle style for SwiftUI, making the Toggle look like a checkbox.
struct CheckboxToggleStyle: ToggleStyle {
@nkmrh
nkmrh / DonutPieChart.playground.swift
Last active January 14, 2023 00:41
Draw donut pie chart with SwiftUI
import UIKit
import SwiftUI
extension FloatingPoint {
var degreesToRadians: Self { self * .pi / 180 }
var radiansToDegrees: Self { self * 180 / .pi }
}
struct Donut: Identifiable {
var id = UUID()
@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
import CoreData
import SwiftUI
struct ContentView : View {
var request: FetchRequest<Task>
init(taskID: Int) {
self.request = FetchRequest<Task>(fetchRequest: ContentViewTest.taskRequest(taskID: taskID))
}
@pudquick
pudquick / pipista.py
Created November 20, 2012 07:23
pipista - pip module (for installing other modules) for Pythonista
import os, os.path, sys, urllib2, requests
class PyPiError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
def _chunk_report(bytes_so_far, chunk_size, total_size):
if (total_size != None):