Skip to content

Instantly share code, notes, and snippets.

@Tianjie-Wu
Tianjie-Wu / float_to_rgba.py
Created September 5, 2023 02:00 — forked from DavidAntliff/float_to_rgba.py
Encode 32bit float into three 8bit RGBA channels
#!/usr/bin/env python
# Store 32-bit floating point number within three 8bit channels of a 32-bit RGBA pixel.
# Only suitable for normalised input values in the range [0.0, 1.0).
#
# Refer: https://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
import numpy as np
def frac(x):
return x - np.floor(x)
@Tianjie-Wu
Tianjie-Wu / fail2ban_amznlnx2.sh
Created August 30, 2023 09:23 — forked from johnstanfield/fail2ban_amznlnx2.sh
install fail2ban on amazon linux 2
# run as root or sudo everything below
# install epel
amazon-linux-extras install epel -y
# install fail2ban
yum -y install fail2ban
# configure fail2ban (just adding enabled=true in the sshd section)
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
@Tianjie-Wu
Tianjie-Wu / count_data_by_xy.py
Created April 20, 2023 02:36
pandas count_data_by_xy
def create_1d_middle_mean_array(arr):
mean_arr = []
for i in range(arr.shape[0] - 1):
mean = (arr[i] + arr[i+1])/2.0
mean_arr.append(mean)
return numpy.array(mean_arr)
def x_to_2d_with_duplication(X,num_rows):
data_2d = numpy.tile(X, (num_rows, 1))
return data_2d
@Tianjie-Wu
Tianjie-Wu / build_2d_3d_from_1d.py
Created March 30, 2023 10:16
build 2d or 3d data from flatten dataset
def build_1_dim_data(data_for_dim1):
data_shape = data_for_dim1.shape
DATA1D = numpy.zeros((data_shape[0],1),dtype=float)
DATA1D[:,0] = data_for_dim1
return DATA1D
def build_2_dim_data(data_for_dim1, data_for_dim2):
data_shape = data_for_dim1.shape
DATA2D = numpy.zeros((data_shape[0],2),dtype=float)
DATA2D[:,0] = data_for_dim1
DATA2D[:,1] = data_for_dim2
@Tianjie-Wu
Tianjie-Wu / colormap.py
Created January 26, 2023 08:20
colormap for rainfall plot
nws_precip_colors = [
"#ffffff",
"#04e9e7", # 0.01 - 0.10 inches
"#019ff4", # 0.10 - 0.25 inches
"#0300f4", # 0.25 - 0.50 inches
"#02fd02", # 0.50 - 0.75 inches
"#01c501", # 0.75 - 1.00 inches
"#008e00", # 1.00 - 1.50 inches
"#fdf802", # 1.50 - 2.00 inches
"#e5bc00", # 2.00 - 2.50 inches
#!/bin/bash
#Whenever you clone a repo, you do not clone all of its branches by default.
#If you wish to do so, use the following script:
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done