2015年5月16日土曜日

CocoaPodsをインストールする

使用中のRuby及びgemのバージョンを確認する。
$ rbenv version
2.2.0 (set by /Users/hogeuser/.rbenv/version)
$ gem -v
2.4.7

CocoaPodsをインストールする。
$ gem install cocoapods
$ rbenv rehash
$ pod setup --verbose


補足


「gem install cocoapods」により"追加で"インストールされたgem
activesupport (4.2.1)

claide (0.8.1)
cocoapods (0.37.1)
cocoapods-core (0.37.1)
cocoapods-downloader (0.9.0)
cocoapods-plugins (0.4.2)
cocoapods-trunk (0.6.0)
cocoapods-try (0.4.4)
colored (1.2)
escape (0.0.4)
fuzzy_match (2.0.4)
i18n (0.7.0)

molinillo (0.2.3)
nap (0.8.0)
netrc (0.7.8)

thread_safe (0.3.5)
tzinfo (1.2.2)
xcodeproj (0.24.1)

インストールするCocoaPodsのバージョンを指定する場合(RubyGemsの仕様通り)
$ gem install cocoapods --version "=0.36.4"

「pod setup」ではそれなりに時間がかかるので根気よく待つ。

2015年4月29日水曜日

32bit EFIブートファイルを作成する

WindowsタブレットPC等で採用されているCPU(Intel Atom: xx Trail)は基本的に32bitアーキテクチャであり、最近は例外なくファームウェアとしてUEFIが採用されていることから、この類のものにLinuxをインストールしたい場合は、別途32bit版(U)EFIファイルを用意する必要がある。

環境
  • Ubuntu Server 14.04.2 LTS x64

作業ディレクトリを作成
$ mkdir ~/tmpwork
$ cd ~/tmpwork

必要なパッケージをインストール
$ sudo apt-get update -y
$ sudo apt-get install -y git build-essential
$ sudo apt-get install -y bison libopts25 libselinux1-dev autogen m4 autoconf help2man libopts25-dev flex libfont-freetype-perl automake autotools-dev libfreetype6-dev texinfo

GRUB 2のソースを落としてきてmake
$ git clone git://git.savannah.gnu.org/grub.git
$ cd grub
$ ./autogen.sh
$ ./configure --with-platform=efi --target=i386 --program-prefix=''
$ make

EFIファイルを作成
$ cd grub-core
$ sudo ../grub-mkimage -d . -o bootia32.efi -O i386-efi -p /boot/grub ntfs hfs appleldr boot cat efi_gop efi_uga elf fat hfsplus iso9660 linux keylayouts memdisk minicmd part_apple ext2 extcmd xfs xnu part_bsd part_gpt search search_fs_file chain btrfs loadbios loadenv lvm minix minix2 reiserfs memrw mmap msdospart scsi loopback normal configfile gzio all_video efi_gop efi_uga gfxterm gettext echo boot chain eval

作成したEFIファイルを作業ディレクトリ直下にコピーしておく
$ cp bootia32.efi ~/tmpwork


[参考URL]
Instructions to install Ubuntu 14.10 on ASUS EeeBook X205TA
UEFIBooting - Community Help Wiki

2015年4月26日日曜日

Ubuntu ServerインストーラをUSBメモリに書き込む

環境
  • Ubuntu Server 14.04.2 LTS x64

isoイメージファイルをダウンロード
$ wget http://releases.ubuntu.com/14.04/ubuntu-14.04.2-server-amd64.iso
$ md5 ubuntu-14.04.2-server-amd64.iso 
MD5 (ubuntu-14.04.2-server-amd64.iso) = 83aabd8dcf1e8f469f3c72fff2375195

isoファイルからimgファイルに変換
$ hdiutil convert -format UDRW -o ubuntu-14.04.2-server-amd64.img ubuntu-14.04.2-server-amd64.iso
$ mv ubuntu-14.04.2-server-amd64.img.dmg ubuntu-14.04.2-server-amd64.img

USBメモリを接続してディスク番号を確認
$ diskutil list
$ df -h

USBメモリをアンマウントした上で、rawデバイス指定でimgファイルを書き込む
(下記はディスク番号が「2」の場合)
$ sudo diskutil unmountDisk /dev/disk2
$ sudo dd bs=1m if=ubuntu-14.04.2-server-amd64.img of=/dev/rdisk2
$ sudo diskutil eject /dev/disk2


[参考URL]
How to create a bootable USB stick on OS X | Ubuntu

2015年3月7日土曜日

Javaの設定を行う

現在インストールされているJDKを確認する(私の環境ではJDK6、7、8がインストール済み)。
$ /usr/libexec/java_home -V

JDK7をJAVA_HOMEとして設定する。
$ vim ~/.bashrc
$ less ~/.bashrc
(関連箇所を抜粋)
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

必要に応じてJavaVMのオプションを設定する。例えば下記の通り。
$ vim ~/.bashrc
$ less ~/.bashrc
(関連箇所を抜粋)
export JAVA_OPTS="-Dfile.encoding=UTF-8"
# または
#export JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8"

最後に~/.bashrcを再読み込み
$ source ~/.bashrc

2014年12月30日火曜日

プロキシ環境下でApache Subversionを使う

設定ファイル


~/.subversion/servers


グループ毎に個別指定する場合


アクセスするリポジトリが固定している場合はgroupsセクションで設定するのが望ましい
$ cat ~/.subversion/servers
(関連箇所のみ抜粋)
[groups]
targetgroup1 = somerepository.example.org

[targetgroup1]
http-proxy-host = proxy.example.com
http-proxy-port = 8080
http-proxy-username = foo.bar@example.com
http-proxy-password = hogepass


まとめて指定する場合


外部リポジトリにしかアクセスしない場合等はglobalセクションで一括設定すると楽
$ cat ~/.subversion/servers
(関連箇所のみ抜粋)
[global]
http-proxy-exceptions = *.internal.example.com, *.internal.example.net
http-proxy-host = proxy.example.com
http-proxy-port = 8080
http-proxy-username = foo.bar@example.com
http-proxy-password = hogepass

2014年11月26日水曜日

NSURLSessionを使ってHTTPリクエストする(Swift)

SwiftでNSURLSessionDataTaskを使って、HTTP-GET、JSONデータをHTTP-POSTする。

環境
  • Xcode 6.1
  • iOS 8.1
import UIKit

class ViewController: UIViewController {

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


    // HTTP-GET
    @IBAction func getAsync(sender: AnyObject) {
        
        // create the url-request
        let urlString = "http://httpbin.org/get"
        var request = NSMutableURLRequest(URL: NSURL(string: urlString)!)
        
        // set the method(HTTP-GET)
        request.HTTPMethod = "GET"
        
        // use NSURLSessionDataTask
        var task = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { data, response, error in
            if (error == nil) {
                var result = NSString(data: data, encoding: NSUTF8StringEncoding)!
                println(result)
            } else {
                println(error)
            }
        })
        task.resume()
        
    }


    // HTTP-POST
    @IBAction func postAsync(sender: AnyObject) {
        
        // create the url-request
        let urlString = "http://httpbin.org/post"
        var request = NSMutableURLRequest(URL: NSURL(string: urlString)!)
        
        // set the method(HTTP-POST)
        request.HTTPMethod = "POST"
        // set the header(s)
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
        
        // set the request-body(JSON)
        var params: [String: AnyObject] = [
            "foo": "bar",
            "baz": [
                "a": 1,
                "b": 20,
                "c": 300
            ]
        ]
        request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: nil)
        
        // use NSURLSessionDataTask
        var task = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: {data, response, error in
            if (error == nil) {
                var result = NSString(data: data, encoding: NSUTF8StringEncoding)!
                println(result)
            } else {
                println(error)
            }
        })
        task.resume()
        
    }
        
}

2014年10月5日日曜日

即時関数を使ってグローバル汚染を最小にする


関数単位でスコープが決まる性質を利用する。

  • 即時関数を使ってローカルスコープ化することにより、グローバル汚染を防ぐ。
  • strictモードでは関数内のthisがundefinedになるため、callメソッドを使用する。
  • 関数前の「;」はファイル連結時に不具合が出ないようにするための予防策。
<!DOCTYPE html>
<html>
<head lang="ja">
  <meta charset="UTF-8">
  <title>即時関数によるスコープ閉じ込め</title>
</head>
<body>
  <ul>
    <li id="first">1行目</li>
    <li id="second">2行目</li>
    <li id="third">3行目</li>
  <ul>
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
  <script src="./js/app.js"></script>
</body>
</html>
;(function ($) {
  'use strict';

  alert('outside ready method: this = ' + this);
  alert('outside ready method: $ = ' + $);
  alert('outside ready method: _.VERSION = ' + _.VERSION);

  $(function () {
    alert('inside ready method: this = ' + this);
    alert('inside ready method: $ = ' + $);
    alert('inside ready method: _.VERSION = ' + _.VERSION);
    $('#third').css('color', 'red');
  });

  alert('this = ' + this);
  alert('$ = ' + $);
  alert(_.VERSION);

}).call(this, jQuery);
//}.bind(this)(jQuery));

[参考URL]
知ってて当然?初級者のためのJavaScriptで使う即時関数(function(){...})()の全て - 三等兵
callで関数を即時実行すると何が嬉しいのか(と、ちょっとおまけ) - ただぱそこんしてるだけ
便利なjavascriptテクニック集 - Thujikun blog
"use strict" - blog.niw.at