lynnux

Logo

☁️ customer engineer at google
🏂 snowboarder
🍞 carb addict
🏘 real estate investor
💃🏻 dancer
✈️ traveler
📖 learner
👾 ex-gamer with semi-annual relapses
☕️ fueled by caffeine


linkedin github

Journal

02 Dec 2021


TIL

I spent this morning’s deep work session studying Go!

Lissajous Figures

I learned how you can use Go to create animated gifs of Lissajous figures (parametric curves produced by harmonic oscillation in two dimensions, such as two sine waves fed into the x and y inputs of an oscilloscope)!

// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/

package main

import (
	"image"
	"image/color"
	"image/gif"
	"io"
	"math"
	"math/rand"
	"os"
)

import (
	"log"
	"net/http"
	"time"
)

var palette = []color.Color{color.White, color.Black} // black on white

const (
	whiteIndex = 0 // first color in palette
	blackIndex = 1 // next color in palette
)

func main() {
	rand.Seed(time.Now().UTC().UnixNano())

	if len(os.Args) > 1 && os.Args[1] == "web" {
		handler := func(w http.ResponseWriter, r *http.Request) {
			lissajous(w)
		}
		http.HandleFunc("/", handler)
		log.Fatal(http.ListenAndServe("localhost:8000", nil))
		return
	}
	lissajous(os.Stdout)
}

func lissajous(out io.Writer) {
	const (
		cycles  = 5     // number of complete x oscillator revolutions
		res     = 0.001 // angular resolution
		size    = 100   // image canvas covers [-size..+size]
		nframes = 64    // number of animation frames
		delay   = 8     // delay between frames in 10ms units
	)
	freq := rand.Float64() * 3.0 // relative frequency of y oscillator
	anim := gif.GIF{LoopCount: nframes}
	phase := 0.0 // phase difference
	for i := 0; i < nframes; i++ {
		rect := image.Rect(0, 0, 2*size+1, 2*size+1)
		img := image.NewPaletted(rect, palette)
		for t := 0.0; t < cycles*2*math.Pi; t += res {
			x := math.Sin(t)
			y := math.Sin(t*freq + phase)
			img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5),
				blackIndex)
		}
		phase += 0.1
		anim.Delay = append(anim.Delay, delay)
		anim.Image = append(anim.Image, img)
	}
	gif.EncodeAll(out, &anim) // NOTE: ignoring encoding errors
}
Lissajous Figure


Switching Between Terraform Versions on MacOS

I find myself switching between my customer’s codebase and my own codebases but each require a different version of terraform. I know there’s the option of using tfenv but I prefer Alexander’s solution. I just paste the following in my .zshrc or .bashrc

function terraform-use {
  vsn=$1
  pkg="terraform_${vsn}_darwin_amd64.zip"
  url="https://releases.hashicorp.com/terraform/${vsn}/${pkg}"
  tf="$(which terraform || echo /usr/local/bin/terraform)"
  if [ -e "${tf}-${vsn}" ]; then
    ln -Fs "${tf}-${vsn}" "${tf}"
  elif curl --head --fail "${url}" 2> /dev/null; then
    wget -O "/tmp/${pkg}" "${url}"
    (
      cd /tmp/
      unzip -o "/tmp/${pkg}"
      rm "/tmp/${pkg}"
      mv terraform "${tf}-${vsn}"
    )
    ln -Fs "${tf}-${vsn}" "${tf}"
  else
    echo "ERROR \`${url}\` not found"
    return 1
  fi
  terraform -version
}

Usage:

$ terraform-use x.y.z

General

Today I told my manager I was unhappy working on my current project and something needed to change. Prior to this engagement, I told myself this staff aug / time & materials would be different. I don’t know why it took me this long to simply say something about it. I think in the past, in order to prevent “complaining”, I would just endure the discontentment until it festered. It’d get to the point where I would look for new jobs and then blindside my managers with a two week notice. Why did I see the act of expressing how I felt as “complaining”? Such a negative connotion. Anyway, my manager took it really well and completely understood. He “commiserated” me. That guy has quite the extensive vocabulary. He said he would make it his top priority and will do his best to get me off-boarded by the end of the year.

This got me thinking; once I’m off the project, what would I love to work on? It can’t be too easy. It can’t be something I know absolutely nothing about. It should solve a problem. And I’d love to work closely with one other engineer where we can bounce ideas off each other and learn from one another. I just need to constantly be doing something challenging. I suppose idle hands causes wandering eyes for me 👀.