Skip to content

Instantly share code, notes, and snippets.

View oshinko's full-sized avatar

Oshinko oshinko

View GitHub Profile
@oshinko
oshinko / add-timestamp-to-log-file.bat
Created July 10, 2021 03:53
Add timestamp to log file on Windows.
set logfile=%computername%.log.txt
set maxlines=1024
set /a taillines=%maxlines%-1
cd %~dp0
powershell -command "Get-Content %logfile% -Tail %taillines%" 1> tmp.txt 2> nul
type tmp.txt > %logfile%
echo %date% %time% >> %logfile%
del tmp.txt
@oshinko
oshinko / zip.js
Created June 30, 2021 03:53
How to zip arrays with JavaScript.
/**
* const expected = [[0, 2], [1, 3]]
* const actual = [...zip([0, 1], [2, 3])]
* assert JSON.stringify(expected) === JSON.stringify(actual)
*/
export function *zip(...arrays) {
try {
arrays[0] = [...arrays[0]]
} catch {
throw Error(`TypeError: First argument "${arrays[0]}" is not iterable`)
@oshinko
oshinko / generate-and-apply-patches-with-git.sh
Last active June 28, 2021 06:49
Generate and apply patches with Git
git diff > ~/tmp/wip.patch
patch -p1 < ~/tmp/wip.patch
@oshinko
oshinko / mk-gitignore_global.sh
Last active March 1, 2022 04:49
My .gitignore_global
cat << EOF > ~/.gitignore_global
.DS_Store
.venv/
tmp/
EOF
git config --global core.excludesfile ~/.gitignore_global
@oshinko
oshinko / sha256sum.sh
Last active December 12, 2021 11:25
One-line hash command in Python
cat $PATH_TO_TARGET | python -c "import sys; import hashlib; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest())"
@oshinko
oshinko / install-python-3-on-amazon-linux-2.sh
Last active June 18, 2021 02:18
Install Python 3 on Amazon Linux 2
if ! command -v python3 &> /dev/null; then
sudo amazon-linux-extras install -y python3.8
if ! command -v pip3 &> /dev/null; then
pip=`which pip3.8`
sudo ln -s $pip `dirname $pip`/pip3
fi
fi
@oshinko
oshinko / nginx.conf
Created March 11, 2021 05:30 — forked from mreschke/nginx.conf
Nginx config for multiple laravel sites based on /api/v1 url paths
# This config will host your main [Laravel] GUI application at /, and any additional [Lumen] webservices at /api/v1 and /api/v2...
# This also works perfectly for all static file content in all projects
# This is full of debug comments so you can see how to print debug output to browser! Took me hours to nail this perfect config.
# Example:
# http://example.com - Main Laravel site as usual
# http://example.com/about - Main Laravel site about page as usual
# http://example.com/robots.txt - Main Laravel site static content as usual
# http://example.com/api/v1 - Lumen v1 api default / route
# http://example.com/api/v1/ - Lumen v1 api default / route
@oshinko
oshinko / install-rust-server-on-linux.sh
Created January 27, 2021 04:09
Install Rust Server on Linux
########################################################################
# Host your own Rust Dedicated Server
#
# see also: https://www.rustafied.com/how-to-host-your-own-rust-server
#
# Usage:
# RUST_HOME=$HOME/rust \
# RUST_SERVER_MAXPLAYERS=100 \
# RUST_SERVER_HOSTNAME="Your Rust Server" \
# RUST_SERVER_IDENTITY=your-rust-server \
@oshinko
oshinko / install-pgsql-12-from-source-code-on-amazon-linux-2.sh
Last active September 2, 2020 08:21
Install PostgreSQL 12 from Source Code on Amazon Linux 2
version=12.4 # ref: https://ftp.postgresql.org/pub/source/
sudo yum groupinstall "Development Tools" -y
sudo yum install readline readline-devel -y
wget -O - https://ftp.postgresql.org/pub/source/v$version/postgresql-$version.tar.bz2 | tar jxf -
cd postgresql-$version
# ref: https://www.postgresql.org/docs/12/install-short.html
./configure
make
@oshinko
oshinko / install-squid-on-amazon-linux-2.sh
Last active April 11, 2024 13:55
Install Squid on Amazon Linux 2
if [ -z "$CLIENT_IP_ADDR" ]; then
echo '$CLIENT_IP_ADDR is required'
exit 1
fi
sudo yum install squid -y
sudo systemctl enable squid
sudo sh -c "cat << 'EOF' > /etc/squid/squid.conf
# ACL My IP address
acl client_ip_addr src $CLIENT_IP_ADDR/32