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 com.apple.screencapture location ~/screenshots
$ killall SystemUIServer

source

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 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvW\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  https://support.google.com/mail/answer/78754 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, default=func.now())
 _updated = Column(DateTime, default=func.now(), onupdate=func.now())

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 eve.com

In the "Tim Feriss show" podcast, Episode #248 : Ten commandments of Startup Success, there is a story about "Buying eve.com 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"

Beethoven's fifth

Beethoven's music has three distinct phases - early, mid and late. This is very uncommon, since most musicians have a "set" style through out their career. Fifth symphony was written during the "mid" part of his career.

Beethoven was working on the fifth for four years.

Beethoven had started going deaf around this time, that may be the reason parts of the symphony are "loud"

Four letter motif of the Beethoven's Fifth symphony was used by BBC during the second world war because :

  • It sounds like morse code letter "V"
  • Roman numeral for five is "V"
  • "V" for victory

Reference : Classical classroom podcast Episode 72

Using local password manager

Bit of history

Long time ago I was using LastPass. and it worked well for me for a long time, till it was acquired. I heard some "bad" things, which honestly I do not remember, but it was probably like the "free" option will go away.

I started looking for options, and chanced upon Dashlane.

Honestly it worked really well, but there is this inkling that I can't explain, that I need to move out.

I tried KeePass - but honestly, it just doesn't compare. It is a just a storage. Without ability to autofill the login pages, it is just too cumbersome.

I've been hearing great things about pass

I had tried it earlier in Feb 2017, but the companion browser addons did not work (at that time) So I went back to Dashlane (I never stopped)

Import the data from Dashlane

One of the issue was I wanted to import my existing data from Dashlane to pass. But this is not natively supported. (For various valid reasons) But there was an importer that worked with KeePass2 CSV file.

This is a python script - very well written - I might add.

It clearly documents the columns.

Dashlane has "unsecure" export option, which exports the passwords in "normal" CSV file.

The sequence of the columns required by the importer wasn't far off.

I manually fixed this issue, and populated the title column.

Upgrade. Issues

Since my pass was old, I decided to upgrade. Bunch of extensions also required relatively newer version.

brew upgrade pass

This upgraded gpg as well. Warning says "backup ~/.gnupg"

mv .gnupg .gnupg.back

Now that .gnupg was backed up, time to use the upgraded software.

brew link --overwrite gnupg
pass init <PassStore Key>
python keepass2csv2pass.py dashlane-new.csv

Most import failed because there was no gpg key

So ..

gpg2 --full-generate-key

Now python keepass2csv2pass.py dashlane-new.csv worked.

confirm using

pass about.me

Autofill aka Integration with the Browser

But pass is a command line tool. It is just a backend for storage and retrieval for the data.

For autofill, there is browserpass

There is some bug, which prevents autofill from working.

The workaround was to unlock the passstore using pass command from the terminal first. I was asked for the passphrase interactively in the terminal.

Once it was "unlocked", I had to (re) start firefox from the terminal using open -a firefox

As of this writing, see this open bugs related to gpg passphrase:

Keep the passstore up to date

One time import is never enough when switching password manager. Ability to update existing entries and creating new ones is equally important.

pass falls short here.

Inserting new entry is not easy as using Dashlane (which is very well integrated with the browser)

But "extension" are supposed to take care of that. There is already a feature request on the browserpass

None the less, here is how you do it.

pass insert group/username
Enter password for group/username:
Retype password for group/username:

I had a bit of a problem, since I had imported my old GPG keys from gpg1 to gpg2

When I used pass insert for the first time I saw the following error:

There is no assurance this key belongs to the named user

Since the working has changed a LOT (use of trustdb, as opposed to secring) I need to explicitly trust the imported keys.

The way to do this is "edit" the key and set the trust level explicitly.

# Get the list of keys
gpg2 --list-keys
# Edit the key(s) you just imported
gpg2 --edit-key <KEYID>
# When asked, choose the trust level (5) being maximum, called ultimate
# confirm with "y"

On a related note, KeePassXC, along with PassIFox looks promising. I'm waiting for this issue to be fixed so that I can continue to enable multiprocess support in Firefox.

How to use multiple versions of python at the same time

If you install python via the package manager for your OS (brew, apt-get, yum) you can have only one version of python at the same time.

At best one python2 and one python3

But if you want to have (and want ability to easily switch between) say 3.5.2 and 3.6.0 (and 2.7.2) then you should definitely consider using pyenv

pyenv is not platform specific. It installs all the versions in your home directory under ~/.pyenv

Some useful commands:

pyenv versions  # Lists the various versions on your system
pyenv install -l # Lists available versions you can install
pyenv install 2.7.0 # Install Python 2.7.0

Off course there is lot more on the pyenv page

There is a pyenv plugin that helps manager virual environments. See here

Google Analytics Alternative