Hello 👋! Thanks for subscribing.
Here are the articles from last week:
Published on: 2021-06-28
tags: TIL, Unix, Shell
One of the repositories I maintain is a beginner’s GitHub repo. New developers can make their first pull request by adding their GitHub handle to a simple text file.
When pull requests get merged into the master branch, they often contain duplicates. The file has more than 7,000 lines. Names are not sorted alphabetically.
I needed a simple way to remove all duplicates lines from the file without sorting the lines.
I’m using awk
, a Unix shell program. I’m not proficient in using awk
, but I’ve found useful one-liners that do what I want.
For reference, this is how my file should look like:
# CONTRIBUTORS
- [@RupamG](https://github.com/RupamG)
- [@hariharen9](https://github.com/hariharen9)
- [@clevermiraz](https://github.com/clevermiraz)
- [@smeubank](https://github.com/smeubank)
- [@LJones95](https://github.com/LJones95)
- [@shannon-nz](https://github.com/shannon-nz)
- [@sammiepls](https://github.com/sammiepls)
Here’s how it often looks like:
# CONTRIBUTORS
- [@RupamG](https://github.com/RupamG)
- [@hariharen9](https://github.com/hariharen9)
- [@clevermiraz](https://github.com/clevermiraz)
- [@smeubank](https://github.com/smeubank)
- [@LJones95](https://github.com/LJones95)
- [@hariharen9](https://github.com/hariharen9)
- [@shannon-nz](https://github.com/shannon-nz)
- [@sammiepls](https://github.com/sammiepls)
- [@shannon-nz](https://github.com/shannon-nz)
awk 'NF > 0' file.txt
NF
is the Number of Fields Variable.
awk '!seen[$0]++' file.txt
I stole this command from opensource.com, where you can find an explanation on how it works.
awk '{print; print "";}' file.txt
See Stackexchange.
Published on: 2021-06-27
tags: Notes, Lab
In this talk, Abbey Perini enthusiastically shares her tips for showcasing your strengths for the job search as a software developer.
image credit: Karsten Winegart
Published on: 2021-06-26
tags: TIL, Unix, Shell
I’m using fd
, an alternative to the Unix native find
, to find a list of files and copy them to a different location, using xargs
. On Unix, we use cp
to copy the files, but the command is silent.
I don’t know which files cp
will copy. Maybe I could use echo
to log the files?
How can I pass multiple shell commands to xargs
?
Previous command:
fd --changed-within 1hour -0 | xargs -I cp {} /new/location/
fd -0 --changed-within
: find all files changed within a time frame, separate results by null character|
: pipe previous command as stdin
to the next commandxargs -I cp {} /new/location/
: takes the input from previous command (fd
) and uses cp
to copy the files; {}
is a placeholderWhat does not work:
fd --changed-within 1hour -0 | xargs -I cp {} /new/location/ | xargs -I echo {}
What does work:
fd --changed-within 1hour -0 | xargs -0 sh -c \
'for arg do echo "$arg"; cp "$arg" /new/location/; done' _
xargs -0
: use null as separating character (useful for files that contain whitespace)sh -c
: read commands from next string'for arg do echo "$arg"; cp "$arg" /new/location/; done' _
: loop over each input and first use echo
to log, then cp
to new location_
is a placeholder for $0
, such that other data values added by xargs
become $1
and onward, which happens to be the default set of values a for
loop iterates over.This is shell magic to me!
I found the solution on StackOverflow, where you can also find a more detailed explanation.
Published on: 2021-06-25
tags: Notes, Lab
Here are my notes from the ~ 45 min talk by Rahat Chowdhury.
Cognitive Behavioral Therapy is a talk therapy where you challenge your thoughts.
Example of an initial thought (imposter syndrome):
They gave me the job and I don’t understand why. I couldn’t finish the code challenge and the interviewer had to guide me through the process. How will I manage to do this job on my own?
Cognitive Distortions are how your mind fools you.
Examples:
Challenge your thoughts!
We need to explore the deeper reasoning behind our imposter syndrome.
Published on: 2021-06-24
tags: this_blog, Writing, Lab
Last month I decided to try to write a blog post each day.
Today’s article is the embodiment of my frustration with this experiment.
While I code every day, some days I don’t have anything interesting to share. No learnings, no insights that warrant a blog post.
Today the daily writing habit feels pointless.
I will try to keep it up for a few days more.
My new job (first job in tech!) starts next week. Will this be the time to ditch the writing experiment?
Published on: 2021-06-23
tags: TIL, Go, Unix, Fish, Shell
A Go Workspace is how Go manages our source files, compiled binaries, and cached objects used for faster compilation later. It is typical, and also advised, to have only one Go Workspace, though it is possible to have multiple spaces. The
GOPATH
acts as the root folder of a workspace. 1
I’d like to install my global binaries into a central location. These programs are third-party CLIs that I want to use everywhere in my terminal as a consumer. I don’t develop these progams.
At the same time, I’d like to make sure that my GOPATH
is correct for my actual projects that I’m working on.
Executables are installed in the directory named by the GOBIN environment variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH environment variable is not set. 2
Check the wiki for your operating system and shell.
For Unix, Fish shell:
set -x -U GOPATH $HOME/.go:$HOME/projects/go/workspace
This command sets an universal variable for both $HOME/.go
and $HOME/projects/go/workspace
.
Use fish_add_path
to add more locations to fish’s $PATH
.
To use the “global” Go binaries as well as your own workspace binaries:
fish_add_path $HOME/.go
fish_add_path $HOME/projects/go/workspace
Published on: 2021-06-22
tags: Notes, Lab
In this ~1 hour video developer advocate Sam Julien shares his tips for shipping faster:
You’ll need a system that enables you to consistently produce results on which you can get feedback on.
Action + Speed + Feedback = Growth
The problem:
The “Ultimate Guide” Trap: Trying to write a big, all-encompassing article leads to exhaustion and burn-out. You stop writing for months.
Don’t think of content (or any other skill you’re building) as a dictionary to memorize.
Instead: think like an explorer.
The secret lies in Consistent Small Wins.
Comfort is the enemy of growth.
(But self-care, too!)
Sam does not encourage the “hustle mindset”.
Do challenging things quickly and get feedback.
What?
Getting feedback:
Systems trump Motivation
Build a small but complete system.
Eliminate the distraction of figuring out where to jot something down.
Look for: speed, ease of use, ability to export.
Google Keep, Drafts app, etc.
Slow burn your drafts and link your ideas together.
Look for: cross-linking, collections, multimedia.
Evernote, Obsidian, Roam, Notion.so, etc.
Ship things faster by determining the next action and context for a project.
Look for: works with your brain, ability to add context/tags
OmniFocus, Google Keep, etc.
image credit for the cover image: Andy Li
Thank you for reading my blog.