Skip to content

Instantly share code, notes, and snippets.

View motokiee's full-sized avatar
🎯
Focusing

motokiee motokiee

🎯
Focusing
  • Mercari, Inc.
  • Tokyo
  • 08:36 (UTC +09:00)
  • X @motokiee
View GitHub Profile
@motokiee
motokiee / file0.swift
Created January 30, 2015 02:58
@IBDesignable@IBInspectableを使ってグラデーション可能なカスタムViewを作ってみた ref: http://qiita.com/mo_to_44/items/762f42c22ae70c689cb9
@IBDesignable class GradationView: UIView {
@IBInspectable var gradationStartColor : UIColor = UIColor.whiteColor()
@IBInspectable var gradationEndColor : UIColor = UIColor.blackColor()
@IBInspectable var gradationXPosition : CGFloat = 0.5
@IBInspectable var gradationYPosition : CGFloat = 0.5
@IBInspectable var circleSize : CGFloat = 1.0
override func drawRect(rect: CGRect) {
@motokiee
motokiee / UIStroyboardExtension.swift
Last active August 29, 2015 14:20
UIStroyboard Extension
extension UIStoryboard {
/**
StoryboardからUIViewControllerを取り出す
:param: storyboardName 取り出すstoryboard名
:param: viewControllerName 取り出したいviewcontroller名
:returns: viewController
*/
class func instantiateViewController(storyboardName: String, viewControllerName: String) -> UIViewController {
@motokiee
motokiee / UIViewExtension.swift
Last active August 29, 2015 14:20
UIView Extension
/**
* xibからviewオブジェクトを取り出す
*/
extension UIView {
class func loadFromNibNamed(nibNamed: String, bundle : NSBundle = NSBundle.mainBundle()) -> UIView! {
return UINib(nibName: nibNamed, bundle: bundle).instantiateWithOwner(nil, options: nil)[0] as? UIView
}
class func screenCapture(view: UIView) -> UIImage {
@motokiee
motokiee / ReadPlist.swift
Last active August 29, 2015 14:20
Read plist file
let filePath = NSBundle.mainBundle().pathForResource(<#Filename#>, ofType:"plist" )
let dic = NSDictionary(contentsOfFile:filePath!)
let numbers = [0,1,2,3,4,5]
var sum = { (a:Int, b:Int) -> Int in
a + b
}
var odd = { (number:Int) -> Bool in
number % 2 != 0
}
[[NSUserDefaults alloc] initWithSuiteName:<#App Groups Name#>];
@motokiee
motokiee / CustomView.m
Created August 9, 2015 01:35
dash line custom view
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface CustomView : UIView
@property (nonatomic) IBInspectable CGFloat lineWidth;
@property (nonatomic) IBInspectable CGFloat dotWidth;
@property (nonatomic) IBInspectable CGFloat dotInterval;
@property (nonatomic) IBInspectable UIColor *lineColor;
@property (nonatomic) IBInspectable BOOL *isThinLine;
lucky :: Int -> String
lucky 7 = "LUCKY NUMBER SEVEN!!"
lucky x = "SORRY," ++ show x ++ " YOU'RE OUT OF LUCK!!"
sayMe :: Int -> String
sayMe 1 = "One"
sayMe 2 = "Two"
sayMe 3 = "Three"
sayMe 4 = "Four"
func chain(num:Int) -> [Int] {
guard num > 0 else {
fatalError("can not calculate with 0")
}
switch num {
case 1:
return [1]
chain :: Integer -> [Integer]
chain 1 = [1]
chain n
| even n = n : chain (n `div` 2)
| odd n = n : chain (n * 3 + 1)
numLongList :: Int
numLongList = length (filter isLong (map chain [1..1000]))
where isLong xs = length xs > 15