Skip to content

Instantly share code, notes, and snippets.

View toshi0383's full-sized avatar
🏠
Working from home

Toshihiro Suzuki toshi0383

🏠
Working from home
View GitHub Profile
@toshi0383
toshi0383 / CodePiece.swift
Created July 30, 2015 07:14
ふとこんな構文があったらどうだろうとか妄想していた。 #CodePiece
/* 妄想 */
walkOutside().if() {
return isNiceWeather()
} else {
stayAtHome()
}
@toshi0383
toshi0383 / deploygate.sh
Last active August 29, 2015 14:26
upload to DeployGate
#!/bin/bash
# usage: ./deploygate.sh path/to.ipa "This is new beta app"
deploygate() {
username=${DEPLOYGATE_USER:?}
apikey=${DEPLOYGATE_API_TOKEN:?}
pathToIpa=${1:?}
message="$2"
command="ipa distribute:deploygate \
--trace \
-n \
import Darwin
enum Member: Int {
case Nakagawa, Otani, Mattsu, Toshi, Minami
case Unknown
static let count:Int = 5
static func getSomeone() -> Member {
let r = Int(arc4random_uniform(10000))
let i = r % Member.count
return Member(rawValue: i) ?? Member.Unknown
}
import Darwin
enum Member: Int {
case Nakagawa, Otani, Mattsu, Toshi, Minami
case Unknown
static let count:Int = 5
static func getSomeone() -> Member {
let r = Int(arc4random_uniform(10000))
let i = r % Member.count
return Member(rawValue: i) ?? Member.Unknown
}
#!/bin/bash
#
# name:
# mkicon.sh
#
# description:
# Generates icon images from original file
# The original image should be larger than 1024x1024 in pixel
#
# parameters:
@toshi0383
toshi0383 / map.swift
Last active January 10, 2021 08:59
Custom map implementation performance test in Swift
import Foundation
// used in map5
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
let group = dispatch_group_create()
extension Array {
func map2<U>(transform: Element ->U) -> [U] {
return reduce([]) {
$0 + [transform($1)]
/// A pointer to an object of type `Memory`. This type provides no automated
/// memory management, and therefore the user must take care to allocate
/// and free memory appropriately.
///
/// The pointer should be aligned to `alignof(Memory.self)`.
///
/// The pointer can be in one of the following states:
///
/// - memory is not allocated (for example, pointer is null, or memory has
/// been deallocated previously);
import Foundation
extension Array {
func map7<U>(@noescape transform: Element ->U) -> [U] {
var result = UnsafeMutablePointer<U>.alloc(1000)
let resultBuffer = UnsafeMutableBufferPointer(start: result, count: 1000)
self.withUnsafeBufferPointer { (buffer:UnsafeBufferPointer<Element>) in
for element in buffer {
import Foundation
extension Array {
func map7<U>(@noescape transform: Element ->U) -> [U] {
var result = UnsafeMutablePointer<U>.alloc(1000)
let resultBuffer = UnsafeMutableBufferPointer(start: result, count: 1000)
self.withUnsafeBufferPointer { (buffer:UnsafeBufferPointer<Element>) in
for element in buffer {
@toshi0383
toshi0383 / CodePiece.swift
Created October 4, 2015 01:40
SwiftBond。短いは正義。まあ正直読みやすくはない。ちなみにreduceのパラメータ省略して$0, $1 とするとSegmentation Fault 11。 #CodePiece
reduce(username.dynText, dB: password.dynText, dC: passwordVerification.dynText)
{ user, pass, v in
return [user, pass, v].reduce(true)
{(v, e) in
return !v ? false : e.characters.count > 0
}
} ->> button.dynEnabled