[XCode]DropboxにGitリモートリポジトリを作る

DropboxにGitリモートリポジトリを作る

1) gitインストール
2) ターミナルで
「cd /Users/ユーザ名/Dropbox/git/プロジェクト名」
「git –bare init」
3) XCodeで対象プロジェクトを開く
4) Source Control -> プロジェクト名 – master -> Configure プロジェクト名
5) Remotesクリック
6) 左下+ -> Add Remote
7) Nameに任意の名前 Addresに「/Users/ユーザ名/Dropbox/git/プロジェクト名」を入力後「Add Remote」
8) Source Control -> Commit CommitMessageを入力して左下「Push to remote」チェック

[objective-c]UIViewをUIImageへ(Retina対応)

UIViewをUIImageへ(Retina対応)

-(UIImage*)getUIImageByUIView:(UIView*)view
{
    UIImage *screenImage;
    //UIGraphicsBeginImageContext(size);
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    screenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenImage;
}

[Ruby]formの値を受け取る

formの値を受け取る

サンプル

#!/usr/bin/ruby-1.9.3
# coding: utf-8
require 'cgi'

puts "Content-type: text/plain\n\n"
cgi = CGI.new
keys=cgi.keys
keys.each{|value|
    puts value+" = "+cgi[value]+"\n"
}

[Ruby]ファイルを読み込む

ファイルを読み込む

サンプル

#!/usr/bin/ruby-1.9.3
# coding: utf-8
require 'json'

puts "Content-type: application/json\n\n"

filename="test.txt"
results=Array.new

if File.exist?(filename)
    f = open(filename)
    f.each{|line|
        results.push(line.force_encoding("utf-8"))
    }
    f.close
else
    results.push("no data")
end

puts JSON.generate({'time'=>Time.now.strftime("%Y-%m-%d %H:%M:%S"), 'data'=>results})

[Ruby]MySQLからデータ取得

MySQLからデータ取得

サンプル

#!/usr/bin/ruby-1.9.3
# coding: utf-8
require 'json'
require 'mysql'

puts "Content-type: application/json\n\n"

connection = Mysql.connect('host','user','password','db name')
connection.query("set character set utf8") #文字化けするとき

columns=["ID","post_title","post_date"]
result = connection.query("SELECT "+columns.join(",")+" FROM wp_posts WHERE post_status='publish' ORDER BY ID DESC LIMIT 5")
connection.close

results=Array.new
result.each {|record|
    w = {}
    record.each_with_index{|val,i|
        key = columns[i]
        w[key.force_encoding("utf-8")]=val.force_encoding("utf-8") #文字化けするときforce_encoding
    }
    results.push(w)
}
puts JSON.generate({'time'=>Time.now.strftime("%Y-%m-%d %H:%M:%S"), 'data'=>results})

[MySQL]MySQLの文字コードの設定を確認する

MySQLの文字コードの設定を確認する

クエリ

SHOW VARIABLES LIKE 'character_set%'

結果

Variable_name Value
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server utf8
character_set_system utf8
character_sets_dir /usr/share/mysql/charsets/

[Ruby]jsonを出力する

jsonを出力する

サンプル

#coding:utf-8
require 'json'
print("Content-type: application/json\n\n")

print JSON.generate({"time"=>Time.now.strftime("%Y-%m-%d %H:%M:%S"),
                    "user"=>[
                                {"id" => 32, "name"=>"jeff"},
                                {"id" => 56, "name"=>"john"}
                            ]
                    })

[objective-c]UIColorから16進数の文字列を得る

UIColorから16進数の文字列を得る

NSString*colorHex = [self getColorHexByUIColor:[UIColor redColor]];
NSLog("%@",colorHex);

-(NSString*)getColorHexByUIColor:(UIColor*)color
{
    CGFloat r,g,b,a;
    [color getRed:&r green:&g blue:&b alpha:&a];
    return [NSString stringWithFormat:@"%02x%02x%02x",(int)(r*255.0),(int)(g*255.0),(int)(b*255.0)];
}

[Swift]Swift #5 animateWithDuration

Swift #5 animateWithDuration

@IBOutlet weak var mainLabel: UILabel!

func initUI(){
    var message:String = getMessage(message:"いあうえ",message2:"390u8")
    println(message)
        
    message = getMessage(message2:"むぎちゃ")
    println(message)

    UIView.animateWithDuration(
        2.0,
        delay: 1.0,
        usingSpringWithDamping: 1.0,
        initialSpringVelocity: 0.0,
        options: UIViewAnimationOptions.CurveEaseInOut,
        animations:{()in
            self.mainLabel.frame = CGRectMake(100.0, 300.0, self.mainLabel.frame.size.width, self.mainLabel.frame.size.height)
        },
        completion:{(finished)in
            println("finished:\(finished)")
            
        })
}
func getMessage(var message:String="ABC",var message2:String="MBNRKF")->String{
    return "\(message) \(message2)"
}

override func viewDidLoad() {
    super.viewDidLoad()
    initUI()
}

出力結果

いあうえ 390u8
ABC むぎちゃ
finished:true