Skip to content

Instantly share code, notes, and snippets.

View julianlam's full-sized avatar
🤔
I may be slow to respond.

Julian Lam julianlam

🤔
I may be slow to respond.
View GitHub Profile
@julianlam
julianlam / mocha-tests-best-practices.md
Last active August 5, 2022 14:48
Best Practices for Writing Tests #blog

This is a living document, it will be updated from time to time as my test writing evolves.

It's easy to fall into the trap of writing your tests with less care than you would your regular code. After all, if tests pass, then ship it is de rigeur, so there's an incentive — especially if the clock is ticking closer to the end of workday — to get those tests passing ASAP.

Avoid globals/leaky states

One corner that is often cut is to introduce or reuse variables between tests. For example:

  1. I am writing tests for updating a user's profile. I will create one user and run all tests against that single user.
@julianlam
julianlam / deleting-old-files.md
Created July 27, 2022 15:55
Delete all files older than X days #blog

Sometimes you just need to prune a directory of all files older than a certain age. Think log files, or uploaded files... maybe ~/Downloads, perhaps?

find . -mindepth 1 -maxdepth 1 -mtime +90 -delete
@julianlam
julianlam / home-networking-cable-porn.md
Last active July 17, 2022 04:03
Home Networking Cable Porn — a weekend home improvement project #blog

Those that know me know that I don't exactly have a great relationship with neat cabling practices. My desktop PC builds are rather haphazard, with power cables, SATA cables, and the like snaking across and through the case with no regard for aesthetics. After all, plug A needs to go to socket A, why not take the most direct route? Brace yourselves...

fc2fbc5b808b59654664bde2c18e932507e0c5b8

Accordingly, the same work ethic seemed to follow me into my home networking setup. Through a combination of organic growth (new devices added over time), and due to the added incentive of needing to get connected ASAP when we moved in, little to no thought was put to making everything look neat and tidy.

I'll spare you the imagery, but some lovely faults:

  1. A DSL line that entered the house via a demarcation point at one end of the house, only to snake across the entire length of the house before actually entering
@julianlam
julianlam / remove-one-domain-from-san-certbot-cert.md
Created June 9, 2022 20:14
Remove a single domain from a Certbot certificate that contains multiple domains #blog

I came across a scenario where I had a certificate (example.org, below) that supported multiple domains, but one domain's (broken.example.org, below) the A record no longer existed, causing certbot to abort renewals with an error:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/example.org.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
@julianlam
julianlam / datetime-local-across-locales.md
Created June 8, 2022 15:37
Testing `datetime-local` input across various locales #blog

Working with <input type="datetime-local"> is a lot of fun. All major browsers have standardized their UIs, and offer full support, and so the days of using polyfills or jQuery fallbacks are numbered.

Should you need support for older or more esoteric browsers, it may be best to fall back to a bunch of <select> inputs instead.

The cool thing about datetime-local is that the UI itself is localised based on the user's browser/machine language settings.

For example, in Canada:

image

@julianlam
julianlam / bye-fast-checkout-lanes.md
Last active May 30, 2022 15:54
The age of the fast self-checkout lane is over #blog

I have a not-so-secret confession to make — I use the self-checkout line at grocery stores because they get me out of the store faster.

The choice used to be simple: at any given checkout queue, the queue for the self-checkout is usually non-existant, and I am adept enough at the interface so that it is not overly cumbersome to use.

My so-called "Speed Hacks"

  1. If you take care to cart your items with all of the barcodes facing upwards, then at the scanner, you can use the hand-held scanner to scan everything without having to waste time turning the product across three dimensions trying to find the barcode1. The time spent locating the barcode is spread out across my entire shopping trip, instead of at the till. If you use the "skip bagging" option, then you can even leave the items in the cart, instead of needlessly scanning/bagging/carting your items.
@julianlam
julianlam / wannabe-security-researchers.md
Last active May 16, 2022 16:20
Wannabe "Security Researchers" are the worst part about running a bug bounty #blog

Where I work, we run a bug bounty. We've done this for a number of years, and it's yielded great results in that bugs that could potentially affect user data are quickly and quietly dealt with at our own pace, and we retain control over the narrative (as opposed to having it disclosed publicly and dealing with the fallout.)

By far, however, the most annoying part of running the bug bounty program are the wannabe security researchers.

You know the kind;

  • The ones who run automated scanners against every website they can find
  • The ones who copy and paste technical jargon from websites in an attempt to feign legitimacy
  • The ones who assign a "high" priority to their reports via subject—just to get your attention
  • The ones who, when pressed for details, have no clue what they're talking about or even reporting
@julianlam
julianlam / gmail-basic-html.md
Last active May 2, 2022 02:12
Quickly switch GMail to Basic HTML mode #blog

I often have to toggle between a number of GMail accounts because even though they are managed by Zendesk, occasionally ham is caught by GMail's spam filter and never makes it to Zendesk. I've had enough important messages fall through that I became suspicious, and then discovered that I have replies and incoming leads being caught almost weekly!

Anyways, in short, GMail takes bloody forever to load anything that isn't Chrome, and the UI is not very snappy. Clicking "Use Basic HTML" at the bottom left is pointless because it doesn't actually trigger right away, and I've already waited many seconds before it sends me to that interstitial page asking me if I really wanted to use Basic HTML. Oh the horror.

In the future, just append ?ui=html or /h/, and voila!, watch your mailbox load in .5 seconds, flat.

So in the future, accessing your main mailbox would be https://mail.google.com/mail/u/0/h/. Note the trailing slash, that's needed.

I really miss when webs

@julianlam
julianlam / port-forward-cheatsheet.md
Last active April 21, 2022 20:10
Forward port from remote server to local machine #blog

This is how to do it, because I have the memory of a goldfish and have to look it up every time.

The context

Let's say there's a server (123.123.123.123) running a service on port 1234.

You want to view it on your local machine on port 2345.

The command

@julianlam
julianlam / programmatically-setting-values-multiselect.md
Last active April 11, 2022 17:33
Programmatically getting & setting values of a multiselect (without jQuery) #blog

I came across an interesting problem without a good native browser solution, recently. Usually, browser APIs are so complete that this is a non-issue, but nonetheless...

The specific scenario involved a multiselect:

<select multiple id="mySelect">
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
 Four