海外のAppStoreに簡単に切り替える方法

iOSアプリのローカライズのためにキーワードサジェストをチェックしようと思い海外のAppStoreに切り替えようとしたところ、

abikosan.com

のような記事が検索TOPに出てかなり大変だなと思っていたのですが、もっと簡単な方法があったので共有します。

それはSafariで、

「特定の国(自分が切り替えたいと思っている国)でしか提供していないアプリを検索してURLを開く」

ということです。

例えば

Domino's Pizza USA on the App Store

はアメリカでしか提供されていないアプリなのですが、これをSafariで開こうとするとAppStoreのアプリに切り替わり

「リクエストされたアイテムは現在日本のStoreでは取扱ってはいませんが、アメリカ合衆国のStoreで利用可能です。『Storeを変更』をタップすると、このアイテムが表示されます」

とダイアログが表示されます。これでStoreを変更をタップするとアメリカ合衆国のStoreに変更されて海外のキーワードサジェストをチェックすることが出来ます。

アカウントを別に作ったりしなくても海外のAppStoreに切り替えることが出来たのでもし海外のAppStoreに飛びたい方は試して見てください。

ドミノ・ピザのアプリはそれぞれの国で専用のアプリを提供しているようなので、切り替える際におすすめです。

Macのターミナルで新規タブを開こうとしたらforkpty: Device not configuredと怒られたときの対応方法

最近macOS High Sierraにアップグレードし、ターミナル(zsh)で新規タブを立ち上げようとしたところ

forkpty: Device not configured

と怒られ新規タブを立ち上げることが出来なかった。 色々ググったところ、ptmx_maxの値が関係しているようだったので、

sysctl -a | grep kern.tty.ptmx_max

で現在の値を確認。 現在の値は512だったので、

sudo sysctl -w kern.tty.ptmx_max=768

のコマンドで試しに値を768にしてみたところ、タブをたくさん立ち上られるようになった。

設定を常に反映しておきたい場合は、/etc/sysctl.confを編集もしくは作成し、以下の記述をしておく。

kern.tty.ptmx_max=768

brew tapを用いてElasticsearch2.4とelasticsearch-headをMacにインストール

前提

  • OS
  • Homebrewのバージョン
    • 1.1.9

概要

Elasticsearchをbrewでインストールすると、デフォルトでバージョン5がインストールされたが、
https://github.com/mobz/elasticsearch-headを確認すると、

for Elasticsearch 5.x: site plugins are not supported. Run as a standalone server

とのことなので、
brew tapを用いて過去のバージョンの2.4とelasticsearch-headをインストールする。

手順

1. Elasticsearch2.4のインストール

brew tap homebrew/versions
brew search elasticsearch

elasticsearch                                  elasticsearch@1.7                              elasticsearch@2.4

過去のelasticsearchのパッケージが確認出来るので、

brew install elasticsearch@2.4

でElasticsearch2.4をインストールする。
次に、

ln -sfv /usr/local/opt/elasticsearch\@2.4/homebrew.mxcl.elasticsearch\@2.4.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch\@2.4.plist

自動起動の設定を行う。

2. PATHの設定

brew info elasticsearch@2.4

を実行すると

Data:    /usr/local/var/elasticsearch/elasticsearch_HirofumiYamamoto/
Logs:    /usr/local/var/log/elasticsearch/elasticsearch_HirofumiYamamoto.log
Plugins: /usr/local/opt/elasticsearch@2.4/libexec/plugins/
Config:  /usr/local/etc/elasticsearch/
plugin script: /usr/local/opt/elasticsearch@2.4/libexec/bin/plugin

と記述されている部分が見つかるのでこれを参考にPATHを通しておく。
今回はpluginコマンドでelasticsearch-headをインストールするので、

echo 'export PATH="/usr/local/opt/elasticsearch@2.4/libexec/bin:$PATH"' >> ~/.bash_profile

で.bash_profileを更新しPATHを通す。

source ~/.bash_profile

で.bash_profileを再度読み込みしておく。

3. elasticsearch-headのインストール

plugin install mobz/elasticsearch-head

でelasticsearch-headをインストールする。

4. ブラウザで確認

elasticsearch

でelasticsearchを起動し、
http://localhost:9200/_plugin/head/を開き、

f:id:poustel:20170204184016p:plain

が表示されていればOK。

参考リンク

qiita.com

Itamaeを用いてUbuntuにRails5をインストールする

前提

  • サーバ
  • クライアント
  • Mac側の各種バージョン
    • Ruby
      • 2.3.3
    • gem
      • 2.5.2
    • Itamae
      • 1.9.10
  • UbuntuにインストールするRailsのバージョン
    • 5.0.1

Itamaeをインストール

gem install itamae

Railsをインストールするレシピを作成

rbenvを使用しない場合

execute "ubuntu update" do
  command "sudo apt-get -y update"
end
package 'build-essential'
package 'libssl-dev'
package 'libreadline-dev'
package 'git'
package 'nginx'
package 'ruby-dev'
package 'libsqlite3-dev'
gem_package 'sqlite3'
gem_package 'rails'

rbenvを使用する場合

rbenvをパッケージからインストールすると上手くいかなかったのでgitからインストールする形にした。

REROAD_PROFILE = ". ~/.profile"
execute "ubuntu update" do
  command "apt-get -y update"
end

package 'build-essential'
package 'libssl-dev'
package 'libreadline-dev'
package 'git'
package 'nginx'
package 'libsqlite3-dev'

execute "rbenv install" do
  not_if "ls ~/.rbenv"
  command "git clone https://github.com/sstephenson/rbenv.git ~/.rbenv && git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build"
end
execute "update .profile for rbenv" do
  not_if %(#{REROAD_PROFILE} && rbenv --help)
  command %(echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile && echo 'eval "$(rbenv init -)"' >> ~/.profile)
end
execute "install ruby" do
  command "#{REROAD_PROFILE} && rbenv install -s 2.3.1"
end
execute "apply rbenv specific version" do
  command "#{REROAD_PROFILE} && rbenv global 2.3.1"
end
execute "install bundler" do
  command "#{REROAD_PROFILE} && rbenv exec gem install bundler"
end
execute "install sqlite3 for rails" do
  command "#{REROAD_PROFILE} && rbenv exec gem install sqlite3"
end
execute "install rails" do
  command "#{REROAD_PROFILE} && rbenv exec gem install rails"
end

Itamaeを実行

itamae ssh -h hostname -p 22 -u username recipi.rb -l debug

UbnutuにアクセスしてRailsがインストールされていることを確認する

$ rails -v
Rails 5.0.1

今回作成したレシピのGIthubのURL

github.com

Itamaeを使ってUbuntuサーバにNginxをインストール・起動する

前提

  • サーバ
  • クライアント
  • Macの各種バージョン
    • Ruby
      • 2.3.3
    • gem
      • 2.5.2
    • Itamae
      • 1.9.10

Itamaeをインストール

gem install itamae

Nginxをインストールし起動するレシピを作成

# nginx_recipi.rb
execute "install nginx" do
  command "sudo apt-get -y install nginx"
end
execute "nginx start" do
  command "sudo /etc/init.d/nginx start"
end

Itamaeを実行

itamae ssh -h hostname -p 22 -u username nginx_recipi.rb -l debug
INFO : Starting Itamae...
DEBUG : Executing `mkdir -p /tmp/itamae_tmp`...
DEBUG :   exited with 0
DEBUG : Executing `chmod 777 /tmp/itamae_tmp`...
DEBUG :   exited with 0
.
.
.
DEBUG :       (in set_current_attributes)
DEBUG :       (in show_differences)
 INFO :       execute[nginx start] executed will change from 'false' to 'true'
Executing `sudo /etc/init.d/nginx start`...

上記のようなコードが出ていたら成功。

サーバにアクセスしてNginxが起動していることを確認する。

ホスト名をexample.comと仮定した場合、ブラウザで http://example.com にアクセスして
f:id:poustel:20170121185647p:plain
が出ていたら成功。

【アルゴリズムの勉強】Rubyで力任せ探索で文字列探索を行うコードを書いてみる

力まかせ探索とは

力まかせ探索(ちからまかせたんさく、英: Brute-force search)またはしらみつぶし探索(英: Exhaustive search)は、単純だが非常に汎用的な計算機科学の問題解決法であり、全ての可能性のある解の候補を体系的に数えあげ、それぞれの解候補が問題の解となるかをチェックする方法である。

力まかせ探索 - Wikipedia

Rubyで実装

def brute_force_search(str, target)
  str_location, target_location = 0, 0
  while str_location != str.length && target_location != target.length
    if str[str_location] == target[target_location]
      str_location += 1
      target_location += 1
    else
      str_location = str_location - target_location + 1
      target_location = 0
    end
  end
  if target_location == target.length
    return true
  else
    return false
  end
end

p brute_force_search("today", "day")
# => true
p brute_force_search("yesterday", "tomorrow")
# => false

参考文献、参考リンク