DEV.KAOLLOVE.JP ~日々の技術的なメモ~

2019/11/20

入力フォームの入力チェックを自動でする仕組み

https://github.com/koitoyou/multi-form-checker

ほんとは流行りのフレームワークを導入したりするのがスジなんだろうけど、ものおぼえが悪すぎて学習コストがかかりすぎてしまうので、簡単なものをつくれないかなと試してみた。

  <form id="auto-check-form" onsubmit="return test('#auto-check-form');">
    <table>
      <tbody>
        <tr>
          <th colspan="2">必須</th>
          <th colspan="2">任意</th>
        </tr>
        <tr>
          <th><label for="input-01">入力項目01<b class="required">(必須)</b></label></th>
          <td>
            <input type="text" name="input-01" data-required="true"><br>
            <p class="error-message error-message-required input-01" style="display:none">入力項目01を入力してください。</p>
          </td>
    (略)
  <script src="./formutils.js"></script>

主な仕様

  • 「formsutils.js」をインクルード
  • 必須項目にはinputタグに「data-required="true"」属性をつける
  • 必須エラーのときに表示するメッセージには、「error-message-required」クラスとフォーム名(name)のクラスをつけておく。予め表示されているとおかしいので、display:noneで消しておく
2019/10/16

HTML5のテンプレート

HTMLをいちから書くときのテンプレートとしてよく使うもの。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
<meta name="description" content="">
<meta name="keywords" content="">
<title>TITLE</title>
<link href="style.css" rel="stylesheet">
<style type="text/css">
<!--
/* CSSを直接書くとき */
-->
</style>
<script src="javascript.js"></script>
<script>
<!--
// JavaScriptを直接書くとき
//-->
</script>
</head>
<body>
</body>
</html>
2019/09/27

telnetコマンドの代わりはcurlで

最近のLinux環境だと、最初からtelnetコマンドが入っておらず、ネットワークの疎通試験をしたいときに不便。そういうときはcurlコマンドで代用できる。
$ curl -v telnet://www.google.com:80
* About to connect() to www.google.com port 80 (#0)
*   Trying 216.58.199.228... connected
* Connected to www.google.com (216.58.199.228) port 80 (#0)
GET / HTTP/1.0
 
HTTP/1.0 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: http://www.google.co.jp/?gfe_rd=cr&dcr=0&ei=4nrKWduvHfSQ8QeIjZGgAg
Content-Length: 271
Date: Tue, 26 Sep 2017 16:05:54 GMT
(以下略)

shellの色がキレイにつかないな...

2018/10/02

bashで乱数

bashで乱数を取得したいときは$RANDOMを参照するだけでいい。

0~4を返す乱数の例
$ echo $(( $RANDOM % 5 ))
※先頭の$はプロンプト

man bash からの抜粋:

このパラメータが参照される度に、0 から 32767 までのランダムな整数が生成されます。RANDOM に値を代入すると、乱数の列を初期化できます。RANDOM を unset すると、この変数の特殊な性質は無くなります。後で再び set しても元には戻りません。
2018/09/30

.(ドット)から始まるファイルへのアクセスを禁止する

.htaccess の基礎

Apacheのデフォルト設定で「.ht」から始まるファイルへのアクセスは禁止されているが、開発で使われそうな「.svn」みたいなファイルへのアクセスは禁止されていないので、以下のように設定する。

RedirectMatch 403 /\.

参考にしたページ:
http://tm.root-n.com/server:apache:htaccess:redirectmatch

2017/01/01

How to use Giblog😁

How to use Giblog.

Create web site

Create web site by new command.

giblog new mysite

Other prototypes is also available.

giblog new_website mysite
giblog new_blog mysite

After creating web site, change directory to mysite

cd mysite

Add new entry

Add new entry by add command.

giblog add

Build

Build web site.

giblog build

If you want to customize build process, you open lib/Giblog/Command/Build.pm and edit run subroutine.

Serve

You can serve your web site by morbo command if you have Mojolicious.

morbo serve.pl

build command is automatically executed after editting files in templates directory.

Examples

Some examples.

This is a quote.
Hello

Sub header

<><><>
1 > 2;
1 < 3;
  • Item1
  • Item2
  • Item3
Head1Head2
Item1Item2

Giblog