Wednesday, July 25, 2018

Pyenv folder (.venv) with Pipenv

Pipenv, by default will use your virtualenv folder location if you set that environment variable - which probably be a .virtualenv or .env folder in your home directory.

But sometimes you would like to have the virtualenv folder within the project folder - ie. project/.venv No sweat, pipenv supports this workflow if set the PIPENV_VENV_IN_PROJECT environment variable.

For Macs: $ export PIPENV_VENV_IN_PROJECT=1

For Windows: > set PIPENV_VENV_IN_PROJECT=1

Do note that in Windows, you can also use setx.

Then we can run either a: pipenv install or pipenv --three to get started.

Friday, May 25, 2018

Cleaning up your local repo from too many dead branches

You'll eventually have too branches in your local that's untracked - ex. Not in origin or Github. This gets annoying since too many of these branches are often dead. So time to prune them:

git remote prune origin

You would assume that would work but nope. This only works on the remote repo and not your local. But you can to do this:

git branch --merged master | grep -v '^[ *]*master$' | xargs git branch -d

This is uncomplicated since this just soft deletes all branches that are already merged - the -d flag in git branch.

But if you need to check against the remote repo then a more complex command is called for:

git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d

The only rub here that is only works on bash or zsh shells. Also you need to run git fetch --prune first because using this.



Wednesday, May 9, 2018

Understanding the two kinds of smart contracts

Stellar is a platform built with Blockchain that enabled someone to build a financial system like say a payment system. One feature on Stellar is Stellar Smart Contracts (SSC) and I've been trying to wrap my head around it.

So what is a smart contract? An SC is just an agreement between 2 or more parties formalised over a computer network. Think paper contracts but with a computer network as a witness. The catch is that there are TWO kinds of smart contracts - Turing complete OR non-turing.

Turing complete SCs like Ethereum's Solidity include code that EXECUTES ON THE CONTRACT when given certain inputs. What can be executed is still subject to constraints on the contract like say time - ie. You can execute this contract after 48 hours.

Non-Turing complete SCs like Stellar's do not include code with the contract. So you have to execute the contract on your side - ie. your own server. But similar to the other type of SC, what can be executed is still subject to constraints.

Turing complete SCs are like self contain black boxes with buttons and sensors. It does stuff on it's own based on what button is pressed or what the sensors pick up.

Non-Turing SCs on the other hand are like those hand-crank jack-in-box toys, who (when, how, etc.) can crank it defined is identified on the toy. On it's own it doesn't do much. It just sits there.

So what use cases are talking about?

Non-Turing SCs seem to be pretty good for escrow type transactions. Stellar's SC examples are in fact, escrows.

Turing complete SCs seem to fit into long term, repeating type transactions like retirement payments.

Which one to use? I can't say. I've been learning Stellar via a Python SDK. It's been interesting so far.