2noの日記

メモ用

Ubuntu と KeePassX で AutoType

環境:Ubuntu 12.10, KeePassX 0.4.3, Python 2.7

基本的には下記ページにある python-keepasshttp を導入すれば Ubuntu でも AutoType 出来る。
http://project-p.jp/halt/?p=1779

ただ、このまま使うと都度 Ubuntu を起動した後に自分でコマンド打つ必要がある。
これは大変億劫。
やっぱり自動起動出来るのがベストよね。
という事で勝手にフォークしてパラメータとか追加したみたのがこれ。
https://github.com/wakuworks/python-keepasshttp

Usage:

$ python main.py [options] [kdb_path]

Options:

パラメータ 説明
-c, --config-file コンフィグファイルパス(デフォルト: /etc/keepasshttp.conf)
-p, --password kdb のパスワード

Config Example:

[keepass]
db_path=[kdb のパス]
output_key_path=[kdb からテキストファイルに変換した後の保存先]
password=[kdb のパスワード]

コンフィグファイルを作成した後は「自動起動するアプリケーション」を開き(「自動起動するアプリケーション」がない場合は、Ubuntuソフトウェアセンターから「gnome-session」をインストール)

f:id:wakuworks:20130311122455p:plain

python-keepasshttp/main.py を python で開く様に指定。

f:id:wakuworks:20130311122450p:plain

以上で設定完了。

Chrome に ChromeIPass のインストールを忘れないこと。 https://chrome.google.com/webstore/detail/chromeipass/ompiailgknfdndiefoaoiligalphfdae

iOS6 で ZXing 2.1 をビルドする際の注意点

参考サイト:iOSでQRコードを読み込む(ZXing 2.0) : てるてる坊主

基本的に上記サイトを参考にすればビルドできるはずだが、何故かエラーになる。
同じ状況の人が Stack Overflow で質問投げており、見事解決してくれた。
コンパイラをデフォルトに合わせる必要がある事に注意。

zxing in xcode 4.5 and ios 6 - Stack Overflow

iOS6 の Social.framework で Facebook いいねする

まずは Facebook DEVELOPERS よりアプリを作成する
https://developers.facebook.com/

作成後、設定 -> 詳細設定に移り、「App Type」を「Native/Desktop」に、「App Secret in Client」を「いいえ」にする。

f:id:wakuworks:20121105151824p:plain

オープングラフの編集より、「Like」を選択

f:id:wakuworks:20121105152350p:plain

作成すると、「Get Code」よりアクセストークンや送信する各値について書かれているダイアログが出るのでメモっておく。

Link Binary with Librariesにて「Social.framework」「Accounts.framework」を追加 。 ヘッダにSocial.hをインポート。

#import <Social/Social.h>
#import <Accounts/Accounts.h>

後は iOS に設定している Facebook アカウントを取得し、SLRequest を使って Graph API を叩けば「いいね」出来る。

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{
    ACFacebookAppIdKey : @"アプリ ID",
    ACFacebookPermissionsKey : @[@"email"]
};
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error) {
    if (granted) {
        NSArray *accounts = [accountStore accountsWithAccountType:accountType];
        if ([accounts count] > 0) {
            ACAccount *account = [accounts objectAtIndex:0];
            NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                                    @"Get Code で取得した Access Token", @"access_token",
                                    @"いいねする URL", @"object",
                                    nil];
            SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                    requestMethod:SLRequestMethodPOST
                                                              URL:[NSURL URLWithString:@"https://graph.facebook.com/me/og.likes"]
                                                       parameters:params];
            [request setAccount:account];
            [request performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
                NSLog(@"%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
            }];
        }
    }
}];

iOS6 の Social.framework で Twitter フォローする

Social.framework を使うことで、OAuth の面倒な手続きを全て iOS 側で行ってくれるので大変便利。

Link Binary with Librariesにて「Social.framework」「Accounts.framework」を追加 。 ヘッダにSocial.hをインポート。

#import <Social/Social.h>
#import <Accounts/Accounts.h>

フォローさせる為には、SLRequest を使って API にリクエストを飛ばす必要がある。
参考:https://dev.twitter.com/docs/api/1.1/post/friendships/create

if (NSClassFromString(@"SLRequest") != nil) {
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
        if (granted) {
            NSArray *accountArray = [accountStore accountsWithAccountType:accountType];
            if (accountArray.count > 0) {
                NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.json"];
                NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                                        @"フォローしたい Twitter アカウント名", @"screen_name",
                                        @"true", @"follow", nil];
                
                SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
                                                        requestMethod:SLRequestMethodPOST
                                                                  URL:url
                                                           parameters:params];
                [request setAccount:[accountArray objectAtIndex:0]];
                [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                    NSLog(@"responseData=%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
                }];
            }
        }
    }];
}

処理としては、登録している Twitter アカウントを配列で取得し、一番最初の物を使って対象ユーザーをフォロー。成功・失敗は responseData を取得して表示。

【CSS3】各ブラウザにおける rgba の誤差

各ブラウザで rgba の挙動が違う。
誤差が生じるのはアルファ値だが、以下のとおり結果が異なる。

テスト例:

var div = document.createElement("div");  
div.style.backgroundColor = "rgba(0, 0, 0, 0.5)";

各ブラウザで backgroundColor の値を確認したところ

  • Google Chrome 22.0.1229.94
    結果:"rgba(0, 0, 0, 0.498039)"
  • Safari 6.0.1 (8536.26.14)
    結果:"rgba(0, 0, 0, 0.496094)"
  • Firefox 16.0.1
    結果:"rgba(0, 0, 0, 0.5)"
  • Opera 12.01
    結果:"rgba(0, 0, 0, 0.5059)"

Firefox の結果が理想的。
各ブラウザで値の持ち回りが違うのだろうが、どう言った計算でこうなったのかは気になるところ

【CSS3】マルチカラムモジュールについて

http://www.w3.org/TR/css3-multicol/

各ブラウザに対する実装状況

現時点では、各ブラウザでかなり実装がバラバラ。

以下、ざっと調べた内容(12/10/17現在)

Internet Explorer

6/7/8 はもちろん、9 でも対応されていない。
10 に関しては調べていない。

Firefox 16.0.1

column-span に対応していない。
また、column-break-inside などには対応していない為、カラム内部の要素に対して display: inline-block を指定する事で分割を防ぐ事が可能。
columns プロパティは count の値が採用される。
-moz- プリフィックス必須

Google Chrome, SafariWebKit 系)

column-span、column-break-inside に対応している。
columns プロパティは count の値が採用される。
-webkit- プリフィックス必須

Opera 12.0.1

column-span に対応している。
また、column-break-inside などには対応していない為、カラム内部の要素に対して display: inline-block を指定する事で分割を防ぐ事が可能。
columns プロパティは width の値が採用される。 プリフィックス必要なし

マルチカラムを実現する JS