Skip to content

Instantly share code, notes, and snippets.

View lysender's full-sized avatar

Leonel lysender

View GitHub Profile
@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
@lysender
lysender / rust-sum-of-left-leaves.rs
Created October 6, 2023 04:00
Rust - Leetcode - Easy - Sum of left leaves
// Leetcode problem: https://leetcode.com/problems/sum-of-left-leaves/
// Easy but difficult when Rust's Rc<RefCell<T>> is used for rust beginners
// Definition for a binary tree node.
// #[derive(Debug, PartialEq, Eq)]
// pub struct TreeNode {
// pub val: i32,
// pub left: Option<Rc<RefCell<TreeNode>>>,
// pub right: Option<Rc<RefCell<TreeNode>>>,
// }
@lysender
lysender / leetcode-rust-sum-of-square-numbers.rs
Last active October 5, 2023 06:13
Leetcode - Rust - Sum of square numbers using binary search
use std::{time::Instant};
fn main() {
solution_sum_of_square_numbers_bs();
}
// Problem: https://leetcode.com/problems/sum-of-square-numbers/
// Solution: https://leetcode.com/problems/sum-of-square-numbers/solutions/4132153/rust-solution-using-binary-search/
// Sources:
// - https://www.geeksforgeeks.org/check-whether-number-can-represented-sum-two-squares/
@lysender
lysender / sharp-resize-portait-to-landscape-but-it-rotates-instead.md
Created August 21, 2023 03:42
sharp - resize portrait into landscape but it rotates the image instead

I have a bunch of photos from my old iPad. I have a script that create thumbnail photos from these images.

The goal is to resize the image into 150x125 and crop if necessary to achieve the result.

const options: ResizeOptions = {
  width: 150,
  height: 125,
  fit: 'cover',
}
@lysender
lysender / htmx-allow-400-errors-swap-for-validation-errors.md
Created August 19, 2023 13:49
HTMX - Allow HTTP error 400 and 422 swap content to enable showing validation errors

Still a newbie to HTMX.

I was writing some form submit interaction and realized that HTMX won't swap/render if the HTTP status code is not 2xx.

For 404, 500 or 503 errors, I think it's fair enough.

For my use case, I'm returning error 400 or 422 for validation errors. I'm returning the form back with some error decorations for example.

According to the docs, I can change that behavior.