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 March 5, 2024 07:24
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 July 11, 2024 15:11
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 May 31, 2024 00:21
Technical Error vs Business Error

Technical Errors vs Business Errors

When designing or learning about APIs or microservices, it's crucial to consider error handling. 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 alway return ONLY "Functional" (or "Business") errors.
  • The API/micro-service migh crash 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.

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

  • HTTP 404 Business error (or Fake technical error)
@Linch1
Linch1 / tokenPriceApi.js
Last active June 23, 2024 12:49
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 July 14, 2024 18:31
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 January 23, 2024 13:41
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 23, 2024 00:25
set -e, -u, -o, -x pipefail explanation
@posener
posener / go-table-driven-tests-parallel.md
Last active July 10, 2024 13:19
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()
@squarism
squarism / iterm2.md
Last active July 23, 2024 19:13
An iTerm2 Cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@kevin-smets
kevin-smets / iterm2-solarized.md
Last active July 23, 2024 04:22
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k