TIL: How to Run Your Scripts From Everywhere

I've been writing a few bash scripts and some Nim command line utilities. You can run a script from the folder which contains the script. Here's an example file structure: ~/bin/ ├── git-reset-author.sh └── readme_template When I'm inside the ~/bin directory, I can type into the terminal: readme_template. But what if I want to navigate to a different folder on my machine and run the script from that location? fish: unknown command readme_template The shell doesn't find the program.
Read more →

TIL: Docker Debugging and Exit Codes

Read more →

TIL: JupyterLab: Run All Cells

Read more →

TIL: Docker: chown Copies All Files

Docker builds containers via layers. All commands add another layer to the already existing image. What does that mean for changing file permissions via chown or chmod? Let's say we build this image: FROMfrolvlad/alpine-miniconda3:python3.7 AS build# set working directoryWORKDIR/usr/src/app# copy codeCOPY ./code /codeCOPY ./notebooks /notebooks# add non-root userRUN addgroup –system user && \ adduser –system -G user user && \ chown -R user:user /usr/src/appAfter copying the code from the host machine to the container, we switch permissions for the working directory from root to user.
Read more →

TIL: kitty @ set-colors

kitty is the terminal emulator that I use in conjunction with fish. Kitty is fast, customizable, and has font ligatures. When I start a Vim session from the kitty terminal, Vim looks smooth (I use Victor Mono as my font). If you want to switch kitty's color scheme, you can use kitty @ set-colors –all <path-to-colors-file> to interactively switch colors in your session. I wrote a fish function that uses kitty @ set-colors and sed to switch colors for both kitty and (Neo)Vim.
Read more →

About Docker DNS and Networking

Read more →

TIL About 3factor app

Read more →

TIL: PostgreSQL Insert ID Only Works With id as Primary Key

I've created a database table for my PostgreSQL database with Nim: import db_postgres, os # some code proc setup*(database: Database) = database.db.exec(sql""" CREATE TABLE IF NOT EXISTS Url( shortcode SERIAL PRIMARY KEY, orig_url VARCHAR(255) NOT NULL ); """)# more codeMy primary key is shortcode as a SERIAL data type. That means the shortcode column automatically increments. I want to insert data into the database and return the generated ID for the row.
Read more →

TIL: You Can't Mount Host Volumes Into Docker During Build

Today I learned that you can't bind-mount folders on your host machine into a Docker container during build. For local development, I bind-mount with docker-compose. Example: version: '2.4'services: url-shortener: build: context: ./services/url-shortener dockerfile: Dockerfile volumes: - './services/url-shortener:/usr/src/app:delegated' ports: - 5001:5000My goal was to use the language's package manager to install the required dependencies. Here's the Dockerfile:

base imageFROMnimlang/nim:1.0.4-regular AS build-image# set working directoryWORKDIR/usr/src/app# install dependenciesRUN nimble refresh && nimble install -y# run serverCMD nimble c -r src/urlShortenerHere is the problem: nimble can't find the required files for installation.

Read more →

TIL: Objects in Nim

Objects in Nim use the type constructor:

Type Definition type MusicTrack = object index: int title: string # (Mutable) Value var summer = MusicTrack(index: 1, title: "Summer in the City") That reminds me of Records in Reason:

/* Type definition */ type musicTrack = {index: int, title: string} /* Value */ let summerInTheCity = {index: 1, title: "Summer in the City"} In Nim, “An object is a value type, which means that when an object is assigned to a new variable all its components are copied as well.

Read more →