Skip to content

Instantly share code, notes, and snippets.

@SLboat
SLboat / Bash.swift
Created Dec 27, 2019 — forked from andreacipriani/Bash.swift
Execute shell/bash commands from Swift
View Bash.swift
import Foundation
protocol CommandExecuting {
func execute(commandName: String) -> String?
func execute(commandName: String, arguments: [String]) -> String?
}
final class Bash: CommandExecuting {
// MARK: - CommandExecuting
@SLboat
SLboat / currentTrack.swift
Created May 16, 2019 — forked from bjhomer/currentTrack.swift
Using ScriptingBridge from Swift.
View currentTrack.swift
#! /usr/bin/swift
import ScriptingBridge
@objc protocol iTunesTrack {
optional var name: String {get}
optional var album: String {get}
}
@objc protocol iTunesApplication {
@SLboat
SLboat / timeago.swift
Created May 16, 2019 — forked from minorbug/timeago.swift
"Time ago" function for Swift (based on MatthewYork's DateTools for Objective-C)
View timeago.swift
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil)
if (components.year >= 2) {
return "\(components.year) years ago"
View Python Built-in List vs Numpy.md

Python 内置的 List vs Numpy

Test on MacBook Air (11-inch, Early 2015) 1.6 GHz Intel Core i5

List: List Time used: 7.607762999999999

import time
start = time.clock()
a = range(10000000)	
b = range(10000000)
You can’t perform that action at this time.