Skip to content

Instantly share code, notes, and snippets.

View oshinko's full-sized avatar

Oshinko oshinko

View GitHub Profile
@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
@oshinko
oshinko / sort-tasks.gs
Last active March 15, 2024 08:11
For the ToDo list of Google Spreadsheet
function sort() {
const TARGET_SHEETS = ['全て']
const sheet = SpreadsheetApp.getActiveSheet()
if (!TARGET_SHEETS.includes(sheet.getName()))
return
const [_, targetColumn] = sheet
.getRange(1, 1, 1, sheet.getMaxColumns())
@oshinko
oshinko / install-pgsql-11-from-source-code-on-amazon-linux-2.sh
Last active January 19, 2024 16:26
Install PostgreSQL 11 from Source Code on Amazon Linux 2
sudo yum groupinstall "Development Tools" -y
sudo yum install readline readline-devel systemd-devel -y
wget -O - https://ftp.postgresql.org/pub/source/v11.4/postgresql-11.4.tar.bz2 | tar jxf -
cd postgresql-11.4
# ref: https://www.postgresql.org/docs/11/install-short.html
./configure --with-systemd
make
sudo make install
sudo adduser postgres
@oshinko
oshinko / boolify.py
Last active November 24, 2022 10:37
Convert to Boolean
def boolify(value):
"""
Convert to bool.
>>> falsy = None, False, 0, b'', '', '0', 'false', 'off'
>>> truthy = True, 1, b'\\0', '1', 'true', 'on', 'A'
>>> any(boolify(x) for x in falsy)
False
>>> all(boolify(x) for x in truthy)
True
@oshinko
oshinko / hash-date.js
Last active April 13, 2022 02:42
Hash the date
d = new Date()
s = [d.getFullYear(), d.getMonth() + 1, d.getDate()].join('/')
(async function(text, n) {
data = new TextEncoder().encode(text)
hash = await window.crypto.subtle.digest('SHA-1', data)
uint = new DataView(hash, 0).getUint32()
console.log(text, uint % n)
})(s, 10)
@oshinko
oshinko / nt.bat
Last active April 12, 2022 00:25
Open a new tab in Windows Terminal
wt -w 0 nt -d %cd%\%1
@oshinko
oshinko / img2mp4.py
Last active April 2, 2022 13:12
Convert images to mp4
import pathlib
import subprocess
try:
import cv2
except ModuleNotFoundError:
import sys
subprocess.run(f'{sys.executable} -m pip install opencv-python',
shell=True)
import cv2
@oshinko
oshinko / docker-mysql-login-via-host.sh
Last active March 31, 2022 09:02
Run the MySQL sandbox container
docker run --rm -it mysql mysql -h host.docker.internal -u root -p --default-character-set=utf8 test
@oshinko
oshinko / install-python-3.8-on-debian.sh
Created December 1, 2019 03:09
Install Python 3.8 from Source Code on Debian
sudo apt-get update
sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev tar wget
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
sudo tar zxf Python-3.8.0.tgz
cd Python-3.8.0
sudo ./configure --enable-optimizations
sudo make -j 4
sudo make altinstall
python3.8 -V
@oshinko
oshinko / docker-linux.sh
Last active March 15, 2022 02:21
Run the Linux sandbox container
docker run --rm -it debian:latest /bin/bash