Monday, 24 October 2016

VS Code for GO - get a function list

I have been using VS Code to design my GO code ever since my last MacBook died of caffeine poisoning (don't ask).

I had been using UltraEdit since 1998 and had found nothing that really changed my mind but I had been exploring VS Code for Ethereum work.

The new MacBook was supposed to be a temporary fix but four months on and no sign of the old MacBook back, it is looking quite permanent now.

So -what do I like about it? A lot. And I am learning more every day.

Today's tip

UltraEdit used to have the option of showing a list of functions in a separate pane. I could not find this in VS Code. Here is how to do it.

Cmd+P pops up the action entry box

Type a '@' in this box and you get a list of the imports, variables, functions etc. in your current file.

Selecting one of these takes you to the correct place in the file.

Sunday, 4 September 2016

POSTGRES - Change money field to Integer....

So, we had a table with a money field when all of a sudden we realised that it would make a lot more sense for the amount to be expressed in cents instead of in dollars.

$ 1234.56 would now become 123456

I am sure that there is a far better way to do this but - I am an occasional DB admin and so I figured that I needed to

  1. Convert dollars to cents
  2. Convert Money to Integer
#1 was easy : update bills set amount=amount*10;


#2 was a bit more tricky. Very hard to convert Money to Int.

amount::varchar does, however, yield a string so

Create a new int column:

Alter table bills add column iamount int;

Then copy the correct amount into it:

update bills set iamount =
     replace(substr(amount::varchar,2,length(amount::varchar)-4),

     ',','')::int;

Then drop the old column and rename the new....


alter table bills drop column amount;
alter table bills rename column iamount to amount;

Thursday, 30 June 2016

Compiling GO code for the BeagleBone Black

One thing I love about GO is that you can cross compile code for different platforms. 

The Ethereum Foundation use this feature to create developer releases of GETH (the ethereum node written in GO) to many platforms relatively quickly.

It also means that I do not need to wait ages for a slow processor like the Raspberry Pi 1 or the BeagleBone Black to make the build, I can do it from my MacBook.

I first learned how effortless it was from Audrey Lim's go-snap project

There are more details about cross compiling for ARM in the GoArm Wiki

So finally - to compile on Linux or a MacBook for the BBB*

# GOARCH=arm GOOS=linux GOARM=7 go build myBBBprogram.go

Once it has finished you should have a cross compiled executable. All you have to do is to transfer it to the BBB with scp or an sftp utility and you are in business!

*or on a PC if you really have to...

Set Fixed IP Address on BeagleBone Black (Debian)

After a couple of years of serious distractions, I dragged my BeagleBone Blacks out of the cupboard and am putting them to use hosting test software in the office so that people can access them while I am away.

I downloaded the latest Debian because it seems that Arch had not been updated recently

Many things have changed, in particular the connection manager but it is a very simple process.

These commands may require running as root (via Sudo or su)

First find your service name (I have truncated the names of mine for brevity)

connmanctl services
your_network_id            wifi_000c


Then set the IP address, netmask and gateway address

#connmanctl config wifi_000c --ipv4 manual 192.168.0.200 255.255.255.0 192.168.0.1

If you have logged in via SSH and are entering the commands remotely, the BBB will now freeze because you have already changed the IP address and so your connection is frozen.

Reboot and your connection is up on the new address.

Tuesday, 5 April 2016

Getting Started with Ethereum

It has become clear that Cryptocurrencies are not so much about using the currency as a means of saving or speculation, more about using their key features on which to build a platform that has value and doing so in a more secure, flexible and inexpensive way than were possible without the technology.

The result of this is that, while you still see many people mining Bitcoin, stashing it and praying for the value to increase back to the glory days, there are many more services that buy and re-sell bitcoin almost instantaneously in different markets, using the technology as a way of transferring value around the world at the speed of light.

But still, Bitcoin was a currency. Ripple, Stellar and their spinoffs moved this forward by being an asset trading platform. The ripple and stellar currencies were merely the oil for the machine, the value being the incentive for miners to keep the wheels of the processing nodes turning.

Stellar has some excellent features. Automatic exchanges can be set up - and peer exchanges - anybody who deals in two assets may propose exchange rates - and the best will win. But at the end of the day, they are still rigid systems and you need to build a system to take advantage of them.

A couple of years ago there were (if you will pardon me for saying it) ripples in the ether. A paper had been written proposing what were called "smart contracts".

Smart contracts are small programs inserted into a blockchain which get run every time somebody wants to interact with them. People who want to use a smart contract have to pay for the privilege because thousands of people worldwide are expected to offer computing power to run these programs. The programs themselves are ultimately very flexible - written in languages similar to Javascript or Python.

At the time of writing Ethereum, the result of all this work, is starting to take the crypto world by storm. While still officially in Beta, people are using it to manage all kinds of things - from auctions and trading systems to online gambling.

OK, I hear comments. That is a huge amount of verbosity. What's the point?

The main point is that I am exploring Ethereum and have been doing a bit of coding. Some of it digs quite deep into the Ethereum source Code.

In the process, I am building some useful libraries which I will be sharing in a way that allows us to explore the power of Ethereum.

Expect to hear from me soon.