/dev/jcheng
  • About
  • Articles
  • Pages
  • Reviews
  • Tags

Articles

September 21, 2020

Deriving Average Without Totals

Even an old dog like me learns something new every day.

Let’s say you need a program that receives a sequence of numbers and output the current average. How do you do this efficiently? The naive solution is to to keep track of two variables:

total   # add up all numbers seen so far
count   # a count of how many numbers seen so far

This way, at any step, you can calculate the current average using total/count.

read more
September 21, 2020

Creating New Abstractions

Software engineers find it natural to talk about abstractions. We have ideas such as Decorators, Model-View-Controller, and Message Queues. These abstractions allow software engineers to talk to each other using our own rich and succint language. Abstractions, however, is not unique to engineers. In my role as a parent and an American citizen, I am constantly confronted with new abstract ideas arising out of life.

The abstractions I am referring to are new words and ideas coming out of our shared culture. For example, words that do not exist twenty years ago: Me-Too and BLM as well as a redefinition of words like gender and socialism.

read more
September 8, 2020

I want to love DynamoDB

I want to love DynamoDB. I love that it just scales (disk usage and processing power). I love that it is tightly integrated with AWS’s IAM model, so I don’t have to deal with user/role/permissions management.

But DynamoDB does some weird things by design. For example, only the primary key can be unique. If you want a table with multiple unique attributes, for example, a Users table where both the user_name and email are unique, you’ll have to do weird things like this.

read more
September 2, 2020

Post(s) of the Week Sept 2020

The Empathy Gap from Effectiviology.com

For example, if a person is currently feeling calm, the empathy gap can cause them to struggle to predict how they will act when they’re angry. Similarly, if a person who is on a diet is currently full, the empathy gap can cause them to struggle to assess how well they will be able to handle the temptation to eat when they’re hungry.

read more
August 17, 2020

Managing Humans

I finished Managing Humans from Michael Lopp today. I knew of Lopp through “Rands Leadership”, the Slack community he created. I enjoyed learning from the people in the community and thought I’d pick up his book. I’m not sure what I expected going into the book. I think I expected tips and rules that I can follow. After trying to summarize the book, I think what I wanted and got was a set of mental models that I am happy to add to my toolbox.

read more
August 1, 2020

Go io/fs Design (Part I)

As usual, LWN has a good write up on what’s going on in the Go community. This week’s discussion in on the new io/fs package. The Go team decided to use a Reddit thread to host the conversation about this draft design. LWN points out that posters raised the following concerns:

  • We added status logging by wrapping http.ResponseWriter, and now HTTP/2 push doesn’t work anymore, because our wrapper hides the Push method from the handlers downstream. / It becomes infeasible to use the decorator pattern more
  • Doing it “generically” involves a combinatorial explosion of optional interfaces

Ultimately, Russ Cox admits, “It’s true - there’s definitely a tension here between extensions and wrappers. I haven’t seen any perfect solutions for that.”

read more
August 1, 2020

Links for the Week

The big thing from this week is the launch of the Perseverance Rover to Mars. In the last Month, United Arab Emirates, China, and United States all launched rovers to Mars. The US rover is the Perseverance. It carries a novel flying drone. It will also attempt to safely store soil samples that can eventually be brought back to US.

It makes my heart twinge even writing about it.

Atlas Obscura has an article on the origins of the automatic rice cooker. I read it over coffee this morning and thought about how happy good rice makes me feel. The humber Datung rice cooker was so central to my childhood.

read more
July 26, 2020

Localstack S3 and Go

I spent too much time Saturday getting the Go S3 SDK to work with LocalStack.. It turns out that if you are using LocalStack, you need to explicitly configure the following properties:

	sess, err := session.NewSession(aws.NewConfig().
		WithEndpoint(endpoint).
		WithRegion(region).
		WithS3ForcePathStyle(true))

The requirements for Endpoint and Region are obvious. If S3ForcePathStyle is not specified, then LocalStack will fail.

	data, err := svc.GetObject(&s3.GetObjectInput{
		Bucket: &bucket,
		Key:    &cfgKey,
	})

What is path-style? In May 2019, Amazon deprecated path-based access model for S3 objects. This means one should no longer use URLs of the form:

read more
July 12, 2020

Running Private Docker Registry

I still find it hard to believe how easy it is to run your own infrastructure in the cloud.

Running a Docker registry is as simple as adding a few lines of code to your Terraform configuration.

	resource "aws_ecr_repository" "foo" {
	  name                 = "bar"
	  image_tag_mutability = "MUTABLE"

	  image_scanning_configuration {
		scan_on_push = true
	  }
	}

When deployed, this create an registry where you can manage multiple Docker repositories. You can upload a Docker image to be used in your private ECS cluster:

read more
May 26, 2020

Gomock Tutorial

I’ve been using mock/Gomock to write tests in my personal project. When you’re building something in a new language, it is hard to prioritize learning every tool in your toolchain. For me, I’ve been writing custom and suboptimal code for Gomock because of a nifty but undocumented API call .Do.

In many cases, I wan to match subsets of a complex object while ignoring irrelevant parts. e.g., verify a function is invoked with a list of User objects, but only verifying the email addresses. To do that in a generic way, I wrote a custom Matcher API that uses text/template to describe what parts of the object to match. Thus, my mock-and-verify code looks like:

read more
  • ««
  • «
  • 4
  • 5
  • 6
  • 7
  • 8
  • »
  • »»
© /dev/jcheng 2025