Bits and bytes of code

Bytes is my collection of short-form posts, tips, and things I learn as I build software.

URL Encode Text In Bash

In an upcoming Byte I'll be sharing a script that I built which opens pull request URLs based on Git branch names. However to do this correctly, we need to URL encode the input data. With the help of jq and 5 lines of code, we can URL encode any text we need.

ast-grep is an amazing tool for structural code search. With it, you can search for code by it's AST shape, rather than just a simple string or regex search. I've been using it a fair bit at work, and I developed a few scripts that replaced the core logic of the Flashlight project I built last year.

Tmux includes a switch-client command which allows you to switch to the previous or next session which is handy for quickly jumping between open sessions. However, it doesn't behave in the way you might expect as it orders sessions based on most recently visited, rather than when the session was created. For me, this just isn't how I think about my Tmux sessions, so I had to find another way.

If you've ever had to debug a live issue, you may have had to diagnose specific commits to determine if they could have been the cause of the issue. You might have a suspect commit, but how can you easily tell if that commit is included in the release of the app at the time of the issue?

I previously wrote a Byte about the commit-url command that I created and use frequently to copy the GitHub commit URL of the current commit. The main body of that command was determining the remote URL which can now be simplified given the new remote-url command I wrote about yesterday.

I have several bash scripts that require the remote URL of a Git repository, so a while back I wrote a script to build the URL. I recently rebuilt it with support for SSH host aliases.

For a recent work project, I had to downscale a video to a fixed size to fit into our application as designed. Though I didn't know the exact options, I new this was a perfect task for my good friend ffmpeg.

One challenge I ran into recently after starting a new role at Ramp was managing SSH authentication multiple GitHub accounts. Being able to access personal repositories like my dotfiles while also accessing work repositories which are managed by a separate GitHub enterprise account was something I hadn't done before.

I started a new job at Ramp this week, and I quickly found out that they value the number of days since the inception of the company. What started as bit of copy/paste in a slide deck, became a core part of the company culture. Wanting to join the fun, I wrote a simple shell script to keep track of how long I've been at Ramp.

While working on a recent side project, I had the idea to build a simple API like styled components that works with Tailwind. The idea is given a list of class names, create a component that you can easily share without writing all the normal boilerplate.