Skip to content

Instantly share code, notes, and snippets.

View norio-nomura's full-sized avatar

Norio Nomura norio-nomura

View GitHub Profile
@norio-nomura
norio-nomura / HashOfString.swift
Created October 12, 2016 00:30
Hash of Swift String
// The hash algorithm is founded on http://opensource.apple.com//source/CF/CF-1153.18/CFString.c
import Foundation
let first16Char = repeatElement("f", count: 32)
let middle16Char = repeatElement("m", count: 32)
let last16Char = repeatElement("l", count: 32)
let a = (first16Char + ["ab"] + middle16Char + ["ab"] + last16Char).joined()
let b = (first16Char + ["bc"] + middle16Char + ["bc"] + last16Char).joined()
a == b // false
// Foundation
@norio-nomura
norio-nomura / otpauthFromVIPAccess.exp
Last active September 21, 2016 08:23 — forked from p120ph37/VIPAccess.exp
Generate otpauth URL from Symantec's "VIP Access" on OS X that can be used by TOTP Apps such as 1Password.
#!/usr/bin/expect -f
#
# otpauthFromVIPAccess.exp
#
# Generate otpauth scheme url from Symantec VIP Access.
# Usage:
# ./otpauthFromVIPAccess.exp [v]
# If the "v" argument (or any argument) is specified, verbose output
# will be produced on stderr. The otpauth url will be output on stdout.
#
@norio-nomura
norio-nomura / config.console
Last active October 26, 2020 09:31
`git commit` 時に自動でPGP署名する設定
git config user.signingkey <secret key id>
git config gpg.program /path/to/gpg-batch-notty.sh
git config commit.gpgsign true
//
// Collection+movingAverage.swift
//
// inspired by https://gist.github.com/hirohitokato/5bfc5836480d68074135820d73c04794
import Foundation
public protocol ArithmeticType: Comparable, IntegerLiteralConvertible {
func +(lhs: Self, rhs: Self) -> Self
import Foundation
/// A reference type that provides a better default representation than the class name
public protocol DefaultReflectable: Streamable {}
/// A default implementation that enables class members to display their values
extension DefaultReflectable {
/// Constructs a better representation using reflection
internal func DefaultDescription<T>(instance: T) -> String {
let mirror = Mirror(reflecting: instance)
@norio-nomura
norio-nomura / String+StaticString.swift
Last active April 5, 2016 10:40
StringインスタンスをStaticStringとして使う `func withStaticString<T>(@NoEscape f: StaticString -> T)`
import Foundation
extension String {
func withStaticString(@noescape f: StaticString -> Void) {
withCString {
let rawPointer = $0._rawValue
let byteSize = lengthOfBytesUsingEncoding(NSUTF8StringEncoding)._builtinWordValue
let isASCII = true._getBuiltinLogicValue()
let staticString = StaticString(_builtinStringLiteral: rawPointer, byteSize: byteSize, isASCII: isASCII)
f(staticString)
@norio-nomura
norio-nomura / README.md
Last active November 23, 2016 23:23
SequenceType を使った Swift 2.2 のコードを Swift 3 に書き換えて、Swift 2.2でもビルド可能にする。

SequenceType を使った Swift 2.2 のコードを Swift 3 に書き換えて、Swift 2.2でもビルド可能にする。

次のSwift 2.2コードをSwift 3でビルドできるようにする。

//
//  SequenceTests.swift
//
import XCTest

class SequenceTests: XCTestCase {
@norio-nomura
norio-nomura / example.md
Last active March 30, 2016 08:59
`git submodule update --init --recursive` stores gitdir in full path into `.git` of nested submodules

git submodule update --init --recursive stores gitdir in full path into .git of nested submodules. So, working directory is not portable to another directory.

On following example, Carthage/Checkouts/Quick/Externals/Nimble/ is nested submodule and Carthage/Checkouts/Quick/Externals/Nimble/.git contains full path.

➜  15:34:01  git clone https://github.com/Carthage/Commandant.git
Cloning into 'Commandant'...
remote: Counting objects: 891, done.
remote: Compressing objects: 100% (93/93), done.
@norio-nomura
norio-nomura / add_path_to_swift-build.sh
Last active March 24, 2016 16:31
Fix "dyld: Library not loaded: @rpath/libswiftCore.dylib" on swift-DEVELOPMENT-SNAPSHOT-2016-03-16-a
sudo install_name_tool -add_rpath @executable_path/../lib/swift/macosx /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-03-16-a.xctoolchain/usr/bin/swift-build
sudo install_name_tool -add_rpath @executable_path/../lib/swift/macosx /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-03-16-a.xctoolchain/usr/bin/swift-test
protocol Pokemon {
typealias PokemonType
func attack(move: PokemonType)
}
class Pikachu: Pokemon {
func attack(move: Int) {
print("pika")
}
}