Skip to content

Instantly share code, notes, and snippets.

set nosmoothscroll
set noautofocus
let searchlimit = 30
let scrollduration = 10
let scrollstep = 70
let locale = "jp"
let searchalias g = "google"
let blacklists = ["chrome://*","https://mail.google.com/*","http://feedly.com/*","https://www.google.com/calendar/*","https://my.omniture.com/*"]
let barposition = "bottom"
@starhoshi
starhoshi / ios9-transport-security.sh
Last active January 4, 2016 06:12
cordova ios9 App Transport Security (project_root/after_prepare/ios9-transport-security.sh)
#!/bin/bash
PLIST=platforms/ios/*/*-Info.plist
cat << EOF |
Add :NSAppTransportSecurity dict
Add :NSAppTransportSecurity:NSExceptionDomains dict
Add :NSAppTransportSecurity:NSExceptionDomains:dev.example.com dict
Add :NSAppTransportSecurity:NSExceptionDomains:dev.example.com:NSExceptionAllowsInsecureHTTPLoads bool YES
Add :NSAppTransportSecurity:NSExceptionDomains:dev.example.com:NSExceptionRequiresForwardSecrecy bool NO
@starhoshi
starhoshi / ManageViewController.swift
Created February 4, 2017 15:05
SnapKit で画面を作ってみる遊び
import UIKit
import SnapKit
import RxSwift
import RxCocoa
final class ManageView: UIView {
let descriptionLabel = UILabel()
let greetingTitleLabel = UILabel()
let greetingLabel = UILabel()
let segmented = UISegmentedControl(items: ["挨拶の始まり選択", "自由入力"])
@starhoshi
starhoshi / UIWindow+Ex.swift
Created June 27, 2017 12:30
rootViewController を別の ViewController に入れ替える [Swift3]
import UIKit
extension UIWindow {
func changeRootViewController(new viewController: UIViewController) {
UIView.transition(
with: UIApplication.shared.keyWindow!,
duration: 0.5,
options: .transitionCrossDissolve,
animations: {
UIApplication.shared.keyWindow?.rootViewController = viewController
@starhoshi
starhoshi / UIWebView+Ex.swift
Last active June 27, 2017 12:31
UIWebView で Custom UserAgent をセットする [Swift 3]
import UIKit
extension UIWebView {
func setCustomUserAgent() {
let classiSuffix = Constants.userAgent
let originalUserAgent = stringByEvaluatingJavaScript(from: "navigator.userAgent")!
let customUserAgent = originalUserAgent + "+CustomUA"
UserDefaults.standard.register(defaults: ["UserAgent": customUserAgent])
print("new userAgent: \(pbUserAgent)")
}
@starhoshi
starhoshi / URL+Ex.swift
Last active June 29, 2017 02:38
https://google.com/ のような、最後に / だけ付いている場合に / を削除する
public extension URL {
public func removeLastSlash() -> URL {
let separator = "/"
let schemeSeparator = "://"
var paths = path.components(separatedBy: separator)
if let lastPaths = paths.last, lastPaths == "", let host = self.host, let scheme = self.scheme {
paths.removeLast()
let urlString = scheme + schemeSeparator + host + paths.joined(separator: separator)
return URL(string: urlString) ?? self
@starhoshi
starhoshi / NSCoding.swift
Created June 29, 2017 05:40
UserDefault などに class を保存するサンプル
import Foundation
import ObjectMapper
public class User: NSObject, Mappable, NSCoding {
public var id: Int!
public var name: String!
public required init?(map: Map) {
}
@starhoshi
starhoshi / StatsInputView.swift
Last active October 14, 2017 07:43
コードで綺麗に View かけた
import UIKit
class StatsInputView: UIView {
private let verticalStackView: UIStackView = {
let stackView = UIStackView()
stackView.distribution = .fillEqually
stackView.axis = .vertical
stackView.alignment = .fill
return stackView
}()
{
"extends": "tslint:latest",
"rules": {
"array-type": [
true,
"array"
],
"boolean-trivia": true,
"class-name": true,
"comment-format": [
//
// Nature.swift
// DamageZ-VIPER
//
// Created by Kensuke Hoshikawa on 2017/10/11.
// Copyright © 2017年 star__hoshi. All rights reserved.
//
import Foundation