Brad Lucas

Programming, Clojure and other interests

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)

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.


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.


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.


Continue reading →