Skip to content

Instantly share code, notes, and snippets.

@tamaki-shingo
tamaki-shingo / OpenByXcodeSelect
Created September 16, 2018 13:57
It is alias for open by xcode using path of `xcode-select -p`.
alias xcode='xcode-select -p | cut -d '/' -f3 | xargs -I{} open -a {} $1'
@tamaki-shingo
tamaki-shingo / gist:b896cd2180f96db5628d1f56f2cdb0df
Created November 19, 2017 10:03
Array extension for to Control layout constraints together
extension Array where Element == NSLayoutConstraint {
func activate() {
self.forEach { (constraint) in
constraint.isActive = true
}
}
func deactivate() {
self.forEach { (constraint) in
constraint.isActive = false
}
@tamaki-shingo
tamaki-shingo / CodePiece.swift
Created January 8, 2017 14:06
こうなった。なるほど。このほうが気持ちいいですね。もう一段階なんか方法がある気がしてたのでスッキリ。 @eduraaa #CodePiece
protocol UUIDRepresentable: RawRepresentable {
associatedtype RawValue = String
}
extension UUIDRepresentable where Self.RawValue == String {
func uuid() -> String {
return self.rawValue
}
}
@tamaki-shingo
tamaki-shingo / CodePiece.swift
Created January 8, 2017 13:16
String型のEnumだけに縛りたいならこうかな? #CodePiece
protocol UUIDRepresentable: RawRepresentable {
}
extension UUIDRepresentable where Self.RawValue == String {
func uuid() -> String {
return self.rawValue
}
}
enum hogeInt : Int, UUIDRepresentable {
extension NSLayoutAttribute {
func toString() -> String {
switch self {
case .Left: return "Left"
case .Right: return "Right"
case .Top: return "Top"
case .Bottom: return "Bottom"
case .Leading: return "Leading"
case .Trailing: return "Trailing"
case .Width: return "Width"
@tamaki-shingo
tamaki-shingo / gist:68dc4655fbc14cad20d96c83c54490f9
Created November 8, 2016 02:25
convenience applescript script for xcode debugging
display notification "Foo Bar" & (time string of(current date))
@tamaki-shingo
tamaki-shingo / CodePiece.swift
Created November 5, 2016 11:05
やっぱ同じかな? 個人的にはVoidだと思うんだけど好みの問題かね? #CodePiece
var action1: () -> Void = {}
var action2: ()->() = {}
let result1 = action1()
let result2 = action2()
print(type(of: result1))
print(type(of: result2))
import Foundation
import CoreMotion
struct SimpleMovingAvgQueue{
typealias EulerAngles = (roll: Double, pitch: Double, yaw: Double)
var eulerAngles = Array<EulerAngles>()
let capacity: Int
init(capacity cap: Int) {
self.capacity = cap
extension Array where Element: FloatingPoint {
func simpleMovingAverage(scope:Int) -> [Element]? {
guard self.count >= scope else { return nil }
var result = [Element]()
for endIndex in scope...self.count {
let lower = endIndex-scope
let upper = endIndex
let range = Range(uncheckedBounds: (lower: lower, upper: upper))
let sum = self[range].reduce(0) { (v1, v2) -> Element in return v1+v2 }
let avg = sum/Element(scope)
@tamaki-shingo
tamaki-shingo / showCodesigning.sh
Created January 15, 2015 08:27
show codesigning
/usr/bin/security find-identity -p codesigning -v