Skip to content

Instantly share code, notes, and snippets.

View moaible's full-sized avatar

Hiromi Motodera moaible

View GitHub Profile
extension String {
var components: [String] {
return self.characters.map { String.init($0) }
}
func componentsSeparated(
separator: String.CharacterView.Generator.Element) -> [String] {
return self.characters.split(separator: separator).map(String.init)
}
#!/usr/bin/env swift
#if os(OSX)
import Darwin
#else
import Glibc
#endif
import Foundation
static func shell(
_ args: String...,
input: AnyObject? = nil,
errorHandler: AnyObject? = nil,
inDirectory: String? = nil,
waitUntilExit: Bool = true) -> Pipe?
{
let task = Task()
task.launchPath = "/usr/bin/env"
task.arguments = args
import RealmSwift
class RealmString: Object, StringLiteralConvertible {
typealias StringLiteralType = String
typealias ExtendedGraphemeClusterLiteralType = StringLiteralType
typealias UnicodeScalarLiteralType = StringLiteralType
extension Array {
func repeatInserted(addElement: Element, repeatIndex: Int) -> [Element] {
guard self.count > 0 else {
return []
}
guard self.count >= repeatIndex else {
return self
}
@moaible
moaible / SystemMainAction.swift
Created January 16, 2017 14:02
swift cli system function
//
// SystemMainAction.swift
// SystemMainAction
//
// Created by moaible on 2017/01/16.
//
//
import Foundation
import APIKit
import Unbox
// MARK: - Abstract
protocol ResponseParser {
associatedtype ParsedResponse
static func parsedResponse(object: Any) throws -> ParsedResponse
@moaible
moaible / react-sticky-sample.js
Created March 24, 2017 05:15
react-sticky sample
/* @flow */
import React from 'react'
import { StickyContainer, Sticky } from 'react-sticky'
import Header from '../../components/header'
import Footer from '../../components/footer'
type Props = {
children: React.Children
}
@moaible
moaible / repository.swift
Created March 27, 2017 04:27
Swift ddd repository query pettern
import SwiftTask
protocol RepositoryQuery {
}
protocol Repository {
associatedtype ContentId
@moaible
moaible / es6-flowtype-request-types.js
Created March 30, 2017 11:22
es6+flowtype request-types
declare class Headers {
@@iterator(): Iterator<[string, string]>;
constructor(init?: HeadersInit): void;
append(name: string, value: string): void;
delete(name: string): void;
entries(): Iterator<[string, string]>;
get(name: string): string;
getAll(name: string): Array<string>;
has(name: string): boolean;
keys(): Iterator<string>;