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
extension UITableViewController { | |
func reloadDataShowAnimated() { | |
self.tableView.reloadData() | |
let cells = tableView.visibleCells | |
let tableHeight: CGFloat = tableView.bounds.size.height | |
cells.forEach { cell in | |
cell.transform = CGAffineTransformMakeTranslation(0, tableHeight) |
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
#!/usr/bin/swift | |
import AppKit | |
let application = NSApplication.shared | |
let fileOpenPanel = NSOpenPanel(), fileSavePanel = NSSavePanel() | |
let window: NSWindow = { window in | |
window.setContentSize(NSSize(width:800, height:600)) | |
window.styleMask = [.titled, .closable, .miniaturizable] |
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 downsample(values: [(x:Double, y: Double)], threshold: Int) -> [(x:Double,y: Double)] { | |
guard values.count > threshold && values.count > 2 else { return values } | |
let bucketSize = (values.count - 2) / (threshold - 2) | |
var A = 0, nextA = 0 | |
var out = [(x:Double, y: Double)]() | |
var maxAreaPoint: (x:Double, y: Double) = (x:0, y: 0) | |
out.append(values.first!) |
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
infix operator .. : StrideFormationPrecedence | |
precedencegroup StrideFormationPrecedence { | |
lowerThan: RangeFormationPrecedence | |
} | |
func .. <T: Strideable>(left: Range<T>, right: T.Stride) -> StrideTo<T> { | |
return stride(from: left.lowerBound, to: left.upperBound, by: right) | |
} |
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 Foundation | |
let base62Alphabet: [Character] = [ | |
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", | |
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", | |
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", | |
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", | |
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", | |
] |
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
extension CommandLine { | |
@dynamicMemberLookup | |
public struct Options { | |
private let dict: [String : String] | |
public init?(_ arguments: [String]) { | |
let keysWithValues = arguments.dropFirst().compactMap(parse) | |
if keysWithValues.isEmpty { return nil } | |
self.dict = Dictionary(keysWithValues) { $1 } | |
} |
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
LocalizedTagTemplates["deDE"] = { | |
lfg = { | |
{ | |
title = "Looking For Group", | |
keywords = { | |
"lf", | |
"lfg","lfd", | |
"lfm","lf1m","lf2m","lf3m","lf4m", | |
"lftank","lfheal","lfheals","lfhealer","lfdps", | |
"tank","heal","heals","healer","dps","dd","heiler", |
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 Foundation | |
public class PerformanceDataPlot { | |
let xy1s: [[(x: TimeInterval, y: Double)]] | |
let xy2s: [[(x: TimeInterval, y: Double)]] | |
public var y1Titles: [String] | |
public var y2Titles: [String] |
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 Foundation | |
/// Create graphs using gnuplot. | |
public final class Gnuplot { | |
let datablock: String | |
let plot: String | |
public init(data: String) { | |
self.datablock = data | |
self.plot = "plot $data" |
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
/// Represents a polynomial function, e.g. `2 + 3x + 4x²`. | |
public struct Polynomial: Codable, Equatable { | |
/// Represents the coefficients of the polynomial | |
public let coefficients: [Double] | |
public init(coeffs: Double...) { | |
self.coefficients = coeffs | |
} | |
public init(_ array: [Double]) { |
OlderNewer