2018年12月14日金曜日

css grid vs flex

Grid is Container-Based, Flexbox is Content-Based
This is an important difference. It shows that the flexbox layout is calculated after its content is loaded whereas the grid layout is calculated regardless of the content inside it. So, if possible, avoid using flexbox to build the overall layout of your website.

Grid Has a “Gap” Property, Flexbox Doesn’t

Flexbox is One Dimensional, Grid is Two Dimensional
Flexbox is best for arranging elements in either a single row, or a single column. Grid is best for arranging elements in multiple rows and columns.

Flexbox Wraps vs Grid Wraps
when a flex-item is wrapped and pushed in a new row, the Flexbox layout algorithm treats it as a part of a different flex-container. Hence the pushed item loses its context.

参考:https://www.webdesignerdepot.com/2018/09/grid-vs-flexbox-which-should-you-choose/

2018年8月30日木曜日

frontend validation [native browser form validation]

[Required]
<input type="text" required>

[Length]
<input type="text" minlength="3" maxlength="12">

[Pattern]
<input type="password" pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$" required>
If you provide a title attribute with the pattern, the title value will be included with any error message if the pattern doesn't match.

[Number]
<input type="number" pattern="[-+]?[0-9]">
Browser support for input[type="number"] varies, but you can supply a pattern as a fallback.

<input type="number" step="any" pattern="[-+]?[0-9]*[.,]?[0-9]+">
You can allow floats (numbers with decimals) with the step attribute. This tells the browser what numeric interval to accept. It can be any numeric value (example, 0.1 ), or any if you want to allow any number.
You should also modify your pattern to allow decimals.

<input type="number" min="3" max="42" pattern="[3-9]|[1-3][0-9]|4[0-2]">
If the numbers should be between a set of values, the browser can validate those with the min and max attributes. You should also modify your pattern to match.

[Email]
<input type="email" pattern="^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$">
The email input type will alert users if the supplied email address is invalid. Like with the number input type, you should supply a pattern for browsers that don't support this input type.

[uri]
<input type="url" pattern="^(?:(?:https?|HTTPS?|ftp|FTP):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)*)(?::\d{2,})?(?:[\/?#]\S*)?$">

[date]
<input type="date" pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))">
value is actually in this format: YYYY-MM-DD
type="time"  
type="month"


You can style fields that have errors on them with the :invalid pseudo-selector, but you can't style the error messages themselves.
CSS tip: style invalid selectors only when they aren't currently being edited with :not(:focus):invalid { }

参考:https://css-tricks.com/form-validation-part-1-constraint-validation-html/

2018年8月29日水曜日

2018年6月19日火曜日

gitの使い方

git help config
git config --list --show-origin

git config --global user.name "<Your Name>"
git config --global user.email "<Your Email>"

# makes sure that Git output is colored
git config --global color.ui auto

# displays the original state in a conflict
git config --global merge.conflictstyle diff3

git init
or git clone https://github.com/project-name your-project-name

git status

git log
git log --oneline
git log --stat
git log -p
#ignore white space
git log -w

git show fdf5493


we have some new files that we want Git to start tracking
for Git to track a file, it needs to be committed to the repository
for a file to be committed, it needs to be in the Staging Index
the git add command is used to move files from the Working Directory to the Staging Index

git add
move files from the Working Directory to the Staging Index
move modified files to the Staging Index

The goal is that each commit has a single focus. Each commit should record a single-unit change. Each commit should make a change to just one aspect of the project. Conversely, a commit shouldn't include unrelated changes

git diff
The git diff command can be used to see changes that have been made but haven't been committed, yet.

.gitignore
Globbing lets you use special characters to match patterns/characters. In the .gitignore file, you can use the following:

blank lines can be used for spacing
# - marks line as a comment
* - matches 0 or more characters
? - matches 1 character
[abc] - matches a, b, or c
** - matches nested directories - a/**/z matches
a/z
a/b/z
a/b/c/z

If you make a merge on the wrong branch, use this command to undo the merge:

git reset --hard HEAD^

When a merge happens, Git will:
1)look at the branches that it's going to merge
2)look back along the branch's history to find a single commit that both branches have in their commit history
3)combine the lines of code that were changed on the separate branches together
4)makes a commit to record the merge

When we merge, we're merging some other branch into the current (checked-out) branch. We're not merging two branches into a new branch. We're not merging the current branch into the other branch.

Git tracks lines in files. A merge conflict will happen when the exact same line(s) are changed in separate branches.

git commit --amend
git revert <SHA-of-commit-to-revert>

branchを作成
git branch <branchname>
branchを確認
git branch
branchを切り替え
git checkout <branchname>
branchを削除
git branch -d <branchname>

Merge
git merge <branchname>

fetchを実行すると、リモートリポジトリの最新の履歴の取得だけを行うことができます。取得したコミットは、名前の無いブランチとして取り込まれます。このブランチはFETCH_HEADという名前でチェックアウトすることができます。

ローカルリポジトリからリモートリポジトリにpushするときは、pushしたブランチがfast-forwardマージされるようにしておく必要があります。もし、競合が発生するような場合は、pushが拒否されます。

2018年5月11日金曜日

Truffle:是以太坊的开发环境、测试框架和资产通道。换句话说,它可以帮助你开发、发布和测试智能合约
Ganache:创建一个虚拟的以太坊区块链,并生成一些我们将在开发过程中用到的虚拟账号

Geth:Geth 是把你连接到区块链的核心应用程序,它也可以启动一个新的区块链,创建合约,挖掘以太币


truffle init  //初始化
在contracts中添加新的合约文件.sol
在migrations中添加新的js文件,通过运行将合约部署到区块链
truffconfig.js中定义连接的网络

ganache-cli -p 7545  //启动虚拟的太坊区块链,并生成测试账户
truffle compile  //将合约编译成虚拟机语言
truffle migrate --network development  //将代码部署到区块链,这里是ganache创建的development网络
truffle console --network development  //形成与development区块链交互的console


geth --datadir=./chaindata/ init ./genesis.json  //用geth来创建新的区块链
geth --datadir=./chaindata/ --rpc  //启动区块链,“--rpc” 参数让 geth 接受 RPC 连接
mist --rpc ./chaindata/geth.ipc  //连接到geth启动的区块链上,8545是默认端口

geth attach ipc:./chaindata/geth.ipc  //Start an interactive JavaScript environment (connect to node)
  miner.start()  //开始挖矿
  miner.stop()  //停止挖矿
  personal.unlockAccount('0xCe58315c7b4f4FA696473689273BD7598886Af2B','password')

在Shell上
truffle migrate --network ourTestNet  //将合约部署到ourTestNet。要在挖矿情况下,否则将不被执行
truffle console --network ourTestNet
Wrestling.address  //返回已部署的 Wresting 合约实例的地址
JSON.stringify(Wrestling.abi)  //返回 Wresting 合约 ABI(Application Binary Interface)。ABI 基本上就是对合约的描述。它包含了一个函数、变量和其他因素的列表。

2018年1月26日金曜日

JS functionの引数にfunctionを渡す使い方

1)コードを簡潔に記述できる
function putYourHeadInTheSand(otherFunc) {
    try{
         otherFunc();
    } catch(e) { } // ignore the error
}

....

putYourHeadInTheSand(function(){
    // do something here
});
putYourHeadInTheSand(function(){
    // do something else
});

2)callback、非同期になる
Lets say you load some data somehow. Rather than locking up the system waiting for it to load, you can load it in the background, and do something with the result when it arrives.
function loadStuff(callback) {
    // Go off and make an XHR or a web worker or somehow generate some data
    var data = ...;
    callback(data);
}

loadStuff(function(data){
    alert('Now we have the data');
});

3)Lazy loading
まだ理解できていない

参考:https://stackoverflow.com/questions/2824393/javascript-function-as-a-parameter-to-another-function

C# (net framework 4.5以降) zip fileを扱う

using System;
using System.IO;
using System.IO.Compression; //このLibを使う

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string startPath = @"c:\example\start";
            string zipPath = @"c:\example\result.zip";
            string extractPath = @"c:\example\extract";

            ZipFile.CreateFromDirectory(startPath, zipPath);

            ZipFile.ExtractToDirectory(zipPath, extractPath);
        }
    }
}

ちなみに、「@」を利用するとエスケープを行わずに「/」を文字列に含められるので、パスを指定したい場合などに可読性が高く、便利に使える。