Skip to content

Instantly share code, notes, and snippets.

@lysender
lysender / til-enable-application-passwords-on-wordpress-development-env.md
Last active November 29, 2023 22:32
TIL - Enable application passwords on WordPress development environment

API Passwords vs Application Passwords

Forget about API passwords, they are useless in production.

You need the "Application Passwords" instead which can be used for "Basic" authentication when calling the REST API.

This requires HTTPS so this is normally not enabled in local development.

Enable Application Passwords in development environment

@lysender
lysender / til-moving-within-quotes.md
Created November 15, 2023 04:00
TIL - vim - moving within quotes

Basic key bindings

f" and f' to move to the next double quote or single quote.

F" and F' to move to the previous double quote or single quote.

Used when you want to select or copy text including the quotes.

t" and t' to move to the last character before the next double quote or single quote.

@lysender
lysender / leetcode-rust-single-element-in-a-sorted-array.md
Created November 6, 2023 03:45
Leetcode - Rust - Single Element in a Sorted Array

Problem: https://leetcode.com/problems/single-element-in-a-sorted-array/description/ Solution: https://leetcode.com/problems/single-element-in-a-sorted-array/solutions/4254843/rust-solution-using-binary-search/

Using binary search, seek middle. The idea is that since this is a sorted array, finding which side has the single element is just a matter of comparing adjacent items from the middle and the distance between middle and the edges.

For example, if the middle item and the item to the left is equal and the distance between the middle and the left is even, then the single element must not be on the left since the distance is an event number. It must be to the right.

impl Solution {
    pub fn single_non_duplicate(nums: Vec<i32>) -> i32 {
@lysender
lysender / leetcode-add-to-array-form-of-integer.md
Created October 27, 2023 03:33
Leetcode add to array form of integer
@lysender
lysender / nvim-typescript-lsp-auto-import-path-incorrect.md
Created October 26, 2023 03:51
NeoVim + TypeScript LSP - auto import path incorrect - always starts at src

I am working on several projects with neovim with TypeScript LSP installed.

In some projects, the auto import correctly set the path using relative paths.

However, some projects always starts its import at src for some reason.

Tried to configure LSP to always use relative path but can't make it work.

Somehow, there is something in my project configuration that broke the LSP import.

@lysender
lysender / til-cra-build-oom-error.md
Created October 25, 2023 08:59
TIL - CRA (Create React App) build out of memory error

We are getting intermittent build failure on our React.js application which uses CRA (Create React App).

I was able to capture the error on my local VM.

> node scripts/build.js

Creating an optimized production build...

<--- Last few GCs --->
@lysender
lysender / til-vim-bulk-comment.md
Created October 14, 2023 08:25
TIL - vim - bulk comment

Visual Block Mode

Add/remove comment using the visual block mode.

  • First, move the cursor to the first char of the first line in block code you want to comment, then type Ctrl + v.
  • Then vim will go into VISUAL BLOCK mode.
  • Use j to move the cursor down until you reach the last line of your code block. Then type: Shift + i
  • Now vim goes to INSERT mode and the cursor is at the first char of the first line. Finally, type # or the comment character of your language then ESC and the code block is now commented.

Note that at first sight, the editing does not seem to differ from changing a single line. The changes will only be applied to the whole block after hitting ESC.

@lysender
lysender / til-vim-bulk-indent.md
Created October 14, 2023 08:15
TIL - vim - indent multiple lines

Select multiple lines, ex: using the visual mode:

  • Press v on normal mode
  • Move cursor to select the lines to edit
  • Press SHIFT + &lt; or &gt; to indent to left or right.
@lysender
lysender / til-rust-enums-for-union-or-generic-type-scenarios.md
Created October 13, 2023 05:25
TIL - Rust enums for some union or generic type scenarios

Coming from TypeScript background, it is common to use either a union type or a generic hints on function parameters.

For rust though, at some point, you need to specify the type.

I have these structs (oversimplified):

#[derive(Serialize, Deserialize)]
struct PublishedJob {
    id: String,
@lysender
lysender / rust-windows-install-configure-openssl-using-vcpkg.md
Created October 11, 2023 14:20
Rust - Windows - Install/configure OpenSSL using vcpkg