Skip to content

Instantly share code, notes, and snippets.

@adam-fowler
adam-fowler / webserver.md
Last active December 3, 2021 15:12
Local web server written in swift

For this to work you need swift-sh installed.

#!/usr/bin/env swift-sh

import ArgumentParser   // apple/swift-argument-parser
import HummingbirdFoundation  // hummingbird-project/hummingbird

struct WebServer: ParsableCommand {
    @Option(name: .shortAndLong)
 var port: Int = 8001
@byte-sourcerer
byte-sourcerer / MacEditorTextView.swift
Created October 31, 2021 10:46
An NSTextView wrapped by SwiftUI with TextKit 2
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
* Modified by https://github.com/cjwcommuny for TextKit 2
*/
import Combine
@dduan
dduan / bird.swift
Created November 14, 2020 22:16
Flappy bird as a CLI app written in Swift.
// This is the code for the Flappy Bird game running in a Unix terminal.
// Demo: https://twitter.com/daniel_duan/status/1327735679657250816?s=21
// To run it, simply do "swift bird.swift" in a Unix command line.
#if canImport(Darwin)
import Darwin
#else
import Glibc
#endif
enum RawModeError: Error {
@Julioacarrettoni
Julioacarrettoni / ContentView.swift
Last active February 16, 2022 03:15
Neumorphism in SwiftUI
/// This is a simple example of Neumorphism applied to buttons in SwiftUI
/// As seen on https://twitter.com/dev_jac/status/1228575575171723264
/// This should work straight out of the box, no other files are required
import SwiftUI
extension Color {
static let mainColor = Color(red: 224/255, green: 229/255, blue: 236/255)
static let mainColorActive = Color(red: 220/255, green: 225/255, blue: 232/255)
static let grayShadow = Color(red: 163/255, green: 177/255, blue: 198/255)
@zntfdr
zntfdr / firebase-iOS-breakdown.swift
Last active September 24, 2024 06:29
Firebase iOS Version breakdown
// How to:
// 1. Open the Firebase Analytics Dashboard
// 2. Scroll to bottom, where you see the "Users by Device model" widget
// 3. Click "View device models" in that widget (this opens the "Tech details" Firebase Analytics page)
// 4. Above the table shown in the new page, click on the “Device model” drop down menu and select “OS with Version”
// 5. Make sure to select “OS with version” and not “OS Version”
// 6. On the top right corner of the page, click on the “Share this report” icon (next to the date)
// 7. Click “Download file” on the new side bar, then “Download CSV"
// 8. Open the file and select the iOS/Android breakdown raw data
// 9. Replace the sample data in this script with your data
@JUSTINMKAUFMAN
JUSTINMKAUFMAN / SSE.swift
Created July 1, 2019 17:12
Swift SSE EventSource Server for Vapor
import Foundation
import NIO
import Vapor
/**
SSE EventSource server implementation for Swift Vapor 3
Usage:
```
// Create a route for all incoming SSE connection
@dmsl1805
dmsl1805 / SnakeCase.swift
Last active September 25, 2024 23:14 — forked from ivanbruel/SnakeCase.swift
Camel case to snake case in Swift
extension String {
func snakeCased() -> String? {
let pattern = "([a-z0-9])([A-Z])"
let regex = try? NSRegularExpression(pattern: pattern, options: [])
let range = NSRange(location: 0, length: count)
return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "$1_$2").lowercased()
}
}
/*
#
# Copyright (c) 2018 Felix Schwarz (@felix_schwarz), IOSPIRIT GmbH (@iospirit)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@CodaFi
CodaFi / AlgorithmW.swift
Last active July 28, 2024 10:04
A Swift Playground containing Martin Grabmüller's "Algorithm W Step-by-Step"
/// Playground - noun: a place where people can play
/// I am the very model of a modern Judgement General
//: # Algorithm W
//: In this playground we develop a complete implementation of the classic
//: algorithm W for Hindley-Milner polymorphic type inference in Swift.
//: ## Introduction
import Foundation
// MARK: - Protocol
public protocol Notifier {
associatedtype Notification: RawRepresentable
}
public extension Notifier where Notification.RawValue == String {