I researched how to stop auto increment of auto generated id column in CakePHP3.
Continue reading CakePHP3 How to stop auto increment on auto generated id columnShow japanese in xterm
Japanese letter is sometimes shown in incorrect way on xterm. In case that you use ubuntu with Japanese font. Here, I introduce how I made it available to show Japanese letter. (The way is also available for uxterm.)
Edit Menu
Launching xterm with some option solves the problem. So, change xterm command on menu. If you use LXDE or Gnome etc., you can change menu with property window opened by right-clicking the menu. On the dialog, change the command to xterm -fwb Sans, then wide bold letter displayed in Sans font,
In my case, I use openbox and wanted to change “Terminal emulator” menu item, which open LXTerminal, to xterm, then followed the steps below.
|
1 2 |
mkdir -p ~/.config/openbox cp /etc/xdg/openbox/menu.xml ~/.config/openbox |
Then I was ready to change menu and changed the execution command of “Terminal emulator” in ~/.config/openbox/menu.xml to xterm launching command with options.
CakePHP3 separate config file for each environment
I’ll write how to separate config file in CakePHP3 version 3.0.9. As for FuelPHP, you can add setting file into app/config/development, etc.
In the case when creating setting file in CakePHP3 for each environment, I’ll recommend you to create the directory config/development and put setting files in it, and modify configure loading code.
Modified Code
Add one line with Configure::load into config/bootstrap.php. In the following code, it’s forth line. Suppoted that $environment is set. You should define it somewhere.
|
1 2 3 4 5 6 7 |
try { Configure::config('default', new PhpConfig()); Configure::load('app', 'default', false); Configure::load($environment.'/app', 'default', true); } catch (\Exception $e) { die($e->getMessage() . "\n"); } |
At the forth line, it will merge setting file config/{$development}/app.php into config/app.php.
You can add any other conditional statement like if or switch.
Explanation
What does Configure do?
According to bootstrap.php, Configure::config and Configure::load seems to concern loading setting file. Let’s look at these functions.
Class Configure is defined at vendor/cakephp/cakephp/src/Core/Configure.php.
Configure::config
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/** * Add a new engine to Configure. Engines allow you to read configuration * files in various formats/storage locations. CakePHP comes with two built-in engines * PhpConfig and IniConfig. You can also implement your own engine classes in your application. * * To add a new engine to Configure: * * ``` * Configure::config('ini', new IniConfig()); * ``` * * @param string $name The name of the engine being configured. This alias is used later to * read values from a specific engine. * @param ConfigEngineInterface $engine The engine to append. * @return void */ public static function config($name, ConfigEngineInterface $engine) { static::$_engines[$name] = $engine; } |
According to the comment, this method adds an engine. First parameter is the key to identify added engines, seconed one is the instance of the engine. You know, if you set the engine with the same name twice or more times, the setting is overwritten by last one.
bootstrap.php adds engine new PhpConfig() as default one, with Configure::config('default', new PhpConfig());.
Configure::load
The method loads setting with the engine set with Configure::config.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
/** * Loads stored configuration information from a resource. You can add * config file resource engines with `Configure::config()`. * * Loaded configuration information will be merged with the current * runtime configuration. You can load configuration files from plugins * by preceding the filename with the plugin name. * * `Configure::load('Users.user', 'default')` * * Would load the 'user' config file using the default config engine. You can load * app config files by giving the name of the resource you want loaded. * * ``` * Configure::load('setup', 'default'); * ``` * * If using `default` config and no engine has been configured for it yet, * one will be automatically created using PhpConfig * * @param string $key name of configuration resource to load. * @param string $config Name of the configured engine to use to read the resource identified by $key. * @param bool $merge if config files should be merged instead of simply overridden * @return mixed false if file not found, void if load successful. * @link http://book.cakephp.org/3.0/en/development/configuration.html#reading-and-writing-configuration-files */ public static function load($key, $config = 'default', $merge = true) { $engine = static::_getEngine($config); if (!$engine) { return false; } $values = $engine->read($key); if ($merge) { $values = Hash::merge(static::$_values, $values); } return static::write($values); } |
First parameter specify the file to be load. When you use /, it means directory separator.
Second parameter specify the engine to handle settings, which is set with Configure::config. The identify key of the engine is expressed as $name in Configure::config, but it’s $config in here. On specifying the engine unset, return false.
Third parameter defines to merge or to overwrite. I’ll set it true, because common setting in all environments should be written in one file.
So, you can merge setting file with Configure::load(filepath, 'default', true). You know I didn’t explain the detail like Hash::merge.
If load not existing file?
You can know what will occur when you try it. But let’s look at what procedure works. According to bootstrap.php and Configure::load, the setting file will be load with read method in PhpConfig. PhpConfig is defined at vendor/cakephp/cakephp/src/Core/Configure.php.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/** * Read a config file and return its contents. * * Files with `.` in the name will be treated as values in plugins. Instead of * reading from the initialized path, plugin keys will be located using Plugin::path(). * * Setting a `$config` variable is deprecated. Use `return` instead. * * @param string $key The identifier to read from. If the key has a . it will be treated * as a plugin prefix. * @return array Parsed configuration values. * @throws \Cake\Core\Exception\Exception when files don't exist or they don't contain `$config`. * Or when files contain '..' as this could lead to abusive reads. */ public function read($key) { $file = $this->_getFilePath($key, true); $return = include $file; if (is_array($return)) { return $return; } if (!isset($config)) { throw new Exception(sprintf('Config file "%s" did not return an array', $key . '.php')); } return $config; } |
It says error will be occurred. The variable $config seems a relic on the past
When you forget ssh key passphrase
Have you forgotten ssh key passphrase before? I forgot it twice. 設定したパスフレーズではなぜか使えなかったり、パスフレーズをどこに控えたかを忘れてしまったり。 そんなときに、とても時間がかかりますがブルートフォースでパスワードを当てる方法があります。
使うもの
- john the ripper
- 総当たりをするための候補を作るプログラム。 linux だとパッケージに入っていることが多いです。
- ssh-privkey-crack.c
- キーの検証を行うプログラム。 コンパイルできる環境が必要です。
Procedure
Download
ssh-privkey.crack.cfrom lusas project. (執筆時にはダウンロードできていたのですが、時点で同じようにダウンロードできるかはわかりません。)Compile
ssh-privkey-crack.c. コンパイルの方法はプログラム内のコメントに書かれています。 私の環境ではgcc -Wall -o ssh-privkey-crack ssh-privkey-crack.c -lssl -lcryptoでコンパイルできました。 コンパイル後のファイルには実行権限をつけておきます。john the ripper をダウンロードして設定ファイルを編集します。 In my environment (ubuntu),
/etc/john/john.confwas the default configuration. それに追記する形で設定を追加しました。123456[Incremental:Pattern1]File = $JOHN/digits.chrExtra = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZMinLen = 3MaxLen = 10CharCount = 62総当たりをする場合の設定です。 File の指定は存在する chr ファイル を指定し、 Extra に chr ファイル 外 の文字で使用する文字を記述します。 chr ファイル の作り方がいまいち把握できていないのでこのようにしました。 MinLen 、 MaxLen はパスフレーズの長さの範囲を指定します。 CharCount で使用する文字の総数を記述します。 今回は 数字と大文字、小文字なので 62 です。 chr ファイルは私の環境だと
/usr/share/john/にありました。- コマンド
john -stdout -incremental:Pattern1 | ./ssh-privkey-crack ssh-private-keyfileを実行します。 最後に “-v” をつけると詳細なアウトプットが出せます。 (実際のところ MinLen = 3, MaxLen = 10, CharCount = 62 だとまず終わらないです。)
USJ 百味ビーンズ 味一覧
ハリー・ポッターに登場する百味ビーンズ (Bertie Bott’s Every Flavour Beans)、 USJで売られています。 その危ない百味ビーンズの味を一覧にしました。
| 色・特徴 | 味 |
|---|---|
| 黄色にところどころ茶色の斑点 | バナナ味。 普通のキャンディー。 |
| 濃紺 | ブルーベリー味。 普通のキャンディー。 |
| 明るいオレンジがかった赤 | チェリー味。 普通のキャンディー。 |
| 緑 | 青林檎味。 普通のキャンディー。 |
| 深緑 | 西瓜味。 普通のキャンディー。 |
| レモンイエロー | レモン味。 普通のキャンディー。 |
| ピンク | 綿菓子味。 甘くてお菓子らしい味。 |
| うすいベージュに茶色の点々 | マシュマロ味。 甘い味。 マシュマロかと言われると賛否両論出る。 |
| ピンクに青・緑・赤・黄色などの模様がまじっている | 砂糖漬け果物味。 駄菓子みたいな味。 |
| 赤茶 | シナモン味。 ニッキみたいな味でピリピリする。 |
| 黄緑 | 草味。 ほうれんそうなどとは違った、雑草のような味。 |
| 白と黒のまだら | 黒胡椒味。 こしょうを大量に舐めると考えれば、つらさが理解できるだろう。 |
| 茶色で粗びきっぽい | ソーセージ味。 焼いたおいしいソーセージではなく、生々しいソーセージの味。 |
| 白よりのうすーい水色 | 石鹸味。 誰もが石鹸だと頷ける味。 |
| まずそうな黄緑に緑の斑点 | 鼻糞味。 粘り気まで再現されており、衝撃が大きい。 |
| ベージュっぽい色 | 耳垢味。 においまで再現されており、衝撃が大きい。 |
| いやーな感じの赤茶 | ミミズ味。 ミミズが土を食べているだけあって、土っぽい味。 |
| 茶色っぽい | 土味。 飲み込むのも難しい。 |
| 黄色と白のまだら | 腐った卵味。 |
| オレンジに赤の斑点 | ゲロ味。 吐いた人も結構いるらしい。 |
草以下はやめたほうがいいです。 私の勤務先でも、USJに行った人がお土産として配っていましたが、ダメージ受けていた人が数多くいました。 一度にすべてを食べた人は、「口の中がケミストリー」と言っていました。
食べ物で遊ぶのはよくないと思うのですが。 人気商品だそうです。