Skip to content

Instantly share code, notes, and snippets.

@marslin1220
Created June 25, 2018 14:43
Show Gist options
  • Save marslin1220/12f5ba33e5ec51c6dc70fb5e95335b00 to your computer and use it in GitHub Desktop.
Save marslin1220/12f5ba33e5ec51c6dc70fb5e95335b00 to your computer and use it in GitHub Desktop.
Print swift script like a type machine by script self.
#!/usr/bin/swift
//
// SelfPrinter.swift
// SelfPrinter
//
// Created by Lin Cheng Lung on 2018/6/25.
// Copyright © 2018 Lin Cheng Lung. All rights reserved.
//
import Foundation
let filePosition = CommandLine.arguments[0]
let fileContent = try! String(contentsOfFile: filePosition)
for char in Array(fileContent) {
print(char, terminator: "")
fflush(__stdoutp)
if char == " " {
usleep(arc4random_uniform(300000) + 100000)
} else {
usleep(arc4random_uniform(150000) + 50000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment