Parse Analyticsはスマホアプリの利用傾向のリアルタイム分析に便利



iOSやAndroidでは、FlurryやGoogle Analyticsがユーザの行動傾向分析によく使われる。
Flurryの集計は完了するまでに1日近くかかったりする。
Parseは、リアルタイムにイベントの発生をグラフ化してくれる。
使い方はFlurryとほぼ同じ。

すぐに集計結果が見たいというせっかちな人におすすめ。

iOS7でのアニメーションの一時的な無効化方法

アニメーションが有効な時、一部のViewの変更だけをアニメーションさせたくない場合がよくあります。
この時、いままでは以下のようなコードで実現していました:

[CATransaction begin];
[CATransaction setDisableActions:YES];
view.frame = CGRectMake(...);
[CATransaction commit];

iOS 7では、これをブロックベースで書けます:

[UIView performWithoutAnimation:^{
    view.frame = CGRectMake(...);
}];

これは短くて覚えやすい。

NSLocalizableURL

You can get it on GitHub.

Cocoa/UIKit frameworks don’t load different resources on remote server based on user’s preferred language.
This class allows you to have URLs localizable.

Localizable URL

First, you prepare multiple files for each language and their filename are like following:

  • cat-en.png
  • cat-ja.png
  • cat-zh.png

A localizable URL for those files would be:

http://github.com/foo/bar/cat-{en,ja,zh}.png

As you can see above, the URL has two-letters language code(ISO 639-1) which is gonna be replaced on run-time. You include languages in the URL which resource is available. First one is used as default.
If a user prefers Japanese language, you will get URL resolved:

http://github.com/foo/bar/cat-ja.png

If a user prefers other language that is not included in the available languages, English will be used.
It can also use with XCode style file tree:

http://github.com/foo/{en,ja,zh}/cat.png

Usage

It’s same as NSURL.

NSURL* url = [NSLocalizableURL URLWithString:@"http://github.com/foo/bar/cat-{en,ja,zh}.png"];

License

MIT License

Nagios plugin for checking I/O statistics of all disks

https://gist.github.com/noradaiko/5476125.js

Requisites

It requires iostat and bc installed on your computer.

Usage

./check_all_iostat -w tps,read,write -c tps,read,write

-w/c TPS,READ,WRITE TPS means transfer per seconds (aka IO/s)
READ and WRITE are in KBytes per seconds

Example

./check_all_iostat -w 200,100000,100000 -c 300,200000,200000

It will output something like:

OK - I/O stats tps=0.860000 KB_read/s=0.110000 KB_written/s=4.550000 | 'tps'=0.860000; 'KB_read/s'=0.110000; 'KB_written/s'=4.550000;

Note

This plugin is based on check_iostat – I/O statistics. Thanks, Thiago Varela.

Make logrotate cookbook for Chef possible to work on Ruby1.8

There is a great cookbook posted on GitHub to configure logrotation with Chef though, it may work on Ruby 1.9 or greater. My server Ruby1.8 installed couldn’t run its recipes.
I fixed a part of the cookbook so that it can also work on Ruby1.8:

https://gist.github.com/noradaiko/5219337.js

Diff is as follows:

--- a/cookbooks/logrotate/libraries/logrotate_config.rb
+++ b/cookbooks/logrotate/libraries/logrotate_config.rb
@@ -28,36 +28,46 @@ module CookbookLogrotate
       end
 
       def directives_from hash
-        hash.select { |k, v| DIRECTIVES.include?(k) && v }.keys
+                 Hash[ hash.select { |k, v| DIRECTIVES.include?(k) && v } ].keys
       end
 
       def values_from hash
-        hash.select { |k| VALUES.include? k }
+                 Hash[ hash.select { |k, v|
+                                 VALUES.include? k
+                         }
+                 ]
       end
 
       def paths_from hash
-        hash.select { |k| !(DIRECTIVES_AND_VALUES.include? k) }.inject({}) do | accum_paths, (path, config) |
-          accum_paths[path] = {
-            'directives' => directives_from(config),
-            'values' => values_from(config),
-            'scripts' => scripts_from(config)
-          }
+               pp hash
+        Hash[ hash.select { |k| !(DIRECTIVES_AND_VALUES.include? k) } ].inject({}) do | accum_paths, (path, config) |
+                 pp "----"
+          if config.instance_of?(Mash)
+            accum_paths[path] = {
+              'directives' => directives_from(config),
+              'values' => values_from(config),
+              'scripts' => scripts_from(config)
+            }
 
-          accum_paths
+                       pp accum_paths[path]
+            accum_paths
+          else
+            accum_paths
+                 end
         end
       end
 
       def scripts_from hash
-        defined_scripts = hash.select { |k| SCRIPTS.include? k }
-        defined_scripts.inject({}) do | accum_scripts, (script, lines) |
-          if lines.respond_to? :join
-            accum_scripts[script] = lines.join "n"
-          else
-            accum_scripts[script] = lines
-          end
+          defined_scripts = hash.select { |k| SCRIPTS.include? k }
+          defined_scripts.inject({}) do | accum_scripts, (script, lines) |
+            if lines.respond_to? :join
+              accum_scripts[script] = lines.join "n"
+            else
+              accum_scripts[script] = lines
+            end
 
-          accum_scripts
-        end
+            accum_scripts
+          end
       end
     end

Hope it helps.