This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import Charts | |
import Combine | |
import Foundation | |
final class GameState: ObservableObject { | |
struct Player { | |
var position: Int | |
var halfSize: Int = 150 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Resize a SVG file to a new size. Coordinates of paths and gradient definitions get transposed to corresponding | |
values in the new canvas. Everything else remain unchanged. | |
""" | |
import re | |
from argparse import ArgumentParser | |
from xml.etree import ElementTree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SHELL = /bin/bash | |
ifeq ($(shell uname),Darwin) | |
EXTRA_SWIFT_FLAGS = "--disable-sandbox" | |
else | |
SWIFT_TOOLCHAIN = "$(shell dirname $(shell swift -print-target-info | grep runtimeResourcePath | cut -f 2 -d ':' | cut -f 2 -d '"'))" | |
EXTRA_SWIFT_FLAGS = -Xcxx -I${SWIFT_TOOLCHAIN}/swift -Xcxx -I${SWIFT_TOOLCHAIN}/swift/Block | |
endif | |
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func toTimestamp(year: Int, month: Int, day: Int, hour: Int, minute: Int, seconds: Int, nanoseconds: Int, offsetInSeconds: Int) -> Double { | |
var year = year | |
year -= month <= 2 ? 1 : 0 | |
let era = (year >= 0 ? year : year - 399) / 400 | |
let yoe = year - era * 400 | |
let doy = (153*(month + (month > 2 ? -3 : 9)) + 2)/5 + day - 1 | |
let doe = yoe * 365 + yoe/4 - yoe/100 + doy | |
let dayCounts = era * 146097 + doe - 719468 | |
let seconds = dayCounts * 86400 + hour * 3600 + minute * 60 + seconds - offsetInSeconds | |
return Double(seconds) + Double(nanoseconds) / 1_000_000_000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A rotating 3-D cube in terminal | |
/// Only works on macOS | |
/// Run `swift cube.swift` in a terminal application to run it. | |
/// For controlling the cube, see comments for `Key` in code. | |
import Darwin | |
enum RawModeError: Error { | |
case notATerminal | |
case failedToGetTerminalSetting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if canImport(Darwin) | |
import Darwin | |
#else | |
import Glibc | |
#endif | |
enum RawModeError: Error { | |
case notATerminal | |
case failedToGetTerminalSetting | |
case failedToSetTerminalSetting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@propertyWrapper | |
struct Escaping { | |
typealias Closure = () -> Void | |
var store: Closure | |
var wrappedValue: Closure { | |
get { self.store } | |
set { self.store = newValue } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ChaoticPhoto: View { | |
let image: Image | |
let radius: CGFloat | |
@Binding var activated: Bool | |
@State var scale: CGFloat = 1 | |
var body: some View { | |
image | |
.resizable() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
temp_file=$(mktemp) | |
echo 'FROM swift@sha256:c4d53af406c5dc48bd43c0d313f3ed80924eee4bf78907ce4ad6eb8f5513f376' >> temp_file | |
echo 'RUN git clone https://github.com/dduan/DrString.git; cd DrString; make build; cp .build/release/drstring /bin/drstring' >> temp_file | |
echo 'RUN rm -rf /data' >> temp_file | |
echo 'ADD . /data' >> temp_file | |
echo 'WORKDIR /data' >> temp_file | |
echo 'ENTRYPOINT ["drstring"]' >> temp_file |
NewerOlder