たれぱんのびぼーろく

わたしの備忘録、生物学とプログラミングが多いかも

Node.js プロジェクト開始手引き

  • git init
  • npm init

gitは.git directory,
npmはpackage.json
が命
これさえあればgitとnpmが消えても大丈夫(のはず)
でもコード自体が吹き飛ぶと元も子もない. なのでGitHubのプライベートリポジトリをリモート.
これで万事オッケー!
復旧したいときはGitHubから落としてきて、npm installかな?

gitにバージョンとかあるのか
node.jsのバージョンってpackage.jsonに載ってる?

GitHubのさらなるバックアップを取るか否か
GitHubは手動で触るから、誤操作のリスクが高いのよね

electronはnpm installで何とかなるのか…?

再代入できる世界とできない世界の違い

今、数学の世界にいます

x = 1
y = x + 2
yは? => 3 (当然だろ)
-----------------------
今、プログラミングの世界にいます

x = 1
x = x + 2
xは? => 3 (当然だね)

相変わらず、プログラミングの世界にいます
x = 1
■■■■
x = x + 2
xは? => …確定しない。だって■■の中を見ないとわからん.
■■が空行だったら x == 3 だろうけど、
■■が x = x + 1だったら x == 4だもん.
-----------------------
数学の世界に戻りました

x = 1
■■■■
y = x + 2
yは? => 3 (当然だろ)

数学をするときに、 x = x + 1はしません.
つまり、数学では再代入をしません.
逆に言えば、プログラミングでは再代入が認められます.
そして上記の例が示したように、再代入を認めると、全ての式を見ない限り、値が確定しないのです.

現物を対価とする第三者割当増資

現物出資とは、金銭以外の財産による出資をいいます。動産・不動産・債権・有価証券・無体財産権のほか、事業の全部または一部も現物出資の目的物とすることができます。第三者割当増資の方法で行われる事が多いですが、株主割当増資、第三者割当増資のいずれの増資についても認められます。株式譲渡制限会社において、第三者割当増資の方法による現物出資を行う場合は、原則として株主総会の特別決議を経る必要があります。
capitalevolver.com

アイデア出し

イデア出し

定義

「アイデア」とは

「出し」とは

なにがアイデア出しではないか

手法

手法とは

・好き勝手ではない ・枠組み
 →枠組みとは。トートロジーではないか
・決まり・規則
 →従うべき約束
→すべきこと・してはいけないこと
    →義務・推奨・禁止

なにが「手法」ではないか

イデア出しの手法

手法の分類

分類の観点
* 必要資源 + 人数 + 時間 + もの(物資、道具) + 金銭 *

千三つ

blogs.yahoo.co.jp

おそらく事業計画ベースできちんと検討された事業を分母として計算すれば成功確率は何十%ということになるのではないでしょうか。

新規法人の年次死亡率を業種ごとに調査

ideasity.biz

Node.js stream

ReadableとWritable

Sourceからreadして処理をしていくので、Readable streamがSource相当.
writeしてあとはおまかせーと吸い込んでいくので、Writable streamがSink, distination相当.

Readable streams are an abstraction for a source from which data is consumed.
Writable streams are an abstraction for a destination to which data is written.

Readableの使い方

  1. callbackをセットして、callbackを自動でcallしてもらう
  2. Writable streamとつなぐ
  3. .read()を手動でcallして、出てきたデータをつかう

Readableの詳細

2つのモード: flowing, paused
flowingモードだと、イベントを発火しながらデータを吐き出し続ける
pausedモードだと、.read()をcallしてデータを取り出す
デフォルトではpausedモード.

Readable streams effectively operate in one of two modes: flowing and paused.
provided to an application as quickly as possible using events
In paused mode, the stream.read() method must be called explicitly to read chunks of data from the stream.
All Readable streams begin in paused mode

.read()はどれくらい取り出すか指定できる

If the size argument is not specified, all of the data contained in the internal buffer will be returned.

.read()は推奨されてない

In general, it is recommended that developers avoid the use of the 'readable' event and the readable.read() method in favor of using either readable.pipe() or the 'data' event.

Writableとcallback()

writable.write()

writable.write()でデータの書き込み。
internal bufferがいっぱいになるとfalseを返してくる。無理やり書き込んでもinternal bufferにバッファーされるが、当然良くないよ。いっぱいになったのち、internal bufferが消費されて空っぽになると "drain"イベントが発火される.

The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk. If false is returned, further attempts to write data to the stream should stop until the 'drain' event is emitted.
無理やり書き込んでも…
While a stream is not draining, calls to write() will buffer chunk, and return false.
再開は
Once all currently buffered chunks are drained (accepted for delivery by the operating system), the 'drain' event will be emitted.

writable._write()

._write(chunk, encoding, callback)の形でcallbackを取る.
callbackは"write"の成功または失敗を伝えるために呼び出される.

The callback method must be called to signal either that the write completed successfully or failed with an error.

._write()の実行 -> callbackの呼び出しとなるが、callbackが呼び出される前に追加で.write()がcallされた場合、.write()のデータはinternal bufferにバッファーされる.
callback()がcallされると"drain"イベントが発火される.

It is important to note that all calls to writable.write() that occur between the time writable._write() is called and the callback is called will cause the written data to be buffered.
Once the callback is invoked, the stream will emit a 'drain' event.

callbackの使い方

成功時には第一引数にnullを、失敗時には第一引数にError objectを渡す。

The first argument passed to the callback must be the Error object if the call failed or null if the write succeeded.

内部バッファ

internal buffer, internal queue

internal-bufferにデータがたまっていく.
highWaterMark以下の場合、内部的にstream.read()がcallされる.
新しいstreamを作る際、
read()をoverrideし、_read()内でstream.push(chunk)をcallすれば、internal-bufferにchunkがenqueueされる.

generator使ったやり口案.
generatorをstream constructorで作る.
read()内でgenerator.next()をcallする. chunkがyieldされ、yieldされたchunkをstream.push(chunk)する. このread()1サイクルは以上で終了.
次の_read()サイクルでまたgenerator.next()がcallされる. chunk2が(ry. これでstreamの流量制限を利用しながらchunkを渡せる.

When chunk is not null, the chunk of data will be added to the internal queue for users of the stream to consume.

push it into the internal buffer.

If the internal read buffer is below the highWaterMark, and the stream is not currently reading, then calling stream.read(0) will trigger a low-level stream._read() call.

Buffering# Both Writable and Readable streams will store data in an internal buffer that can be retrieved using writable.writableState.getBuffer() or readable.readableState.buffer, respectively.

Data is buffered in Readable streams when the implementation calls stream.push(chunk). If the consumer of the Stream does not call stream.read(), the data will sit in the internal queue until it is consumed.

Once the total size of the internal read buffer reaches the threshold specified by highWaterMark, the stream will temporarily stop reading data from the underlying resource until the data currently buffered can be consumed (that is, the stream will stop calling the internal readable._read() method that is used to fill the read buffer).

Data is buffered in Writable streams when the writable.write(chunk) method is called repeatedly. While the total size of the internal write buffer is below the threshold set by highWaterMark, calls to writable.write() will return true. Once the size of the internal buffer reaches or exceeds the highWaterMark, false will be returned.

複数chunkの同時処理

_writev()

The writable.writev() method may be implemented in addition to writable.write() in stream implementations that are capable of processing multiple chunks of data at once. If implemented, the method will be called with all chunks of data currently buffered in the write queue.
If a stream implementation is capable of processing multiple chunks of data at once, the writable._writev() method should be implemented.
https://nodejs.org/api/stream.html#stream_writable_writev_chunks_callback

node-auto-launch

electronのスタートアップ登録を可能にする不思議ライブラリ

node-auto-launch
← node-winreg
← child_process.spawn

github.com

Child Process Node.js v0.11.11 Manual & Documentation

node.jsはそもそもコマンドラインを叩けるらしい.
子プロセス云々.
そこでレジストリ編集のコマンド叩いてる.

全く知らなかった。
C言語popen()で新しいプロセスを起動できるらしい.
popen(“node xxx.js”)みたいな
こやつらを裏で叩いてるんだな多分.