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);
        }
    }
}

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

2018年1月24日水曜日

C# delegate

A delegate is like a pointer to a function. It is a reference type data type and it holds the reference of a method.
delegate は代表の意味である。定義と同じ戻り値と引数を持つMethodを代入できる。

class Program
{
    // declare delegate
    public delegate void Print(int value);

    static void Main(string[] args)
    {
        // Print delegate points to PrintNumber
        Print printDel = PrintNumber;
         
        printDel(100000);
        printDel(200);

        // Print delegate points to PrintMoney
        printDel = PrintMoney;

        printDel(10000);
        printDel(200);
    }

    public static void PrintNumber(int num)
    {
        Console.WriteLine("Number: {0,-12:N0}",num);
    }

    public static void PrintMoney(int money)
    {
        Console.WriteLine("Money: {0:C}", money);
    }
}

A method can have a parameter of a delegate type and can invoke the delegate parameter.

public static void PrintHelper(Print delegateFunc, int numToPrint)
{
    delegateFunc(numToPrint);
}

参考:http://www.tutorialsteacher.com/csharp/csharp-delegates

2018年1月12日金曜日

vba Variantのnullとempty

値 Empty は、初期化されていない (初期値が代入されていない) Variant 変数を示します。
Null は、 Variant 変数に意図的に有効なデータが格納されていないことを示します。

2017年12月25日月曜日

vba動的array

VBAで配列のサイズを指定しないと、エラーとなる
Dim isholiday() As Boolean
isholiday(0) = checkHoliday(sWeek)

真ん中に、下記記述を入れるとOK
ReDim isholiday(endDate - startDate)

最初から以下のように指定してもNGだった
Dim isholiday(endDate - startDate) As Boolean

vba二次配列の範囲

33 x iの二次配列がある、iを取得するには、UBound(array(0))で試してみたが、エラーとなった。
UBound(array,2)でi-1の値を取得できた。