yun's attic

Quick Fixes

Using Different SSH Profiles for Different Bitbucket Accounts

For various reasons I have multiple Bitbucket accounts with different organisations, and Bitbucket does not let you use the same SSH key for different accounts under different organisations - probably for a good reason - even though I am using the same machine to access them anyway.

This is just a reminder for myself on how to make use of the SSH config file to handle different profiles for different Bitbucket accounts, so hopefully next time I won’t have to come up with this again. This should work for any git server other than Bitbucket.

Waking Up with rtcwake and crontab

I have a couple of scripts that I’d like to run at night, but I also want to leave my machine suspended to RAM overnight to conserve energy (and reduce noise, the fan is a beast!). So this is just a note for myself about how I went about it this time, using rtcwake and crontab.

Here’s the crontab I originally had, which is triggered once a day in the afternoon:

Time Zone in Python - Tip of the Iceberg

Time zone is such a messy subject, and I don’t even know what to start with.

At my previous job I had this photo saved from a stackoverflow answer:

time zone conversion

so that every time I need to do some time zone conversion magic, I have a quick reference to go to. Because seriously, how do you expect anyone to memorize all that?

Today I’m playing with some time zone stuff again for the API with my autotrader database, and encountered a new problem/feature that somehow entirely evaded my attention in the past. In a nutshell, these two code blocks produced different results, and I couldn’t understand why:

Lateral Join with SQLAlchemy

When handling timeseries data, quite often you may want to resample the data at a different frequency and use it that way.

One way to achieve this is to load all data with Python, and resample or reindex it with Pandas.

An alternative is to query directly in SQL by using a pattern like the one below. This allows you to only get the most recent data at each sample point you’re interested in. This particular example samples the exchange rate between JPY and USD every two hours (in the actual database, I have some more recent data at 1 min intervals, and the rest at either 5 min or 30 min intervals):

Schema Names: SQLAlchemy and Alembic

I recently started working on my own autotrader. There’s still much to be done, but I’ve finished the first step – collecting data and put them in a database. I’ve got a PostgreSQL server running on Docker, and a script that reads data using the AlphaVantage API and writes to my database.

The next step would be to write my own Python API to query data from the database. The easy way for me would be to stick a bunch of SQL queries in some python functions, but why do that when you can make life more complicated! I’ve been wanting to learn about ORM, and decided this would be my chance to try it out with SQLAlchemy.