Dread Pirate Roberts

August 25, 2017

The other day I overheard a conversation among a small group picking names for a team.

The name of Dread Pirate Roberts was proposed.

Someone asked who is that and another responded with, "he was the guy who created the Silk Road".

As this happened I was thinking wasn't that the name of a character in the movie The Princess Bride.

Interesting that when you search on Dread Pirate Roberts only two links on the first page are related to the movie.


Continue reading →

Some Pyhon 2 To Python 3 Tips

August 24, 2017

A few thoughts having just tweaked a script to run under Python 3.

The newer print() function syntax works in both 2 and 3. You most likely have print "" statements in your Python 2 script. Update to the new syntax and you'll be able to work in both 2 and 3.

The write statement in the following block throws and error in 3 unless you open the file in binary mode. The following block is the updated one from my script and it runs in 2 and 3.

    with open (filename, 'wb') as handle:
        for block in response.iter_content(1024):
            handle.write(block)

I was processing the content retrieved from a web page using the requests library. In 2 it worked fine as follows:

    lines = r.content.strip().replace('}', '\n')

Under 3 I received this error:

TypeError: a bytes-like object is required, not 'str'

The fix is to decode the content before proc3essing it as follows. This block works in 2 and 3.


Continue reading →

Run A Command In Each Sub-Directory of a Directory

August 23, 2017

If you ever want to run the same command in each sub-directory of a directory consider the following example.

Replace the value for COMMAND with your own command.

$ COMMAND=pwd
$ for d in `find . -maxdepth 1 -type d`; do pushd > /dev/null $d; $COMMAND; popd > /dev/null; done

Or setup your own command by putting the following in your .bashrc file.

function run-command-in-subs {
  for d in `find . -maxdepth 1 -type d`; 
  do 
     pushd > /dev/null $d;
     $1;
     popd > /dev/null; 
  done
}

Continue reading →

Wait For An Ethereum Transaction To Be Mined

August 22, 2017

Working with testrpc hides you from one reality in particular when working with a blockchain. That is that sometimes the time to finish a transaction can take some time. The mining to fully realize the transaction not only has a cost in ether (for Ethereum) but a cost in time as you wait for your transaction to complete.

Moving your application to the testnet will show you this right away. Now, when you have this happen you'll start to wonder how to handle something like an update to your screen after the transaction is complete.

Here is a pattern that works using a function listed below that gets the promise of an Ethereum transaction when it is mined.

You call your sendTransaction then pass your transaction hash into getTransactionRecipteMined with a then in which you have your function to update your UI.

For example:

      console.log("calling initialize");
      txHash = contractInstance.initialize.sendTransaction(paramA, paramB, paramC,
                                                           {from: account, gas: 3000000});

      return web3.eth.getTransactionReceiptMined(txHash).then(function (receipt) {
        console.log("receipt");
        console.log(receipt);
        populateUI(contractInstance);
        });

How is getTransactionReceiptMined setup? I put the following at the top of my index.js file.

web3.eth.getTransactionReceiptMined= function getTransactionReceiptMined(txHash, interval) {
    const self = this;
    const transactionReceiptAsync = function(resolve, reject) {
        self.getTransactionReceipt(txHash, (error, receipt) => {
            if (error) {
                reject(error);
            } else if (receipt == null) {
                setTimeout(
                    () => transactionReceiptAsync(resolve, reject),
                    interval ? interval : 500);
            } else {
                resolve(receipt);
            }
        });
    };

    if (Array.isArray(txHash)) {
        return Promise.all(txHash.map(
            oneTxHash => self.getTransactionReceiptMined(oneTxHash, interval)));
    } else if (typeof txHash === "string") {
        return new Promise(transactionReceiptAsync);
    } else {
        throw new Error("Invalid Type: " + txHash);
    }
};

Continue reading →

Change Ethereum Account Password

August 21, 2017

If you need to change one of your Ethereum account passwords using Geth you'll find the account update command will work.

If you are running your node on the testnet make sure to pass in the –testnet flag.

Here is a sample session:

$ geth --testnet account list
Account #0: {634b8e79b0155e5ac1303c2fe4b1d30f2fc6b930} keystore:///Users/brad/Library/Ethereum/testnet/keystore/UTC--2017-03-13T18-48-40.744428053Z--634b8e79b0155e5ac1303c2fe4b1d30f2fc6b930

$ geth --testnet account update 634b8e79b0155e5ac1303c2fe4b1d30f2fc6b930
Unlocking account 634b8e79b0155e5ac1303c2fe4b1d30f2fc6b930 | Attempt 1/3
Passphrase: 
INFO [08-22|11:40:45] Unlocked account                         address=0x634b8e79b0155e5ac1303c2fe4b1d30f2fc6b930
Please give a new password. Do not forget this password.
Passphrase: 
Repeat passphrase: 

Continue reading →

Run Geth Node With Multiple Unlocked Accounts

August 20, 2017

There is a bit of a trick to run a Geth node with multiple unlocked accounts. It has to do with how to pass in the parameters.

There are two parameters to focus in on. The unlock and the password.

The first, the unlock accepts a list of accounts or a list of indexes into your account list. To keep you command line short you can, for example, pass in "0, 1" to unlock your first two accounts.

Next, you need to get your password passed in if you are starting geth from a script. The way to do this is to put your password in a file and pass that file in through the password command.

For two accounts, the trick is to use a single file for all the passwords you need to pass in. Put each on it's own line in the file. For the two account example you'd have a password file with two passwords each on it's own line.

Here is a mocked up command as an example.

geth --testnet --datadir $ETHEREUM/testnet --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --unlock '0, 1' --password '$ETHEREUM/files/p.txt'

Continue reading →

Multiple Geth Instances Warning

August 19, 2017

A point to remember when developing using geth locally. If you end up with multiple geth instances running you will get confused. Here I was running a geth instance in the background under screen. Today, not remembering it was there I started testrpc and then got the following error.

Error: Error: could not unlock signer account

So as a suggestion do a ps aux | grep geth once in a while.


Continue reading →

Coasters

August 18, 2017

Ran across this article the other day.

"Inside the world of Silicon Valley's 'coasters' — the millionaire engineers who get paid gobs of money and barely work"

What I found myself thinking about after reading it was an experience I had at a company where they had setup a similar situation after buying a startup. But, in this case the situation was different in an important way. The company put the startup people in charge of their own group and told them to run it. The acquiring company didn't put one of their own in charge. They just assumed the startup would work within the larger company without any strong tie back into the buyer.

This in hindsight turned out to be a mistake. At some point the situation between the startup people and the larger company soured and the startup people stopped participating. Without any strong leadership on the buying side and no leadership chain back into the buyer the startup people appeared to drive their business into the ground. It was a bit sad in some sense because after the initial acquisition a number of new people had been brought in. These new hires, officially employees of the buying company, had no idea the situation the startup folks had with the buyer. Over time, of course, they learned as things disintegrated.

If does seem common that larger companies fail often at integrating smaller companies they purchase. But, I can say that from this experience I would recommend that buying companies put their own loyal management in place quickly and move the original startup people out of the way as soon as possible. The incentives for everyone need to be in line. The buyer needs to incentivize their own to make the startup's technology part of the bigger whole while they leave the startup people to wait and vest and not get in the way.


Continue reading →

Send Eth From Geth Console

August 17, 2017

A log of a session showing how to check account balances and then send ETH. In this example I'm running a geth console on a local node and I want to send 10 ETH to two different accounts.

First, I list the accounts and then see how much ETH I have in the default account.

> personal.listAccounts
["0x634b8e79b0155e5ac1403c2fe4b1d30f2fc6b931"]


> web3.fromWei(eth.getBalance(eth.coinbase)); 
83.997039

Before attempting to send I need to unlock the account. This prompts you for your password.

> personal.unlockAccount(eth.coinbase)

Then I send 1 ETH to each account.

> eth.sendTransaction({from:eth.coinbase, to:"0xd60e64afb753583941e1ab42f836ced0d23af2db", value: web3.toWei(1, "ether")})
"0xbea0beb44688f49177c9e2bffa246ee4471d57a9290d5e42b9d959d3e0731d90"

> eth.sendTransaction({from:eth.coinbase, to:"0xf0c7452279d382dc41f7fb9fb59203bcb5a4239a", value: web3.toWei(1, "ether")})
"0xb118e0a48ed6acb6ae5a7a2f7c7b519b7544b1e7c5709833e5e73db48abba260"

Followed by another 9 to each account.

> eth.sendTransaction({from:eth.coinbase, to:"0xf0c7452279d382dc41f7fb9fb59203bcb5a4239a", value: web3.toWei(9, "ether")})
"0x61e7ee5629eec21be23147b0188e793daf77257d1863560cfd247212e5c671e4"
> eth.sendTransaction({from:eth.coinbase, to:"0xd60e64afb753583941e1ab42f836ced0d23af2db", value: web3.toWei(9, "ether")})
"0x4b3c20a3acb218047cfa09c96c0758fe6b55de74e8ea59d20d0e5848fef2d6cd"

Continue reading →

Org Mode Copy Just Headers

August 16, 2017

A tip for working with org-mode. The situation is where you have a large outline but want to extract just the headers. Say you want to expand only two levels and want to extract only those headers.

The key is org-copy-visible.

Expand your tree so you only see what you want to extract. Then select the tree and execute org-copy-visible (C-c C-x v).

Then paste the extracted headers somewhere else.


Continue reading →

F.Lux

August 15, 2017

Installed this interesting application on my laptop and a few other machines. It is called f.flux and it is an app that reduces the blue light in monitors in the evening. This is to prevent the stimulation that the blue light causes which ultimately effects your sleep.

So far I can say that in the evening with the new setup which has a soft orange-ish light is soothing.

The app has a very clever feature. You tell it when you typically wake up and then while you are working late it gently reminds you that you are waking up in 7 hours or some such number. A nice reminder not to over do it.


Continue reading →

Screen In Two Seconds

August 14, 2017

From a terminal window start a new screen session with the command screen. Do what you want and then when you want to detach use Ctrl-A d.

Next time you want to return to the session use screen -r.

If you ever forget if you have a session running and want to check use screen -ls.

- screen
- Ctrl-A d
- screen -r
- screen -ls

Continue reading →

Attestation

August 13, 2017

Heard and interesting phrase in the talk linked below. The word attestation jumped out as an interesting new word to me.

Blockchains allow for us to create an open, global platform on which to store any attestation about any individual from any source.


Continue reading →

Ctrl-A And Screen

August 12, 2017

If you run Screen from a terminal window you'll notice that Ctrl-A does not bring you to the beginning of the line. as a Emacs user you might find this a bit annoying.

Nicely, you can change this behavior.

I did the following:

Edit and create if necessary a file in your home directory called .screenrc and add the following to it.

escape ^^^

Continue reading →

Bootstrap Form Helpers

August 11, 2017

I was looking for dropdowns to allow a user to select a currency, a country and the date for project. They needed to be bootstrap components, look nice and work well. I found and used `Bootstrap Form Helpers' and was very pleased with the results.

If anyone else is looking for the same I'd recommend giving these components a try.

A few comments and notes which may help use them.

I used


Continue reading →