cssのパディングとマージン
パディングとマージンどっちがどっちかよく忘れるのでメモしておく。
コード
<html> <head> <style type="text/css"> div { padding : 10px; /* 要素とボーダーラインのあいだの距離 */ border : 5px solid maroon; /* ボーダーラインの幅 */ margin : 10px; /* ボーダーラインと画面の端の距離 */ background-color : lightgreen; } </style> </head> <body> <div class="hoge"> hoge </div> </body> </html>
ちなみにcssでは //
をコメントに使えないので /* */
を使う必要がある。
2つの proc を合成して1つの proc にする
# 2つの proc を合成して1つの proc にする def foo(arg1, arg2) Proc.new do arg1.call arg2.call end end p1 = Proc.new { p 123} p2 = Proc.new { p 456} res = foo( p1, p2 ) res.call # => 123\n456
例外を投げるclosure
() throws ->(String) in
と書くと例外を投げるクロージャを定義できる
enum MyError : ErrorType { case Hoge } let c = {() throws ->(String) in throw MyError.Hoge } do { try c() } catch { print( "\(__FUNCTION__): L\(__LINE__)") }
Swiftでクラスからインスタンスを生成する
インスタンス化するクラスを定義
class Hoge { required init(){ } class func newInstance()->Hoge { return Hoge.init() } }
呼び出し
let hogeClass: Hoge.Type = Hoge.self let hogeObject = hogeClass.init()
Rubyで行列とベクトルの演算
固有ベクトルは任意の行列m を適用した際に,向きが変わらないベクトルのこと
require 'matrix' m = Matrix[ [2,1], [1,2] ] v1 = Vector[1, 1] v2 = Vector[1, -1] # v1は m の eigen vecotr p m * v1 # => Vector[3, 3] # v2 is eigen vector of matrix m too. # eigen value is 1 p m * v2 # => Vector[1, -1]
参考
UIWebView でリンクをクリックしたとき safari で開く
UIWebView でリンクをクリックしたとき safari で開く
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { if(navigationType == UIWebViewNavigationType.LinkClicked){ UIApplication.sharedApplication().openURL(request.URL!) return false } return true }