Shing Lyu's Random Tech Facts

This is a micro-blog where I write one-liners about random tech stuff I learned.

Generating a notification sound in command-line

You want to play a notification sound in a Linux shell script, but don’t want to download any sound files (e.g. MP3, WAV, MIDI). Here is a script that generates the sound on-the-fly:

First install SoX, the Swiss Army knife of sound processing programs.

sudo apt-get install sox

Then:

play -n synth 0.3 pluck A3 vol -20dB repeat 2


How to import serde's custom derive macors properly?

TL;DR Follow the official documentation

A little bit of history:

extern crate serde;
#[macro_use] extern crate serde_derive; // Imports the procedural macros

#[derive(Serialize, Deserialize)]
struct Foo;
use serde_derive::{Serialize, Deserialize}; // Imports the procedural macros

#[derive(Serialize, Deserialize)]
struct Foo;
// Cargo.toml
[dependencies]
serde = { version = "1.0", features = ["derive"] }

// src/main.rs or lib.rs
use serde::{Serialize, Deserialize}; // Imports both the traits and procedural macros

#[derive(Serialize, Deserialize)]
struct Foo;


Caveats in Terraforming WAF V2 for CloudFront

If you want to add a WAF V2 (aws_wafv2_web_acl) to a CloudFront distribution (aws_cloudfront_distribution) using Terraform, there are a few caveats:


Check MongoDB index usage statistics

Run this command to get the usage of each index:

db.<collection>.aggregate( [ { $indexStats: { } } ] )

This is useful for figuring out which index is underutilized. You can find an example output in the documentation.


RFC2616 is dead, read RFC723X

While looking for the definition of HTTP Status Codes, I realize that RFC2616 is deprecated. You should look for RFC7231 instead.

Reference: mnot’s blog: RFC2616 is Dead