脳汁portal

アメリカ在住(だった)新米エンジニアがその日学んだIT知識を書き綴るブログ

raspberryPi3のwifiを無効化する方法

raspberryPiをwifiを使わずにEthernetのみで運用する場合の方法

Wifi無効化

以下のコマンドを実行して、ラズパイを再起動すればwifiを無効化できます

sudo iwconfig wlan0 txpower off

Wifi有効化

再び有効化したいときは以下のコマンドを実行して再起動

sudo iwconfig wlan0 txpower auto

American Airlinesマイレージの有効期限を延長する方法(寄付)

他のアライアンスに比べてAAのマイルの延長は少し大変だった
ネットマイルを変換したりフライトに乗ったりすれば延長されるらしいが、今回は1000マイル寄付する形で延長する方法をメモとして残しておく

マイルの寄付

1. 以下のサイトにいき、ログインする

Donate today and help make a difference :: American Airlines

  • ページの構成が変わっていた場合は、DonateとかCharityでサイト内検索すると見つかるかも

下部にDonate miles to a causeという項目があるので、寄付の用途を選択する
(今回はMiles for Kids in Needを選んだ)
f:id:portaltan:20170424103802p:plain

2. 寄付するマイル数を入力し、Submitで寄付

f:id:portaltan:20170424104037p:plain

  • 以前は250マイルから寄付できたらしいが、現在は最小で1000マイルの寄付から可能
3. 確認

最後にマイルの有効期限が延長されているか確認して完了
48時間以内に実際に寄付が行われるとあったが、自分の環境ではすぐにマイルが減って、期限も延長されていた

ubuntu16.04でapache2の.htaccessを有効化してip制限をする

.htaccessの有効化

sudo vi /etc/apache2/apache2.conf

### 以下の行がアンコメントアウトされていることを確認
AccessFileName .htaccess

### /var/wwwの設定を変更する
<Directory /var/www/>
        Options Indexes FollowSymLinks
        #AllowOverride None 
        AllowOverride All  # NoneからAllへと変更する
        Require all granted
</Directory>

.htaccessの作成

touch /var/www/html/.htaccess
sudo vi /var/www/html/.htaccess
===================================
<Files ~ "^\.ht">
deny from all
</Files>

# AccessControl IP/HOST
order deny,allow
deny from all
allow from 123.456.789
===================================

これで123.456.789.*のIPアドレス以外からのアクセスを制限するようになった

Unityで前のシーンの情報を(無理やり)取得する

Unityは現在のシーン名は取得できるけど、一個前のシーン(つまりどのシーンから遷移してきたか)の取得がデフォルトでできない
色々試行錯誤していたのだけど、以下の方法に落ち着いた

1. データ格納用のクラスを作成

using UnityEngine;
using System.Collections;

public class Data 
{
	public readonly static Data Instance = new Data ();

	public string referer = string.Empty;
}

2. 各シーン読み込み時にシーン名を格納する

例えばscene1というシーンだったら
using UnityEngine;
using System.Collections

public class scene1 : MonoBehaviour {
	void Start () {
		Data.Instance.referer = "scene1";
	}
.
.
.
例えばscene2というシーンだったら
using UnityEngine;
using System.Collections

public class scene2 : MonoBehaviour {
	void Start () {
		Data.Instance.referer = "scene2";
	}
.
.
.

3. 遷移元のシーンによって処理を変えたいシーンでシーン名を取得する

例えばscene3というシーンだったら
using UnityEngine;
using System.Collections

public class scene3 : MonoBehaviour {
	void Start () {
		if (Data.Instance.referer == "scene1") {
			処理 1
		} else if (Data.Instance.referer == "scene2") {
			処理 2
		} else {
			処理 3
		}

		Data.Instance.referer = "scene3";
	}
.
.
.

Reference

こちらのサイトを参考にさせていただきました
【Unity】シーン間でスコアを共有 まとめ - テラシュールブログ

AWSのEC2のネットワークの速度を測定する

speed-cliを使ってAWSインスタンスのネットワーク速度の測定をします

AWS

今回は以下の環境のインスタンスを作成しました

  • Tokyoリージョン
  • t2.micro

測定方法

install speedtest-cli

sudo apt-get install python-pip
sudo pip install speedtest-cli
sudo pip install speedtest-cli --upgrade

測定

$ speedtest-cli --bytes
Retrieving speedtest.net configuration...
Testing from Amazon (*************)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by at2wn (Yokohama) [24.99 km]: 35.168 ms
Testing download speed................................................................................
Download: 37.36 Mbyte/s
Testing upload speed....................................................................................................
Upload: 13.65 Mbyte/s

こんな感じで回線の速度測定がcliで出来ました

ubuntu16.04にapacheをinstallしてbasic認証をかける

1. install apache

apt-get install apache2

アクセスできることを確認
f:id:portaltan:20170321120846p:plain

2. basic auth

touch /etc/apache2/sites-available/auth-basic.conf
vi /etc/apache2/sites-available/auth-basic.conf
### 以下を入力して保存
<Directory /var/www/html>
    AuthType Basic
    AuthName "Basic Authentication"
    AuthUserFile /etc/apache2/.htpasswd
    require valid-user
</Directory>

htpasswd -c /etc/apache2/.htpasswd hoge
  New password: ******
  Re-type new password: ******
  Adding password for user hoge

cd /var/www/html
a2ensite auth-basic
  Enabling site auth-basic.
    To activate the new configuration, you need to run:
    service apache2 reload

sudo /etc/init.d/apache2 restart

もう一度アクセスしてbasic認証がかかっていることを確認
f:id:portaltan:20170321121815p:plain