Skip to content

Instantly share code, notes, and snippets.

View zigzagg16's full-sized avatar
馃彔
Working from home

zig zag zigzagg16

馃彔
Working from home
View GitHub Profile
@nikcub
nikcub / README.md
Created October 4, 2012 13:06
Facebook PHP Source Code from August 2007
@frozzare
frozzare / regex+string.swift
Created June 11, 2014 11:01
Regex example
import Foundation
extension String {
func exec (str: String) -> Array<String> {
var err : NSError?
let regex = NSRegularExpression(pattern: self, options: NSRegularExpressionOptions(0), error: &err)
if err {
return Array<String>()
}
let nsstr = str as NSString
@chriseidhof
chriseidhof / routes.swift
Created August 17, 2014 21:04
Type-safe routes in Swift
//
// main.swift
// Routes
//
// Created by Chris Eidhof on 17/08/14.
// Copyright (c) 2014 Chris Eidhof. All rights reserved.
//
import Foundation
@natecook1000
natecook1000 / shuffle.swift
Last active April 5, 2017 21:17
Swift 2.0 shuffle / shuffleInPlace
// (c) 2015 Nate Cook, licensed under the MIT license
//
// Fisher-Yates shuffle as protocol extensions
extension CollectionType {
/// Return a copy of `self` with its elements shuffled
func shuffle() -> [Generator.Element] {
var list = Array(self)
list.shuffleInPlace()
return list
@NatashaTheRobot
NatashaTheRobot / WatchConnectivitySingletonDemo.swift
Last active May 21, 2024 18:21
WatchConnectivity Singleton Demo
//
// WatchSessionManager.swift
// WatchConnectivityDemo
//
// Created by Natasha Murashev on 9/3/15.
// Copyright 漏 2015 NatashaTheRobot. All rights reserved.
//
import WatchConnectivity
@daehn
daehn / Searchable.swift
Last active April 23, 2019 03:05
Swift protocols and protocol extensions to easily add and delete conforming instances to Spotlight. Blog post can be found here: http://silvandaehn.com/2015/09/25/Simplifying-CoreSpotlight/
import UIKit
import CoreSpotlight
import MobileCoreServices
public typealias Completion = NSError? -> Void
// MARK: - Searchable Protocol
public protocol Searchable {
static var spotlightDomainIdentifier: String { get }
@chriseidhof
chriseidhof / tableviews.swift
Last active October 15, 2023 20:56
trySwift
import UIKit
// If you enjoyed this talk (video link will be up soon), then you might also enjoy our book Advanced Swift: http://www.objc.io/books/advanced-swift
struct Person {
let name: String
let city: String
}
let people = [
@lvterry
lvterry / getAssetThumbnail.swift
Created March 28, 2016 14:57
Convert PHAsset to UIImage with Swift
// it returns a square thumbnail.
func getAssetThumbnail(asset: PHAsset, size: CGFloat) -> UIImage {
let retinaScale = UIScreen.mainScreen().scale
let retinaSquare = CGSizeMake(size * retinaScale, size * retinaScale)
let cropSizeLength = min(asset.pixelWidth, asset.pixelHeight)
let square = CGRectMake(0, 0, CGFloat(cropSizeLength), CGFloat(cropSizeLength))
let cropRect = CGRectApplyAffineTransform(square, CGAffineTransformMakeScale(1.0/CGFloat(asset.pixelWidth), 1.0/CGFloat(asset.pixelHeight)))
let manager = PHImageManager.defaultManager()
@andreacipriani
andreacipriani / Bash.swift
Last active September 11, 2024 06:46
Execute shell/bash commands from Swift
import UIKit
protocol CommandExecuting {
func run(commandName: String, arguments: [String]) throws -> String
}
enum BashError: Error {
case commandNotFound(name: String)
}
@vinayjn
vinayjn / AnchorPoint.swift
Last active February 10, 2020 15:16
Change the anchor point of a CALayer in Swift
setAnchorPoint(CGPoint(x: 0.5, y: 0.5), forLayer: layer)
private func setAnchorPoint(anchorPoint: CGPoint, forLayer layer: CALayer) {
var newPoint = CGPoint(x: layer.bounds.size.width * anchorPoint.x, y: layer.bounds.size.height * anchorPoint.y)
var oldPoint = CGPoint(x: layer.bounds.size.width * layer.anchorPoint.x, y: layer.bounds.size.height * layer.anchorPoint.y)
newPoint = CGPointApplyAffineTransform(newPoint, layer.affineTransform())
oldPoint = CGPointApplyAffineTransform(oldPoint, layer.affineTransform())
var position = layer.position
position.x -= oldPoint.x