Making a custom datetime in python:

from datetime import datetime
datetime(2021,1,15)

python

Make git log much more readable and compact:

git log --oneline

git

Copy a file

cp -i example.txt ~/Documents

Copy and rename

cp -i example.txt ~/Documents/file.txt

Note: -i or --interactive means you'll be asked to confirm before overwriting a file in the new destination. By default cp will overwrite any existing file with the same name.

shell

Found this Reddit post useful today, when I wanted to do some Ruby gem setup so fastlane can update itself.

Here's what the fastlane docs suggest adding to your ~/.bashrc or ~/.zshrc file:

export GEM_HOME=~/.gems
export PATH=$PATH:~/.gems/bin

But since I use fish, according the Reddit post, the same thing can be done with fish by editing ~/.config/fish/config.fish like so:

set -x GEM_HOME $HOME/gems

And a helpful note from the Reddit user who posted this solution:

"-x" for exporting to all subshells, notice that there is no "=" between variable and value you set it to.

shell

Trying out FastAPI today. Here's how to make a path:

@app.get('/', response_class=HTMLResponse)
def read_root():
    return {'Hello': 'World'}

python

fast-api

Filter out merge commits when using git log:

git log --no-merges

Or, only show merge commits:

git log --merges

git

Creating a virtual environment in python

First, create the directory for your project and cd into it.

python -m venv name_of_virtual_env

You can pass a path to venv but I like to cd into the right place first, then just use the name to create a directory where I am.

Activating the virtual env in fish:

. name_of_virtual_env/bin/activate.fish

To deactivate in fish just type deactivate

python

Use git log for particular files by passing their paths:

git log -- foo.py bar.py

You can omit the -- but it tells git the following arguments are file paths, not branch names, so always use it if your file path could be confused with a branch name.

git

Looking for a key in a dictionary in python will throw a KeyError if the key doesn't exist. We can check first if the key exists using in:

if "possible_key" in my_dictionary:
    # now we know the key exists, so we can access it
    values = my_dictionary["possible_key"]

python

Making a new object:

let user = {};

Alternative syntax (apparently this isn't common, though):

let user = new Object();

javascript

Iterate over a dictionary's keys and values

I keep forgetting you have to use .items() if you want the keys and values.

for key, value in d.items():
    # do stuff

python

Add a beta tester to TestFlight (use -g to specify groups to add the tester to, as well):

fastlane pilot add email@email.com -a com.krausefx.app -g group-1,group-2

Removing a beta tester from TestFlight:

fastlane pilot remove felix@krausefx.com -g group-1,group-2

fastlane

CSS variables

:root {
    --main-bg-color: #F7B100;
}
p {
    background-color: var(--main-bg-color);
}

css