Skip to content

Instantly share code, notes, and snippets.

View trungdlp-wolffun's full-sized avatar
😘
One heart, one love

Trung Duong trungdlp-wolffun

😘
One heart, one love
View GitHub Profile
@corlinp
corlinp / 1brc_corlinp.go
Last active January 24, 2025 14:36
1BRC in Go - corlinp
/*
Corlin Palmer's Go solution to the 1BRC coding challenge: https://github.com/gunnarmorling/1brc
- This solution reads the file sequentially as fast as possible (reader)
- It passes off the job of ensuring that each chunk ends with a complete line to another goroutine (lineSupervisor)
- The lineSupervisor sends valid chunks to a pool of worker goroutines (worker) which parse the data and calculate the results
- The results from the workers are collected in a map and then sorted before printing the final results
A fair amount of optimization has been done to reduce memory allocations.
@danielgross
danielgross / mathpix2gpt.py
Last active March 18, 2025 02:18
mathpix2gpt.py
import requests
import time
import os
import sys
import openai
import tiktoken
from termcolor import colored
openai.api_key = open(os.path.expanduser('~/.openai')).read().strip()
@duongphuhiep
duongphuhiep / Technical Error vs Business Error.md
Last active June 26, 2025 12:24
Technical Error vs Business Error

Technical Errors vs Business Errors

API's designer often categorize errors into "Technical" and "Functional" (or "Business") errors. However, this distinction may not make sense:

  • An API/micro-service should always return ONLY "Functional" (or "Business") errors.
  • The API/micro-service migh be crashed while processing a consumer's request and so the consumer will naturally get a technical error. But the API/micro-service should not deliberately return a "Technical" error for consumer. The simple fact that the App built a nice response called "Technical error", then gracefully return it, make it no longer a technical error, but a "fake" one.

We will explore the distinction between "real technical errors" and "fake technical errors". "Fake technical errors" are initially technical but later manifest as business errors, thus becoming "fake technical errors."

  • HTTP 404 Business error (or Fake technical error)
@Chocksy
Chocksy / sentry-config.html
Last active September 12, 2024 09:14 — forked from impressiver/raven-config.html
Sentry.js configuration for logging JavaScript exceptions to Sentry (https://sentry.io/). Without the added ignore options, you'll quickly find yourself swamped with unactionable exceptions due to shoddy browser plugins and 3rd party script errors.
<!-- Sentry.js Config -->
<script src="https://js.sentry-cdn.com/{{ENV['SENTRY_PUBLIC_DSN']}}.min.js" type="text/javascript"></script>
<script type="text/javascript">
// custom functions to handle errors in JS.
function handleRouteError(err) {
Sentry.captureException(err);
}
function errorHandler(error, data, level) {
level = level || 'info';
@Linch1
Linch1 / tokenPriceApi.js
Last active May 22, 2025 04:15
Retrive the price of any bsc token from it's address without using external service like poocoin/dextools
let pancakeSwapAbi = [
{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsOut","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},
];
let tokenAbi = [
{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},
];
const Web3 = require('web3');
/*
Required Node.js
@acj
acj / microk8s_in_lxc.md
Last active March 17, 2025 08:22
Installing microk8s in an LXC container

Installing microk8s in an LXC container

I wanted to run Microk8s on a Proxmox 6 host inside of an LXC container. These are my notes from the journey.

  1. Create a privileged LXC container through the Proxmox web interface
  • Enable nesting and FUSE
    • In Proxmox UI, select container, then Options > Features > Check nesting and FUSE boxes
  1. SSH into the Proxmox host and edit the container's config in /etc/pve/lxc/.conf
    • Add the following lines
  • lxc.apparmor.profile: unconfined
@anderson-custodio
anderson-custodio / profiling-jvm-kubernetes-visualvm.md
Last active July 10, 2025 01:39
Profiling JVM on Kubernetes using VisualVM

Profiling JVM on Kubernetes using VisualVM

Enable JMX server

Edit Dockerfile to enable JMX server and change the hostname with the IP where the container will run:

FROM openjdk:8-jre-alpine
ADD ./target/app.jar app.jar
EXPOSE 8080
ENTRYPOINT java -Dcom.sun.management.jmxremote.rmi.port=9090 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.1.2 -jar app.jar
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active July 27, 2025 02:46
set -e, -u, -o, -x pipefail explanation
@zthxxx
zthxxx / Activate Office 2019 for macOS VoL.md
Last active July 27, 2025 06:07
crack activate Office on mac with license file
@posener
posener / go-table-driven-tests-parallel.md
Last active April 24, 2025 20:46
Be Careful with Table Driven Tests and t.Parallel()

Be Careful with Table Driven Tests and t.Parallel()

We Gophers, love table-driven-tests, it makes our unittesting structured, and makes it easy to add different test cases with ease.

Let’s create our table driven test, for convenience, I chose to use t.Log as the test function. Notice that we don't have any assertion in this test, it is not needed to for the demonstration.

func TestTLog(t *testing.T) {
	t.Parallel()