RSSAmplifier

Blog

Home on vim, git, aws and other three-letter words

Recent content in Home on vim, git, aws and other three-letter words

serebrov.github.ioRSS feed ↗97 posts

Latest posts

Voyager keyboard: unibody mount

Voyager is a nice compact split keyboard and it has a variety of mounting options thanks to the magnetic case and the extra magnetic mounting kit that ZSA also makes. I had tripod mounts for a while and I use them for tenting, although in some situations it may be more convenient to turn the split into unibody and thinking about my options, I found a nice solution. The tripod mounts that I use…

MacBook - How to keep it on with lid closed, clamshell mode

I am testing the remote desktop to access MacBook and it is inconvenient that MacBook needs to stay with the lid open. Otherwise, if the lid is closed, the laptop goes to sleep and makes it impossible to connect to it. The solution is to have MacBook in a “clamshell mode” which is enabled when there is an external display, mouse and keyboard connected to the laptop. To emulate the…

MacBook - Remote Access from iPad

There are a few solutions to have remote access from iPad to MacBook: Chrome remote desktop Teamviewer Jump desktop SSH, Mac screen sharing app Some other options I’ll start with the simplest - Teamviewer and Jump Desktop. Teamviewer and Jump Desktop Both Teamviewer and Jump Desktop work well and the setup is easy: Install the iPad app (Jump Desktop app is $15, but it is one-time payment)…

git - how to rebase over a rebased branch, stacked branches

It is often useful to split a large change into several smaller branches and create smaller PRs which are easier to understand and review. This approach is also called “stacked branches” or “stacked pull requests”. The problem with this approach is that a modification of the earlier branch will require rebasing all branches created from it. For example, we start with this…

Profile Vue CLI Service Build (actually webpack build)

How to Profile Vue CLI Service Build (webpack build) The vue cli build is managed by the build command of the @vue/cli-service package. The command is located in node_modules/@vue/cli-service/lib/commands/build/index.js. Looking into the code, there is not too much to debug or profile here, it boils down to this: // Compose the webpackConfig object // ... // Run webpack: return new…

Vue CLI Service Build Out of Memory Error

Solving the Vue app build out-of-memory error If you encounter an out-of-memory error during the frontend build, you can increase the memory limit for the node process by setting the NODE_OPTIONS environment variable: export NODE_OPTIONS=--max_old_space_size=8192 npm run build -- --mode production Note that it should be enough to build the frontend application with the default memory limit.…

Tmux: how to run the same command in multiple panes

Why run the same command in multiple tmux panes? Sometimes it can be convenient as a quick way to run some command in parallel on the server. We can still see the output, detach from tmux and disconnect and reconnect later and attach to the tmux session to see the result. How to run the same command in multiple panes? To run the same command in multiple panes, we can use a script like this:

Touch Typing: Spacebar and Thumbs

Traditional keyboards have a large spacebar that is available for both thumbs. On split keyboards, I often see the spacebar key only on one side - left or right. But what is better? Should the spacebar be pressed by the left or right thumb? Or is it better to alternate thumbs? A collection of links to touch typing tutors and games. I was reviewing my layout and I usually have two symmetrical…

Testing FastAPI CORS settings

Testing FastAPI CORS Settings This is an example of testing FastAPI app CORS settings to see how allow_origins (the Access-Control-Allow-Origin) and allow_credentials (the Access-Control-Allow-Credentials header) parameters work practically. We wanted to make sure that we do not need the allow_credentials=True. From the docs it looks like this is the case when we want to send cookies or auth…

Google Colab notebook - input and output, OpenAI TTS API

Running OpenAI TTS API in Google Colab The example below runs OpenAI TTS API in a Google Colab notebook. The process involves some input and output: Prompt the user for API key Run the API method Save result into a file I have a notebook with two cells. First: Setup cell # @title Notebook Setup # @markdown Please, run this cell first. You'll be prompted for your OpenAI API Keys. # @markdown…

Elastic Beanstalk - how to configure access to the external RDS database

I used to configure ElasticBeanstalk access to the external RDS database by editing inbound rules for the security group attached to the database. This is inconvenient because there is always a risk of breaking something, especially if there are several environments accessing the database and we have multiple inbound rules. A more convenient method is to use a “proxy” security group:…

node - localhost connection error ECONNREFUSED ::1:4723 in node 17 and node 18

The upgrade to node 18 broke some things on CI that looked strange at first: The npx wait-on checks started showing connection errors. The webdriver.io tests for native apps failed, also with connection errors. The errors look like this: Unable to connect to “http://localhost:4723/”, make sure browser driver is running on that address. .. ERROR webdriver: RequestError: connect…

bash - how to run command in a loop until it fails

I want to debug a flaky test and run it multiple times until the test runner returns non-zero code. Here is how to do that with a one-liner: # Put the command to run into a variable, for convenience CMD="npm run test:unit -- tests/unit/MyTest.spec.ts -t \"'my test case'\"" # Run it multiple times until it fails cnt=1; while eval $CMD; do echo "Command succeeded, attempt $cnt"; ((cnt++)); done…

docker - check image size and see what takes space

There are three useful tools to check the Docker image size and see what takes space: docker image ls - show images and sizes docker image history image:tag - show image layers and size for each layer dive - a tool to inspect the image and see what each layer adds to the image Check the image size with docker image ls: docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE backend-ecs test-master…

How to inspect extension `chrome.storage` in Chrome DevTools

The extension storage is not displayed under the “Application” tab in Chrome DevTools, but it is possible to access it via the javascript console: Open some web page, open Chrome DevTools In the javascript console, select the extension context (the drop-down with “top” in it) Use chrome.storage.local to access the local storage The chrome.storage.local is a StorageArea…

git - use kdiff3 as a diff/merge tool

To use kdiff3 as your diff tool and merge tool in git, run the following commands: git config --global mergetool.kdiff3.cmd 'kdiff3 "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"' git config --global merge.tool kdiff3 git config --global difftool.kdiff3.cmd 'kdiff3 "$LOCAL" "$REMOTE"' git config --global diff.tool kdiff3 Alternatively, edit the ~/.gitconfig and add settings there: [mergetool "kdiff3"]…

How to format large JSON file in command line

There are several tools that can be used to format a large JSON file. Prettier (if you have node.js and npx installed): npx run prettier input_json.json > formatted_json.json With python: cat input_json.json | python -m json.tool > formatted_json.json # json.tool uses 4 spaces as indent by default, we can change it: cat input_json.json | python -m json.tool --indent 2 > formatted_json.json With…

git - cherry-pick a range of commits

To cherry pick a range of commits to another branch, we can use the START^..END commit range syntax, where START is the first commit in the range and END is the last commit: git cherry-pick START^..END References How to cherry-pick a range of commits and merge them into another branch?

git - how to move files with history to another repository

Git allows joining unrelated repositories via remotes which, in turn, allows moving files and change history between them. Some cases when this might be needed: Extract part of a big repository into a separate repository, preserving change history Splitting big repository to a set of smaller repositories Merge smaller repository into a bigger one (merge in library from the external repository)…

git - show number of commits by author

The shortlog -ns will show the number of commits by author: git shortlog -ns 280 Author One 46 Author Two 25 authorthree 14 au 4 x 3 Autor One 1 ide user x

git - update commit message

Simple: Change Last Commit Message To change the last commit message, use commit with --amend flag: Careful: `commit --amend` will rewrite history, do not use on public branches. $ git commit --amend It will open an editor and change the commit message, changes will be applied after saving the file and closing the editor. Advanced: Change Any Commit Message or Multiple Commit Messages Besides…

Mitosis Keyboard First Impressions

Mitosis Keyboard First Impressions I’ve received my Mitosis a few days ago and I like it a lot so far: The size: perfect for the 36 keys layout I use The shape: very comfortable, lowered outer columns feel great for pinkies I wish the inner column, for the index finger would not be shifted up as it is, it causes a bit of extension to use Y and T (not a big deal though) I also think the…

Oculus Quest for Work: First Impressions

After reading this, this and this and this, I’ve got Oculus Quest wanting to try it for work. I am a software developer and spend 8-10 hours per day before the laptop. My main machine at the moment is Mac Book Pro, I also own Thinkpad with Linux. This way, in terms of software, ImmersedVR seems to be the only contender and only compatible headsets are Oculus Go and Oculus Quest.

Vue.js Cli: How to Use Multiple vue.config.js Configs

It can be useful to have more than one configuration file, for example, to build several code bundles. The config file to use can be set with VUE_CLI_SERVICE_CONFIG_PATH environment variable: # Build using vue.config.public.js CONF=`realpath vue.config.public.js` VUE_CLI_SERVICE_CONFIG_PATH=$CONF npm run build -- --mode production # build using vue.config.js npm run build -- --mode production…

Touch Typing Tutors and Games

A collection of links to touch typing tutors and games. Online Typing Tutors keybr.com - Typing practice, supports Qwerty, Dvorak, Colemak and Workman layouts typing.com - Typing practice, free typing.io - Typing Practice for Programmers monkeytype.com - a minimalistic, customizable typing test, featuring many test modes, open source entertrained.app - practice by typing books typ.ing - typing…

AWS Config - Unexpected Charges and Data Analysis

I started seeing an increased charge in billing for AWS Config service in one of the accounts, it increased from around $5 to $100 per month. And I didn’t even remember if I enabled and configured it. I could not get any details from AWS Cost Explorer besides that charges are in the same region where our app is running. The confusing part was a note in the AWS Config management console:

Git Hook to Add Issue Number to Commit Message

When using project management system (Jira, Redmine, Github issues, etc) it is useful to add the issue number into the commit message that makes it easier to understand which issue the commit belongs to and often allows the project management system to display related commits. For same reasons, it is also useful to include the issue number into the branch name, such as 123-branch-description or…

Multi-Origin CloudFront Setup to Route Requests to Services Based on Request Path

AWS CloudFront allows to have multiple origins for the distribution and, along with lambda@edge functions, that makes it possible to use CloudFront as an entry point to route the requests to different services based on the request path. For example: www.myapp.com -> unbounce.com (landing pages) www.myapp.com/app -> single page app hosted on S3 www.myapp.com/blog -> wordpress blog CloudFront Setup…

Managing NPM packages on github

Sometimes it is simpler to keep the package on github, for example, if you have a fork of a published package with some private changes. So you can avoid cluttering npm registry with similar packages, creating confusion for other people. NPM supports installing dependencies from github, but it is also good to have versioning for your package so you can use it exactly as other packages, develop it…

Recording Linux Terminal Session to GIF with asciinema

The asciinema is a good and simple to use tool to record a screencast from the terminal session. And asciicast2gif allows to convert the recording to gif animation. virtualenv -p python3 venv source venv/bin/activate pip install asciinema $ asciinema asciinema: recording asciicast to demo.cast asciinema: press <ctrl-d> or type "exit" when you're done ... $ <ctrl-d> asciinema: recording finished…

Debugging Python with ipdb and pdbpp

To get a very convenient full-screen console debugger for python, install ipdb and pdbpp packages. Then use __import__('ipdb').set_trace() to start the debugger and enter sticky to switch to the full-screen mode. Both packages can be installed with pip: virtualenv -p python3 venv source venv/bin/activate pip install ipdb pip install pdbpp The ipdb package improves the standard (pdb) debugger by…

Formatting Parameter Blocks in Python

There are two ways recommended in pep-8 to format the blocks with long parameter lists in Python: # Arguments start on the next line foo = long_function_name( var_one, var_two, var_three, var_four) Another way is: # Arguments start on the same line foo = long_function_name(var_one, var_two, var_three, var_four) I always prefer the first option and the other one is problematic for a few reasons.…

Disqus - code formatting and highlighting in comments

It is possible to format and have syntax highlighting for code in Disqus comments. To do that, wrap the code into <pre><code> tags (see the example comment to this post). I didn&rsquo;t know about this feature and, actually, I think this is a UI flaw. It would be great to see the formatting help link or popup when you are editing the comment (and also the preview feature would be really nice to…

There Is No Callback Hell In JavaScript

There is no &ldquo;callback hell&rdquo; in Javascript, it is just a bad programming style. The infamous JavaScript &ldquo;callback hell&rdquo; can easily be fixed by un-nesting all the callbacks into separate functions. Here is an example: const verifyUser = function(username, password, callback) { dataBase.verifyUser(username, password, function(error, userInfo) { if (error) { callback(error); }…

SSH Tunnels (How to Access AWS RDS Locally Without Exposing it to Internet)

Using SSH tunnels, it is possible to access remote resources that are not exposed to the Internet through the intermediate hosts or expose your local services to the Internet. Setup To make SSH commands shorter and easier to use, edit the ~/.ssh/config and add the configuration for the hosts you are going to connect. The configuration defines default ssh options, so instead of the command like…

AWS error - Default subnet in us-east-1f not found

I suddenly started getting the Default subnet in us-east-1f not found error during the ElasticBeanstalk environment update. Failed to deploy application. Updating load balancer named: awseb-e-t-AWSEBLoa-XXXXXXXXXXXXX failed Reason: Default subnet not found in us-east-1f Service:AmazonCloudFormation, Message:Stack named 'awseb-e-xxxxxxxxxx-stack' aborted operation. Current state:…

Simple Git Workflow

The main purpose of this workflow is to have a reliable, but simple to use git workflow. It is simple enough to be used by git beginners and minimizes possibility of mistakes (comparing to advanced flows which use rebase and related git features to achieve clean history). The main idea of this workflow is that we create a new branch for every task and one developer works on this branch until the…

Setup Automatic Deployment, Updates and Backups of Multiple Web Applications with Docker on the Scaleway Server

The purpose of this setup is: Setup multiple web apps with different dependencies on the same server Link all apps to the same MySQL server Manage uploaded files for web apps in the single place (so it is easy to backup them) Automatically deploy and update apps on the remote server Run the same setup locally, so development environment is very close to production Setup backups for MySQL databases…

OOP SOLID Principles "L" - Liskov Substitution Principle

According to the Wikipedia the Liskov Substitution Principle (LSP) is defined as: Subtype Requirement: Let f(x) be a property provable about objects x of type T. Then f(y) should be true for objects y of type S where S is a subtype of T. The basic idea - if you have an object of type T then you can also use objects of its subclasses instead of it. Or, in other words: the subclass should behave the…

AWS PostgreSQL RDS - remaining connection slots are reserved error

Today I had a problem with PostgreSQL connection, both my application and psql tool returned an error: FATAL: remaining connection slots are reserved for non-replication superuser connections The PostgreSQL server was running on the db.t1.micro RDS instance and the &lsquo;Current activity&rsquo; column showed &lsquo;22 connections&rsquo; and a red line which should represent a connection limit was…

How to set up Drone CI on EC2 instance via Elastic Beanstalk

Drone CI is a Continuous Integration platform. It uses Docker containers to run tests for your application hosted on github. It is not complex to set up the automatic testing for your application and run Drone CI on EC2 instance using Elastic Beanstalk. It is even not necessary to have a dedicated EC2 instance for CI system, for example, I run it on the staging server. Drone CI setup First…

CloudWatch Logs - how to log data from multiple instances to the single stream

After using CloudWatch Logs for some time I found that it is very inconvenient to have one stream per instance. The Logs UI is really complex to use - I need to remember instance names, open the log group I need and then go into each instance logs one-by-one to check them. A more convenient alternative is to use one stream like error_log for all instances. Update: logging to the same stream from…

Elastic Beanstalk - how to set up CloudWatch Logs

CloudWatch Logs is an AWS service to collect and monitor system and application logs. At the top level, the setup is this: install CloudWatch agent to collect logs data and send to CloudWatch Logs service define log metric filters to extract useful data, like number of all errors or information about some specific events create alarms for metrics to get notifications about logs make sure that the…

Elastic Beanstalk - python application server structure and celery installation

Elastic beanstalk python application is deployed under /opt/python/. The application is running under Apache web server. Source folder structure is this: bin httpdlaunch - a tool script to set environment variables and launch httpd bundle - dir with app source code, used during updates current - symlink to the recent source code version under bundle app - application sources env - shell script…

Amazon DynamoDB - how to add global secondary index

Note: this post is outdated, because it is already possible to add a secondary index to the existing table (it was not possible in earlier DynamoDB versions). At the moment it is not possible to add a secondary index into the existing table. This feature is announced but not yet available. So the only way is to create a new table and migrate the existing data to it. This can be done using Amazon…

Local Amazon DynamoDB - tools, dump/restore and testing

Setup Download and extract dynamodb local to some folder. Launch it (-sharedDb allows us to connect to the same database with other tools): $ java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb By default it will be running on the port 8000 and will create the db file in the same directory where it was launched. Without the -sharedDB parameter the DB file name depends on…

Amazon DynamoDB, EMR and Hive notes

First you need the EMR cluster running and you should have ssh connection to the master instance like described in the getting started tutorial. Now it is possible to run Hive commands in few following ways: Connect via ssh, launch hive and run commands interactively Create a script file with commands, upload it to S3 and launch as a ERM &lsquo;Hive program&rsquo; step Run it from Hue…

AWS - Deployment via OpsWorks from the command line

Below is a simple python script which performs application deployment using OpsWorks API library (boto). Script performs following steps Execute &lsquo;update_custom_cookbooks&rsquo; deployment command and wait for successful completion (or stop with an error) Execute &lsquo;deploy&rsquo; command and wait for completion At the top there are aws configuration parameters (aws_access_key,…

AWS OpsWorks - setup mongodb ebs volume backups

I described how to setup mongodb on EC2 using OpsWorks and here is how to setup mongo data backups. In my case all mongo data is stored on the same EBS volume so I just need to make a volume snapshot. The relevant part from the mongodb docs: Backup with --journal The journal file allows for roll forward recovery. The journal files are located in the dbpath directory so will be snapshotted at the…

Amazon OpsWorks - node.js app with MongoDB setup

Amazon OpsWorks provides a way to manage AWS resources using Chef recipes. Here I describe a simple setup of the single-instance node.js app with single-node MongoDB server. It is similar to the php application + mysql setup described in the OpsWorks Getting Started guide. The OpsWorks setup includes: Stack - a container for the deployment process we will setup Two Layers - node.js app and MongoDB…