Skip to content

Instantly share code, notes, and snippets.

@zhangzhhz
zhangzhhz / WordPress_v5.3.2_with_Nginx.md
Last active June 23, 2020 17:24
Install WordPress v5.3.2 and self-host it over https using Nginx.
@zhangzhhz
zhangzhhz / common_MariaDB_commands.md
Last active November 29, 2021 04:37
Common Useful MySQL / MariaDB Commands
@zhangzhhz
zhangzhhz / python_proxy.txt
Created April 8, 2020 08:12
python program or PIP accessing internet via proxy
Set environment variables for proxies.
Windows:
set http_proxy=http://xxx.xxx.xxx.xxx:80
set https_proxy=http://xxx.xxx.xxx.xxx:80
Bash:
http_proxy=http://xxx.xxx.xxx.xxx:80
https_proxy=http://xxx.xxx.xxx.xxx:80

pip was broken after I installed pip3.8 and removed some other python links.

To fix pip:

python2 -m pip install --user --upgrade pip

python3 -m pip install --user --upgrade pip

@zhangzhhz
zhangzhhz / python_load_script_in_shell.md
Last active June 4, 2020 06:23
Python: load a script in Python shell

Python: load a script in Python shell

This is usually for some quick testing.

  1. python -i myscript.py

    Then you can reference functions and variables in the script directly.

  2. While you are already in a Python shell:

@zhangzhhz
zhangzhhz / check_certs.py
Created August 31, 2020 11:18
Get issuer, subject and dates for all certs in a single cert file
#!/usr/bin/env python3
import os
import sys
import subprocess
import tempfile
f = 'mycerts.pem' if len(sys.argv) == 1 else sys.argv[1]
if os.path.exists(f) and os.path.isfile(f):
@zhangzhhz
zhangzhhz / non-printable characters.MD
Last active October 8, 2020 07:52
Keep only printable characters in ASCII character set

https://en.wikipedia.org/wiki/ASCII#Printable_characters

Codes 20 to 7E, known as the printable characters, represent letters, digits, punctuation marks, and a few miscellaneous symbols. There are 95 printable characters in total.

Code 20, the "space" character, denotes the space between words, as produced by the space bar of a keyboard. Since the space character is considered an invisible graphic (rather than a control character) it is listed in the table below instead of in the previous section.

Code 7F corresponds to the non-printable "delete" (DEL) control character and is therefore omitted from this chart; it is covered in the previous section's chart. Earlier versions of ASCII used the up arrow instead of the caret (5E) and the left arrow instead of the underscore (5F).

Javascript:

#!/usr/bin/env python3
'''
You have notes in 3 denominations: two, five and ten.
Write a function `change` which takes in one argument which is the money amount,
and return the combination of the 3 notes using minimum number of notes
that adds up to the given amount.
Return None if it is not able to add up to the amount.
Assume you have infinite supply of notes in all 3 denominations.
Examples:
1: the function should return None

Notes from Practical Git for Everyday Professional Use on egghed.io.

git init

Initialize the current local directoy as a git repository locally.

git init --bare will make the local directory a bare repository which will act as a remote respository.

git clone <link>

Clone a remote repository locally. New directory will be created.

@zhangzhhz
zhangzhhz / base64-image.md
Created March 25, 2022 16:54
Encoding an image using base64 and decoding it

NodeJS

// base64 encoding a file
const base64EncodedString = fs.readFileSync(imageFileName).toString('base64');
// saving a base64 encoded image to a file
fs.writeFileSync(imageFileName, Buffer.from(base64EncodedString, 'base64'))

Python