HomeAboutPostsTagsProjectsRSS

Updated
Words151
TagsRead1 minute

I’m quite fond of this saying—it captures the essence of Emacs perfectly.

The core idea of Emacs is to have an expressive digital material and an open-ended, user-extensible set of commands that manipulate that material and can be quickly invoked. Obviously, this model can be fruitfully applied to any digital material, not just plain text.

X

Updated
Words190
TagsRead1 minute

If you are experiencing issues with a Doom Emacs package that has been cloned from GitHub, and you want to force a re-download or re-clone of the package, you can use the following steps to address the issue:

  1. Delete the Problematic Package: Navigate to your .emacs.d/.local/straight/repos/ directory (or wherever your packages are stored; this path is the default for Doom Emacs). Locate the directory corresponding to the problematic package and delete it.
rm -rf ~/.emacs.d/.local/straight/repos/<package-name>

Replace with the actual name of the package directory you want to remove.

  1. Clear Build Cache: Clear the build cache that might contain failed or partial build information. The build cache is typically located in the .emacs.d/.local/straight/build/ directory.
rm -rf ~/.emacs.d/.local/straight/build/<package-name>
  1. Run Doom Sync: Run doom sync in your terminal to synchronize your configuration. This will re-download and rebuild any missing or deleted packages.
doom sync
  1. Restart Emacs: After running doom sync, restart Emacs to ensure that all changes take effect.

Remember that you should re-enable the package your config.el before running doom sync if you previously disabled it.

Updated
Words623
TagsRead2 minutes

I have very limited experience about goto statement except that I know it is not encouraged in high level language. Today I learn from a comment of why is it illegal to use “goto” that goto statement are commonly used in Linux kernel in resource acquisition/release pattern.

The goto statement comes in handy when a function exits from multiple locations and some common work such as cleanup has to be done. If there is no cleanup needed then just return directly.

Centralized exiting of functions - Linux kernel coding style

Context: Resource Acquisition and Release

  • In C, managing resources like memory, file handles, or network connections is critical. These resources must be acquired before use and released after use.
  • The process of acquiring and releasing resources is prone to errors. If not handled correctly, it can lead to issues like memory leaks, where memory isn’t freed correctly, or resource exhaustion, where resources aren’t released back to the system.

Why goto is Useful Here

Simplifies Error Handling: When acquiring multiple resources, each step might fail. Normally, you’d need nested if statements to handle these failures. However, with goto, you can jump to the specific code that releases resources, simplifying the error handling.

Clarity and Maintenance: By using goto for forward jumps, the flow of error handling becomes linear and more readable. This is in contrast to nested if statements, which can become complex and difficult to follow.

Example

int function() {
    int *resource1 = acquireResource1();
    if (resource1 == NULL) goto error1;

    int *resource2 = acquireResource2();
    if (resource2 == NULL) goto error2;

    // Use resources...

    releaseResource2(resource2);
    releaseResource1(resource1);
    return SUCCESS;

error2:
    releaseResource1(resource1);
error1:
    return FAILURE;
}

In this example, if acquiring resource2 fails, the code jumps to error2, where resource1 is released. This ensures that even if there is an error in acquiring the second resource, the first one is properly released

Updated
Words719
TagsRead3 minutes

This video gives an easy explanation about RAG(retrieval augmented generation)

https://youtu.be/T-D1OfcDW1M?si=a_06Z9VkMSwuh6To

Here is my notes about RAG

limitations of Large Language Model (LLM)

  • Outdated Information: LLMs are often limited by the data they were trained on, which can become outdated over time. This leads to responses that may no longer be accurate or relevant.
  • Lack of Fact-Checking: Traditional LLMs do not have a mechanism to fact-check or verify the information they generate, which can lead to inaccuracies in their responses.

why was RAG invented

The RAG technique was invented to enhance the accuracy and relevance of responses generated by LLMs. The key motivations for developing RAG were:

  • To Provide Up-to-Date Information: By integrating a retrieval system, RAG ensures that the LLM has access to the most current information, thereby improving the accuracy of its responses.
  • To Improve Fact-Checking Capabilities: RAG allows LLMs to cross-reference information with reliable sources, enhancing their ability to verify facts and provide more trustworthy responses.
  • To Address the Static Nature of LLMs: Since LLMs are trained on static datasets, they can become outdated. RAG introduces a dynamic element where the model can access and incorporate new and updated information.

how does it work

The RAG framework works by combining the capabilities of a traditional LLM with an external information retrieval system. The process involves:

  • Retrieval of Relevant Information: When a query is made, the RAG system first retrieves relevant information from an external data store. This data store is continuously updated with new information.
  • Three-Part Prompt Processing: The LLM receives a three-part prompt consisting of the instruction, the retrieved content, and the user’s question.
  • Generation of Informed Responses: The LLM uses both the retrieved information and its pre-existing knowledge base to generate a response. This ensures that the response is not only based on its training data but also on the most current information available.
  • Continuous Updating: The data store used for retrieval is continuously updated, allowing the LLM to stay current with new information and developments.

example of the three-part prompt

  • Instruction: This is a directive or guideline that tells the language model what kind of response is expected. It sets the context or the goal for the response.
  • Retrieved Content: This part includes the relevant information retrieved from a large-scale data store. This content is dynamically sourced based on the query, ensuring that the information is up-to-date and pertinent to the user’s question.
  • User's Question: This is the actual query or question posed by the user. It’s what the user wants to know or the problem they need solved.

Example of a Three-Part Prompt

Here’s how the three-part prompt might looks like:

Use the following pieces of context to answer the question at the end.
If you don't know the answer, just say that you don't know, don't try to make up an answer.
Use three sentences maximum and keep the answer as concise as possible.
Always say "thanks for asking!" at the end of the answer.

<An article or a set of articles from a reputable source, retrieved by the system, discussing the latest developments in AI as of 2023.>

Question: "What are the latest advancements in artificial intelligence?"

refer langchain

Updated
Words228
TagsRead1 minute

A nice way to add arbitrary HTML tags in Hugo site markdown content.

Create a content.html in layouts/partials

{{
.
| replaceRE `\{\^([^}]*)\}` "<sup>$1</sup>"
| replaceRE `\{\_([^}]*)\}` "<sub>$1</sub>"
| replaceRE `\{\#([^}]*)\}` "<kbd>$1</kbd>"
| replaceRE `\{\!([^}]*)\}` "<mark>$1</mark>"
| replaceRE `\{\=([^}]*)\}` "<cite>$1</cite>"
| replaceRE `\{\+([^}]*)\}` "<ins>$1</ins>"
| replaceRE `\{\$([^}]*)\}` "<var>$1</var>"
| safeHTML 
}}

and use the partial html template {{ partial "content.html" .Content }} to render the HTML

Get missing inline HTML tags in Markdown without enabling HTML - tips & tricks - HUGO

Updated
Words2196
TagsRead4 minutes

display

System Settings > Accessibility > Display > Turn On Reduce Motion

modifier key

  • change to ^
  • caps lock change to

finder

# show hidden files
defaults write com.apple.finder AppleShowAllFiles YES

# show path bar
defaults write com.apple.finder ShowPathbar -bool true

killall Finder;

brew

install brew

Quick Look plugins

brew install --cask \
    qlcolorcode \
    qlstephen \
    qlmarkdown \
    quicklook-json \
    qlprettypatch \
    quicklook-csv \
    betterzip \
    webpquicklook \
    suspicious-package

applications

brew install --cask \
    appcleaner \
    google-chrome \
    iterm2 \    
    raycast \
    visual-studio-code

command line tools

# [Nerd Font](https://www.nerdfonts.com/)
brew install --cask font-fira-code-nerd-font

brew install \
    bat \
    fish \
    git \
    git-delta \
    go \
    hugo \
    jq \
    neofetch \
    orbstack \
    ripgrep \
    starship \
    tree \
    wget

git

git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.ss status

git-delta

~/.gitconfig

[core]
    pager = delta

[interactive]
    diffFilter = delta --color-only

[delta]
    navigate = true    # use n and N to move between diff sections
    light = false      # set to true if you're in a terminal w/ a light background color (e.g. the default macOS terminal)

[merge]
    conflictstyle = diff3

[diff]
    colorMoved = default

fish shell

starship preset nerd-font-symbols -o ~/.config/starship.toml

add to ~/.config/fish/config.fish

# Add HomeBrew's bin directory to path so you can use HomeBrew's binaries like `starship`
# Fish uses `fish_add_path` instead of `export PATH` modify $PATH.
fish_add_path "/opt/homebrew/bin/"
# Enable Starship prompt
starship init fish | source

Package manager

fisher

plugin:

abbreviation

add to ~/.config/fish/config.fish

source ~/.config/fish/abbreviation.fish

create abbreviation.fish

abbr proxyall "set --export http_proxy http://127.0.0.1:7890; set --export https_proxy http://127.0.0.1:7890"

custom function

it’s very easy to add a custom function in fish shell, an example

Visual Studio Code

Settings

Side Bar:Location change to right

extensions

  • Auto Hide
  • AutoTrim
  • Emacs Friendly Keymap
  • Indenticator
  • Sort lines
  • vscode-icons

Python

use pyenv to manage Python environments, don’t reply on the python installed by brew, because it might update Python version upexpecetdly when performs brew update.

brew install readline xz pyenv
# otpinal: setup pyenv with fish shell
alias brew="env PATH=(string replace (pyenv root)/shims '' \"\$PATH\") brew"
exec "$SHELL"

pyenv install 3.11.6
pyenv global 3.11.6

Reference

Terminal emulator

iTerm2

Keyboard setting

Use fn to Change Input Source

Keyboard Shortcuts -> Uncheck all Input Sources Spotlight

Apple Internal Keyboard

Keyboard Shortcuts -> Modifier Keys

  • Caps Lock Key -> Command
  • Command -> Control

External Keyboard

Keyboard Shortcuts -> keep Modifier Keys unchanged

Karabiner-Elements

  • left_command -> left_control
  • left_control -> left_command
  • right_command -> right_control
  • right_option -> fn

Make Caps Lock → Hyper Key (⌃⌥⇧⌘) (Caps Lock if alone) import

Tiling Windows Manager

  • yabai (no need to disable System Integrity Protection)
  • skhd

yabai installation and configuration reference:

skhd config

cmd + ctrl + shift + alt is the Hyper Key configurated using Karabiner-Elements

# change focus between external displays (left and right)
cmd + ctrl + shift + alt - p : yabai -m display --focus west
cmd + ctrl + shift + alt - n : yabai -m display --focus east

# fullscreen window
cmd + ctrl + shift + alt - m : yabai -m window --toggle zoom-fullscreen

# cycle focus between windows
cmd + ctrl + shift + alt - o : yabai -m window --focus prev || yabai -m window --focus last
# cycle swap window to the main window
cmd + ctrl + shift + alt - j : /bin/bash ~/bin/cycle_clockwise.sh; yabai -m window --focus prev || yabai -m window --focus last

# rotate layout clockwise
cmd + ctrl + shift + alt - r : yabai -m space --rotate 270
# flip along y-axis
cmd + ctrl + shift + alt - y : yabai -m space --mirror y-axis
# flip along x-axis cmd + ctrl + shift + alt - x : yabai -m space --mirror x-axis
# toggle window float
cmd + ctrl + shift + alt - f : yabai -m window --toggle float --grid 4:4:1:1:2:2

cycle_clockwise.sh:

#!/bin/bash

win=$(yabai -m query --windows --window last | jq '.id')

while : ; do
    yabai -m window $win --swap prev &> /dev/null
    if [[ $? -eq 1 ]]; then
        break
    fi
done

Updated
Words469
TagsRead2 minutes

Jotting down thoughts helps clarify the mind. The end goal is simple: just write without fretting over tools. That’s why I’ve always found that starting to write with pen and paper is the easiest approach. However, these days, since everyone carries their mobile phone, the trend has shifted towards writing on phones.

At first, I didn’t consider Apple Notes to be a suitable professional note app, so I tried out OneNote, EverNote, and Notion. Unfortunately, none fit my needs. OneNote posed difficulties on mobile devices; its free layout might be handy for stylus use, but on a small screen, it made things hard to identify and search. I gave Notion a shot for half a year, but it was too complex. While it’s great for team collaboration, I didn’t require that functionality, and I was frustrated by the ’everything as a block’ design, which made selecting and formatting a hassle. Notion’s AI is decent, but I wasn’t keen on shelling out another $10 every month on top of ChatGPT Plus. As for Evernote, I mainly used it to collect webpages rather than for writing.

Apple Notes has seen significant enhancements over time. With the introduction of a transformer model in iOS 17, Apple has elevated its autocorrect and predictive text capabilities , understanding and adapting to your typing patterns. It’s even capable of autofilling entire sentences on occasion. My increasing use of Apple Notes on iPhone has led to more frequent use on macOS as well, and the smooth integration across devices enhances the writing experience in a way that other note apps on different platforms can’t match. The autocorrect and inline predictive text feature available on both operating systems is incredibly effective and is arguably unbeatable at the moment.

Apple Notes now features a tag system and smart lists for note management. Combined with other functions like PDF import, file attachment, OCR, and drawing capabilities, Apple Notes meets most of my requirements.

My current workflow involves using Notion for web clipping and Apple Notes for all my personal notes. This approach has taught me to focus less on the tools and more on simply writing. Just write—use the simplest tool at hand and push it to its limits. Only then consider upgrading your tools if necessary.