Skip to content

Instantly share code, notes, and snippets.

View LeTarrask's full-sized avatar

Alex Luna LeTarrask

View GitHub Profile
@Kentakoong
Kentakoong / JSONManager.swift
Last active March 13, 2024 03:18
Encode + Decode JSON Data with Dynamic Types
import Foundation
class JSONManager {
struct DecodeReturn<T: Decodable> {
var value: T
var error: (any Error)?
}
static func encodeJSON<T: Encodable>(_ data: T) throws -> Data? {
// A URLSession extension that fetches data from a URL and decodes to some Decodable type.
// Usage: let user = try await URLSession.shared.decode(UserData.self, from: someURL)
// Note: this requires Swift 5.5.
extension URLSession {
func decode<T: Decodable>(
_ type: T.Type = T.self,
from url: URL,
keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys,
dataDecodingStrategy: JSONDecoder.DataDecodingStrategy = .deferredToData,
dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate
@davidsteppenbeck
davidsteppenbeck / PreviewProviderModifier.swift
Last active October 31, 2022 10:30
A SwiftUI view modifier for simple preview providers.
import SwiftUI
enum PreviewProviderMode: CaseIterable {
/// Use for a light appearance preview.
case lightMode
/// Use for a dark appearance preview.
case darkMode
@DreamingInBinary
DreamingInBinary / Best in Class iOS Checklist
Last active February 1, 2026 14:46
This is a public checklist updated every year after the latest version of iOS and iPadOS are shipped. It's a boiled down version of a "Best in Class" app checklist created by Jordan Morgan.
# A Best in Class Checklist
A boiled down checklist adapted from this [post](https://www.swiftjectivec.com/a-best-in-class-app/), created by @jordanmorgan10.
> To use this, create a Github Issue in your own repo, and simply copy and paste this text.
## iOS Core Technology
_Things any iOS app can benefit from_
- [ ] iCloud Sync
- [ ] Focus Filter Support
@chriseidhof
chriseidhof / boilerplate.swift
Last active September 27, 2025 12:39
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
// Created by Marcin Krzyzanowski
import Foundation
public protocol JSONEncodable: Encodable { }
public extension JSONEncodable {
func toJSON(using encoder: @autoclosure () -> JSONEncoder = JSONEncoder()) throws -> String {
try String(decoding: encoder().encode(self), as: UTF8.self)
}
@ericaprieto
ericaprieto / worker.js
Last active August 1, 2019 15:49
lazy-seal-12
const Twit = require('twit')
const { Observable, Subject, interval, merge, of, from, race } = require('rxjs')
const { map, flatMap, distinct, zip, tap, filter, bufferTime, count } = require('rxjs/operators')
const config = require('./config')
/*
* config should be an object like this
* {
* targetUsername: string
* minFollowerCount: number
@jnewc
jnewc / NotesApp.swift
Last active August 21, 2025 08:55
A notes app written in <100 lines of swift using SwiftUI
import SwiftUI
let dateFormatter = DateFormatter()
struct NoteItem: Codable, Hashable, Identifiable {
let id: Int
let text: String
var date = Date()
var dateText: String {
dateFormatter.dateFormat = "MMM d yyyy, h:mm a"
@lambda-fairy
lambda-fairy / textanalyzer.py
Created December 28, 2018 07:23
Report the most common phrases in a text file
#!/usr/bin/env python3
from collections import Counter
from itertools import islice
import re
import string
import sys
MIN_PHRASE_LENGTH = 2
@tkfu
tkfu / srd_5e_monsters.json
Last active February 16, 2026 11:49
A JSON file with all the D&D 5e SRD monster data
[
{
"name": "Aboleth",
"meta": "Large aberration, lawful evil",
"Armor Class": "17 (Natural Armor)",
"Hit Points": "135 (18d10 + 36)",
"Speed": "10 ft., swim 40 ft. ",
"STR": "21",
"STR_mod": "(+5)",
"DEX": "9",