Skip to content

Instantly share code, notes, and snippets.

View namgivu's full-sized avatar

Nam G VU namgivu

View GitHub Profile
@namgivu
namgivu / change_git_author.sh
Last active April 1, 2024 10:03
git command change author of multipule commits
git rebase -r $commit_b4_allbadcommits \
--exec 'git commit --amend --no-edit --reset-author'
# ref https://stackoverflow.com/a/1320317/248616
# ref https://www.plesk.com/kb/support/how-to-find-directories-files-that-take-up-the-most-disk-space-on-a-plesk-for-linux-server/
find / -type f -size +200M -exec du -h {} + 2>/dev/null | sort -r -h
# / +200M <- find it
@namgivu
namgivu / convert legacy ChatComplete syntax.txt
Created March 3, 2024 20:44
convert legacy ChatComplete syntax
# before
completions = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": prompt},
],
temperature=0.4,
max_tokens=999,
)
res = completions['choices'][0]['message']['content']
@namgivu
namgivu / _
Last active February 8, 2023 15:55
linux shell script - get script home SH folder
if [ -z "$BASH" ]; then bash $0; exit; fi # forced run w/ bash shell ref. https://stackoverflow.com/a/15731952/248616
SH=$(dirname `realpath $BASH_SOURCE`)
###
SH aka SCRIPT_HOME ie the home folder of the running/executed script file - aka containing folder of .sh script file
ref. https://stackoverflow.com/a/11114547/248616
SH=$(dirname `realpath -s "$0"`) # this works for shell :sh ; CAUTION $0 will always store the FIRST executed .sh ie f0.sh call f1.sh, f2.sh, and $0 always pointing to f0.sh --> must use $BASH_SOURCE to have SH point to the current-script
SH=$(cd `dirname $BASH_SOURCE` && pwd) # this only works for shell :bash and NOT working for :sh
@namgivu
namgivu / 220922.mmd
Created September 20, 2022 07:23
public temp gist
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@namgivu
namgivu / extract a git commit as patch file and then apply the patch
Created May 30, 2021 08:48
extract a git commit as patch file and then apply the patch
extract commit as patch
https://stackoverflow.com/a/6658352/248616
```
cd $source_repo
git format-patch -1 $sha
```
apply the patch
https://stackoverflow.com/a/2250170/248616
```
dockerclearall() {
docker ps --format '{{.Names}}' | xargs -I {} bash -c 'echo "removing {} ..."; docker update --restart=no "{}"; docker stop -t1 "{}"; docker rm -f "{}"';
yes | docker container prune;
yes | docker network prune;
yes | docker volume prune
}
dockerstoprm() {
c=$1 # c aka container_name
docker stop -t1 $c; docker rm -f $c;
curl -s -o /dev/null -w "%{http_code}" -X POST https://reqbin.com/echo/post/json <<EODATA
{
"Id": 78912,
"Customer": "Jason Sweet",
"Quantity": 1,
"Price": 18.00
}
EODATA
shoud_have='
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.webui.driver.DriverFactory
import org.openqa.selenium.WebDriver
import org.openqa.selenium.remote.RemoteWebDriver
import com.kms.katalon.core.webui.driver.SmartWaitWebDriver
import org.openqa.selenium.support.events.EventFiringWebDriver
import org.openqa.selenium.chrome.ChromeDriver
# bit.ly/nnbashtimestamp
log_fielname_w_timestamp=log-`date +%Y%m%d_%H%M%S_%N`