Please check your gas amount : may be misleading

I just started learning solidity development, and when I started writing my own Smart Contract - I came across this error.

Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.

truffle compile worked OK, but truffle migrate gave this error.

Usually, it is said that is there is a loop (infinite loop, due to logic error) one usually "runs out of gas"

If you purely look at the error, it seems "logical" i.e. there is no compilation error, but when deploying the smart contract you "ran out of gas"

But I was writing a really simple code - there were no loops.

Over the years, I have realized that sometimes, reviewing the code helps uncover the problem, so I did. Without looking for "loops" and such, and realized that the problem was not really runtime error.

In my opinion, this should have been caught at compile time.

To understand what was the problem, let's see some code

One thing different from usual "hello world" code was that I had two classes.

contract Animal {
    uint256 public weight;
    function name() public view returns (string);


contract Dog is Animal {

Obviously Animal is an interface, and method name() must be implemented by Dog

It is obvious looking back.

But when you are shown an error "please check your gas amount" - you may be thrown off guard.

Once I added the missing method, the error went away.

I understand solidity is a new language, and the ecosystem is yet maturing. I'm sure, eventually the error messages will become more clearer/precise or just overall "better"

In the mean time, Review your code without any bias, and you may just find the solution.

What are Uncles in Ethereum ?

Recently I started learning blockchain and related technologies.

There is SO MUCH to learn.

I started with blockchain basics (and it inevitably uses bitcoin as an example)

If you are new to blockchain (not ZERO knowledge) I recommend you checkout the blockchain demo

It is one thing to say you can not modify "old" blocks, but visualizing it really makes the difference. (It is important to understand it for the topic under discussion)

Anyway, back to "uncles".

If you know how bitcoin mining works, you know that "orphan" blocks are discarded. (i.e. yours was not the longest chain)

They also lead to "wasted" efforts, since miner does not get any reward for such blocks.

But ethereum is different.

In ethereum, such blocks are called "uncles", and it "encourages" the miners to include the uncle blocks. (and yes, miners are rewarded for uncles)

The only reason (that I understood) is that including these blocks makes the chain "heavy", and thus more secure.

(If you haven't understood why/how it becomes secure, please watch the blockchain demo again. See the link above.)

On a lighter note, but still relevant.

Someone on reddit explained these blocks as :

They are same level as your "Dad" (parent block)

They were "almost" going to be your "Dad", but didn't. Your "Dad" beat them. (i.e. Your parent block was the "longest chain", and thus "won".)

Prize Linked Savings Account


Recently I heard an episode on Freakonomics podcast called "No-lose Lottery". You can listen to the episode here

Apparently, this is a rebroadcast. Original episode was in 2010.

But those details aside, this post is to quickly summarize the concept of "Prize Linked Savings Account"

As shown in the illustration above,

The savings accounts provide you with the safety. That is your funds are always safe, and you also get some interest.

This interest may not be much, in fact there are better avenues of investment.

But each higher "potential" revenue instrument comes with higher risk.

Highest risk (and possible highest reward) comes from a lottery.

You could win a jackpot.

But most people don't.

They keep on "investing" in the hopes of winning "big" (and in the process, lose their savings)

Prize Linked Savings accounts bring the best of both worlds.

It is a savings account (so your money is safe) But the interest rate is zero

One doesn't earn anything on that money. (but like other bank account, you can take out your money any time)

But ...

There is a potential to earn "big"

Every so often there will be a winner.

MAMA - Millionaire-A-Month-Account, as the name suggests has a "draw" once every month.

Seems like a good idea, win-win, no ?

But then there come the regulators, the bureaucrats

They don't like it (for the most part, although that is changing)

Most of the times, the "lottery" industry is monopolized by the government. There is a huge revenue in this industry, so government does not want to "share the pie"

And this is not geography specific.

The podcast provides examples from US as well as South Africa.

So what can you, if you liked this idea ?

I guess try to "influence" your policy makers to allow such bank accounts ;)

What is mix.lock file

In past, I have seen several processes create .lock files, to usually write pid of the process.

e.g. Emacs' desktop package creates .emacs.desktop.lock file to save the PID of the emacs instance that created this file. Eventually, it will use this to ensure that no other instance overwrites it, and also gives a warning as such.

There have been other instances we well.

So when I started working on elixir, I always ignored mix.lock file. When I refer to other people's elixir repo on github, I always wondered why are they committing this file to git.

I have seen junior/inexperienced developers committing everything to git, including files which are built. So I ignored such "mistakes"

How naive I was.

Recently when I started working with phoenix, I bothered looking at the .gitignore file. I was surprised that mix.lock was not in it.

People who created phoenix framework are smart.

If they are smart enough to create a "default" .gitignore file, they know what they want in there.

So I looked inside the mix.lock file, and realized that it is definitely not PID :)

I should have thought about it earlier, since mix is not a long running/daemon process. So why would it need to store the PID ?

On reading the file, I realized that it is equivalent of requirements.txt files from the python world, but automatically created !

The documentation specifically asks to commit this file to version control !

Here is the relevant part of the documentation:

Dependency fetching is repeatable, Mix will lock the version of a dependency in the lockfile to ensure that all developers will get the same version (always commit mix.lock to version control). $ mix deps.update will update the dependency and write the updated version to the lockfile.

You can read up the original/details here

Turns out python is also moving towards similar .lock file mechanism over requirements.txt. See this.

Change the default Screen shot location for macOS

By default, macOS saves all screenshots to the ~/Desktop.

If you'd like screen shots to be saved somewhere else, you have to configure it manually from the terminal.

For instance, if you'd like your screenshots to be saved in the ~/screenshots directory, then enter the following commands:

$ mkdir ~/screenshots
$ defaults write location ~/screenshots
$ killall SystemUIServer


SMTPAuthenticationError : 534

One of the website suddenly stopped sending emails from the "Contact Us" form

My fellow engineer tried to debug the problem, but could not.

so I stepped in.

The first thing I tried was to verify that the username/password was correct, by logging into the gmail account via the browser.

It was.

So then I considered changing to TLS from SSL, but before I did that on production setup, I decided to do all the trials locally.

I have a sample code that takes all the mail settings, and sends a test email using python's SMTP library.

If it works, it eliminates the issues related to the "setup", which includes things like port, SSL or TLS and off course username/password combination.

My first attempt failed with the following error:

smtplib.SMTPAuthenticationError: (534, b'5.7.14 <\n5.7.14 lAhhjNCbEJP2Q5KgrvLRQlVrk8jRfKn4OfRMsdzU2DGweFba4uAvMh21nZQfU9dw5RI7Dc\n5.7.14 E7XdA9kgDEsy4cLigYxpDA_u7nkED1ljI4umnTIgygAtCziJoK3j1PJlaJPPkiXxQIqKPJ\n5.7.14 Qtz8q2piGCXlwcb999SWr4msRuYT_98tnjtZatjVolJvO4rAfI_sYWDKQP3TmrGEY_kwdF\n5.7.14 HsCkRe7iVGCExAMuCnR5GSvYiQtzc> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14 h29sm3440144pfd.145 - gsmtp')

(If you are too lazy to scroll all the way to right to see the complete error, it says Please log in via your web browser and then try again)

Since I had already tried logging via the browser, I was confused. But I tried it anyway.

May be I copy/pasted one less character.

But that was not the case. Browser login worked.

Stackoverflow to the rescue.

Turns out one needs to turn ON "allow less secure apps" option in accounts settings.

I did (Just to see whether it will work.) and test email was sent successfully.

And so did the email from the "Contact Us" form.

create and update timestamp in DB

I have following defined in my sqlalchemy models file.

class CommonColumns(Base):
 __abstract__ = True
 _created = Column(DateTime,
 _updated = Column(DateTime,,

I then derive most of my classes from CommonColumns This automatically inserts the creation and updation timestamps for the each row.

But this works for the records created via the python/sqlalchemy script using db.session.add(...)

Recently I needed to quickly insert records directly from psql prompt. Something like :

insert into user (name, age) values ('John', 25);

Since my models file does not have server_default, the record created from psql ends up with null values in the _created and _updated columns

That is when I discovered, that I can use CURRENT_TIMESTAMP in postgres. (mysql may have slightly different function name) Something like :

insert into user (name, age, _created, _updated) values ('John', 25, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

Sense of completion in org-mode

If you use org-mode to keep track of your TODO lists, then this might be useful.

Assuming you have tasks in an hierarchical manner, you should Put [/] and/or [%] in the header

Use TODO keywords in the child node, as you normally would.

When an entry is marked DONE, values are updated automatically.

In case you need to update the values manually, do C-c C-c

I needed this when I refiled the entries. They were not DONE, so automatic update did not work.

Here is how it looks :

* Plan Trip to Paris [1/3] [33%]
 * DONE Book Tickets
 * TODO Pack your Bags
 * TODO Set vacation auto-response

You can read more here

Cost of buying

In the "Tim Feriss show" podcast, Episode #248 : Ten commandments of Startup Success, there is a story about "Buying domain"

Turns out this domain was owned by 5 year old girl named Eve Rogers. How does one negotiate with a 5 year old ?

Luckily (?) the negotiations were her mom, and the price of the deal was :

  • Equity in the company (exact details not shared)
  • (Observer) seat on the board of directors for the daughter (Eve Rogers)
  • Multiple trips to Disney Land per year
  • $50000

A funny little story worth sharing ..

Sending Rich Text emails with mu4e

I recently started using mu4e exclusively for emails. I haven't opened the browser based email client in more than a week.

I almost never use "rich text" emails, so I didn't miss sending "rich" emails much.

But sometimes it is nice (useful?) to make certain word(s) bold for the impact.

and if one is using "rich text", marking code/commands in fixed width font is always nice. I always used to manually change the font in such cases, when using browser based email client.

Since my needs were relatively low, using org-mode's mark-up was sufficient.

To quickly summarize, how I was able to do that, here are the steps :

(Note : My keybindings are spacemacs default. They may be different for you)

  • Start new email using "C"
  • After entering to/subject etc, and switching to body section, do org-mu4e-compose-org-mode
  • Write email using org mode. When done, org-mime-htmlize
  • Switch to headers area (This may not be needed, but I read reports somewhere that attempting to send email when in "body" part leads to some errors)
  • Send using C-c C-c

During my first few "Test" emails, I (naturally) tried bullets, sub-bullets (like one expects to have in an org file)

This caused emails with TOC, and section numbers. It might be OK (even desirable) when exporting an org-mode file to HTML file. But in an email, that looks "odd"

This was easily cured by adding #+OPTIONS: toc:nil num:nil to the "email body"

But I don't want to (remember to) add this each time I want "rich text" email.

So these were created as global (?) settings in my .spacemacs file as follows :

(setq org-export-with-section-numbers nil)
(setq org-export-with-toc nil)

You can read about other export related settings here

I did run into a little problem (still unresolved as of this writing) See this reddit thread

Update : July 6th, 2017

I found a workaround, that "works for me, for now"

Instead of #+BEGIN_SRC if I use #+BEGIN_EXAMPLE - I don't get "bad characters"

Off course, no syntax highlighting, but at least for my use cases - I didn't need it

More over, if I were using standard browser-based email client, I do not get syntax highlighting any way.

The email (bodies) were never meant to share "code snippets"

Google Analytics Alternative