Helpful Bash Script - git reset all

22 Sep 2021

I use this script at work and at home. It saves me a lot of time when I need all of my local repositories to be up to date with the master branch.

It’s a simple script - it iterates through a folder (in my case, ~/Documents) and checks each directory to see if it’s a valid git project. If so, it checks out master and fetches the latest commits. Optionally, you can also have the script delete all branches other than master. You can also (again, optionally) run yarn install in any directories with a yarn.lock file.

If you go on vacation for a week and come back to all of your repositories out-of-date, this script is a lifesaver.



# Ensure we're in the correct directory (update this directory to your preference)
cd ~/Documents

# Loop through each sub-directory and perform some work on them
for f in *; do

    if [ -d "$f" ]; then

        # Ignore this directory when making changes
        if [ "$f" == $IGNORED_DIRECTORY ]; then
            echo "Ignoring $IGNORED_DIRECTORY"
            continue 1

        cd "$f" # $f is a directory, so we can cd into it

        if [ -d .git ]; then
            # This directory has a .git directory :)
            git reset --hard
            git clean -d -f
            git checkout master
            git pull

            ### Warning: This will delete ALL local branches aside from master!
            # Only uncomment if you really, really want this!
            # git branch | grep -v "master" | xargs git branch -D

            ### Warning: This installs all yarn packages in all directories
            # Very slow, but very useful!
            # if [ -f yarn.lock ]; then
            #     echo "yarn.lock exists, installing packages."
            #     yarn install
            # fi

            echo "/${f}/ does not have a .git directory."

        cd ..


Get a Pull Request by Number - Bash Function

22 Sep 2021

If you’re working on an open-source project, you’ll find yourself frequently pulling down other people’s PRs. Here’s an easy command to add to your .bash_profile that lets you easily “git” (hehe) a PR by just providing the PR number.

# Add this to your .bash_profile
# Just pass a number (e.g. 451) and the branch will be pulled down for you
# Great for working with lots of forks
gitpr () {
  git fetch origin pull/$1/head:pr/$1 && git checkout pr/$1


# Call `gitpr` with the number of the PR you're trying to pull down
gitpr 451

# That's it! You'll be switched to branch 'pr/451' and ready to review!

Creating Effective Presentations with stock Apple applications

21 Sep 2021

When you don’t have access to advanced editing software (i.e. on work devices), sometimes you’re going to need to abuse the stock applications installed on your Mac.

I like to use:

  • iMovie
  • Quicktime Player
  • Keynote

For creating images for animations, I like to use SimpleDiagrams4, which is free for a 7 day trial and then 50 bucks. Super worth it IMO.

Creating Diagrams

As mentioned, I use SimpleDiagrams4. I make sure I download all of the free libraries on their site so I have a large range of shapes and icons to work with.

I make the Document size 4000x4000px. This lets me zoom around the diagram later without ugly aliasing effects when I zoom in.

SimpleDiagrams4 does not support animation, but you can create different frames and export them. We’ll animate them in Keynote later.

When you’re happy, export your diagrams as a PNG file, and uncheck the Export background option - we want a transparent background.

Animating Diagrams

This part takes a lot of finesse. Import your SimpleDiagrams PNG file into a blank slide in Keynote.

There are two ways to animate slides.

  • Method 1 contains all of the animation logic in one slide, and it’s great for small animations, but can get REALLY confusing when you move around more than 5-6 times.

  • Method 2 will create a bunch of slides, and is not as customizable as Method 1 - but I recommend using this method until you know for sure you need Method 1.

Method 1 involves using Keynote’s built-in animation system. This will involve a mixture of Build In, Action, and Build Out animations. These are governed by the Build Order. You can use the Build Order to make really fine-grained animations with specific delays and start/stop points.

Method 1

Method 2 involves abusing Keynote’s built-in Magic Move between-slide transition. This amazing transition detects similar objects (or words or characters) and tweens them across distinctly different slides. This workflow involves creating one slide for each tween of animation. It’s not very configurable, but it works really well for scooting around a large image with smooth movement.

Method 2

I prefer to use Method 2 unless I have to animate multiple things at once.

This part is more art than science, so be prepared to work hard on it.

Exporting your animated diagram

  1. In Keynote, Play -> Record Slideshow
  2. Record yourself animating the slides
  3. File -> Export To -> Movie

Recording your screen

  1. Open Quicktime Player
  2. File -> New Screen Recording
  3. Start Recording -> Stop Recording -> Save

Feel free to narrate your actions or don’t - we can always add voiceovers later.

You will now have a .mov file with your screen recording.

Editing your screen recording

  1. Open iMovie
  2. Import your .mov file and put it on the timeline
  3. When finished, export your file (see Editing and Exporting Your Presentation below)

Editing and Exporting Your Presentation

  1. Open iMovie
  2. Go nuts
  3. You can re-record voiceovers by hitting V
  4. When you’re satisfied, File -> Share -> File
  5. Use the following settings
Export Settings

Turning a recording into a GIF

Note: make sure you convert .mov files to .mp4 via iMovie before doing this.

  1. Open Keynote
  2. Create a slide that’s just your video file
  3. File -> Export to -> Animated Gif
Export Settings

Compressing your GIF

Once you have your .gif - use gifsicle to compress it.

# Compress input.gif
gifsicle -i input.gif -O3 --colors 256 -o output.gif

Creating demo GIFs

For creating simple GIFs, I like to use Licecap.

Make sure you save your file name as [file-name].gif (if you don’t include the .gif suffix, it’ll fail on Macs.)

My First NFTs - Generated Word Art

20 Sep 2021

I’ve got a lot of feelings about NFTs, mainly that I believe they are currently in a bubble that’s about to spectacularly implode.

But nonetheless, since I am a long-standing fan of cryptocurrency and all of the wonderful and wild ideas that pour out from it, it’d be a poor form to not create and mint at least a few pieces of generative art on the Ethereum blockchain!

These pieces of art are are created using classic texts, Python, Natural Language Processing, and a healthy dose of creativity.

Each sentence of a book or document is broken down and saved as the sum of the contained words - e.g. the sentence “This is a wonderful day” will be saved with a value of 5.

The Path will move in a given direction for that length (5 units), and then turn 90 degrees to the left. And so on, and so forth, for every single sentence in a book, paper, text, etc.

Any time you see a long unbroken sentence, you can be sure the author has been letting their thoughts (and pen) wander.

The Path can also reflect when certain keywords appear in the text- for example, we can highlight any sentences containing the word “liberty” in the U.S. Constitution, or the word “forgiveness” in the Bible.

Tools used: Python with NLP Toolkit