Skip to content

Instantly share code, notes, and snippets.

View hansheng0512's full-sized avatar
🏠
Working from home

Han Sheng hansheng0512

🏠
Working from home
View GitHub Profile
@hansheng0512
hansheng0512 / crypto.ts
Created September 20, 2024 03:14
Encrypt and Decrypt string using Typescript
import * as crypto from 'crypto';
// Secret key generation (should be stored securely and not hardcoded)
const secretKey = crypto.createHash('sha256').update(String('your-secret-key')).digest('base64').substr(0, 32);
function encrypt(text: string): string {
const iv = crypto.randomBytes(16); // Initialization vector
const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(secretKey), iv);
const encrypted = Buffer.concat([cipher.update(text, 'utf8'), cipher.final()]);
// Return the IV and encrypted data as a combined string
@hansheng0512
hansheng0512 / sample.txt
Created November 8, 2023 13:39
Trial Balance Report
Trial Balance Report - January 31, 2023
Account Name Debit ($) Credit ($)
----------------------------------------------------
Loan Receivables 100,000 -
Interest Income - 2,000
Loan Origination Fees 3,000 -
----------------------------------------------------
Total 103,000 2,000
def generate_pdf(data):
response = select_one_data("SELECT * FROM pdf")
if(not response["success"]):
return jsonify({"msg": "Database Error", "error_msg": response["error_msg"], "success": False})
subprocess.call(["php", "tfpdf.php"], shell=True)
pdf = FPDF('P', 'in', 'A4');
pdf.add_page()
@hansheng0512
hansheng0512 / video.sh
Created September 10, 2021 18:09
GStreamer + FFmpeg + Opencv Setup in Ubuntu
## gstreamer
sudo apt-get install libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-bad1.0-dev \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
gstreamer1.0-doc \
@hansheng0512
hansheng0512 / upload.py
Last active September 9, 2021 06:33
AWS S3
import boto3
from botocore.exceptions import NoCredentialsError
ACCESS_KEY = "xxxxxxxxxxxx"
SECRET_KEY = "xxxxxxxxxxxxxxxxxxxx"
def upload_to_aws(local_file, bucket, s3_file):
s3 = boto3.client("s3", aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
git clone https://github.com/tesseract-ocr/tesseract.git
git checkout -b <branch name / version>
sudo sh autogen.sh
sudo ./configure
sudo LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include" make
sudo make install
sudo make install -langs
sudo ldconfig
@hansheng0512
hansheng0512 / opencv_install.sh
Created September 1, 2021 13:21
Opencv Install Shellscript
######################################
# INSTALL OPENCV ON UBUNTU OR DEBIAN #
######################################
# -------------------------------------------------------------------- |
# SCRIPT OPTIONS |
# ---------------------------------------------------------------------|
OPENCV_VERSION='4.5.1' # Version to be installed
OPENCV_CONTRIB='NO' # Install OpenCV's extra modules (YES/NO)
# -------------------------------------------------------------------- |
@hansheng0512
hansheng0512 / README.md
Last active May 3, 2024 14:19
Increase SWAP Memory Size in Jetson Nano
  1. Run Command Below
sudo apt-get install -y dphys-swapfile
  1. Run sudo gedit /sbin/dphys-swapfile
  2. Change CONF_MAXSWAP to 4096, save and exit
  3. Run sudo gedit /etc/dphys-swapfile
  4. Enable CONF_SWAPSIZE and put 4096, save and exit
  5. Run sudo reboot . to restart Jetson Nano 7.Run free -m and check the Swap total
@hansheng0512
hansheng0512 / README.md
Created August 27, 2021 07:23
Add Ant Design RN for React Native Project

Ant Design RN Setup

  1. Execute Code Below
yarn add npm install antd-mobile-rn
yarn add npm install babel-plugin-import
yarn add @react-native-community/viewpager
  1. Modify babel.config.js.
@hansheng0512
hansheng0512 / result.json
Last active August 22, 2021 03:52
Example Output for Spanish Id Card Information Extraction
{
"front": {
"annotation": {
"Sex": "M",
"Date of Birth": "17 12 1997",
"Document": "0NE158350",
"Nationality": "ESP",
"Date of Expiry": "05 11 2025",
"personal": "73659110T",
"address_num": "128256",