Packages defined with environment.systemPackages in nix-darwin are installed to /var/current-system/sw/bin. Those configured with home-manager go to the user-specific profile’s bin directory, typically found at ~/.nix-profile/bin.
Python list comprehension is faster than using the .append() method in a loop because it utilizes a special LIST_APPEND bytecode, which is more efficient than the costly object method lookup.
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.
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
intfunction(){int*resource1=acquireResource1();if(resource1==NULL)gotoerror1;int*resource2=acquireResource2();if(resource2==NULL)gotoerror2;// Use resources...
releaseResource2(resource2);releaseResource1(resource1);returnSUCCESS;error2:releaseResource1(resource1);error1:returnFAILURE;}
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
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?"
[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
# 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 promptstarship init fish |source
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 shellaliasbrew="env PATH=(string replace (pyenv root)/shims '' \"\$PATH\") brew"exec"$SHELL"pyenv install 3.11.6
pyenv global 3.11.6
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.
The unicode-range CSS descriptor sets the specific range of characters to be used from a font defined by @font-face and made available for use on the current page. If the page doesn’t use any character in this range, the font is not downloaded; if it uses at least one, the whole font is downloaded.
In Emacs, the fill-paragraph function neatly reflows a block of text, wrapping lines to fit within a specified column width. VS Code offers an extension called “Rewrap,” which you can install to enjoy similar functionality.
Selecting the text you want to rewrap and pressing Alt+Q, or
Placing your cursor within a comment block and pressing Alt+Q to rewrap that comment.
This feature can increase your productivity significantly if you’re editing or writing a considerable amount of text. It streamlines the process of formatting paragraphs, ensuring that they look neat and are easier to read, very much like Emacs’ fill-paragraph.
I recently ventured into deploying a service on Google Cloud Run. My goal was straightforward: create a service that fetches webpage titles and captures screenshots of URLs. However, the journey led me into a peculiar bug when I actually used it on Goole Cloud Run.
The Bug
During the development phase, I worked with a python:3.11-slim base image on macOS, and my Dockerfile functioned without a hitch. Here’s a snapshot of the Dockerfile I used:
Yet, upon deploying to Google Cloud Run and initiating the screenshot capture process, I hit a snag:
playwright._impl._api_types.Error: Executable doesn't exist at /home/.cache/ms-playwright/chromium-1084/chrome-linux/chrome
╔═════════════════════════════
║ Looks like Playwright was just installed or updated.
║ Please run the following command to download new browsers:
║
║ playwright install
║
║ <3 Playwright Team
╚═════════════════════════════
Official Playwright Docker Image Saves the Day
Rather than wrestle with the error, I pivoted to an official Docker image of Playwright, and skipped installation of dependency:
The playwright 1.39.0 requires slightly more than 512MB of memory to run on Google Cloud Run. Adjust the memory limit on GCR, as it’s 512 MB by default.
Conclusion
Use the official Docker image to save time, or specify the PLAYWRIGHT_BROWSERS_PATH environment variable on a supported linux docker image.