Skip to content

Instantly share code, notes, and snippets.

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

Zak Fong ZakFong

🏠
Working from home
View GitHub Profile
@ZakFong
ZakFong / file_magic_numbers.md
Created September 27, 2022 03:03 — forked from leommoore/file_magic_numbers.md
File Magic Numbers

File Magic Numbers

Magic numbers are the first bits of a file which uniquely identify the type of file. This makes programming easier because complicated file structures need not be searched in order to identify the file type.

For example, a jpeg file starts with ffd8 ffe0 0010 4a46 4946 0001 0101 0047 ......JFIF.....G ffd8 shows that it's a JPEG file, and ffe0 identify a JFIF type structure. There is an ascii encoding of "JFIF" which comes after a length code, but that is not necessary in order to identify the file. The first 4 bytes do that uniquely.

This gives an ongoing list of file-type magic numbers.

Image Files

@ZakFong
ZakFong / Socket.class
Created November 12, 2020 15:53 — forked from bongbongco/Socket.class
C# Port Forwarding
using System;
using System.Net;
using System.Net.Sockets;
namespace BrunoGarcia.Net
{
public class TcpForwarderSlim
{
private readonly Socket _mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
@ZakFong
ZakFong / IoT - MQTT - AWS Publish & Subscribe.sh
Last active August 29, 2019 19:01
IoT - MQTT - AWS Publish & Subscribe
The Mosquitto Publish CLI
Linux
$> mosquitto_pub --cert certificate.pem.crt --key private.pem.key --cafile AmazonCA1.pem -h XXXXXXXXYYYYY-ats.iot.us-west-2.amazonaws.com -p 8883 -t 'test/thing' -m 'Hello from Mosquitto'
Windows
mosquitto_pub --cert certificate.pem.crt --key private.pem.key --cafile AmazonRootCA1.pem -h af20rc7y2njn8-ats.iot.us-east-2.amazonaws.com -p 8883 -t "vender/svm/check" -m "Hello from Mosquitto"
@ZakFong
ZakFong / C# - Windows Form - TextBox append text.cs
Created August 11, 2019 17:47
C# - Windows Form - TextBox append text.
private void Log(string message)
{
if (TestTextBox.InvokeRequired)
{
Invoke(new Action<string>(Log), message);
return;
}
TestTextBox.AppendText($"{DateTime.Now:yyyy/MM/dd HH:mm:ss.fff}|{message}|{Environment.NewLine}");
}
@ZakFong
ZakFong / OpenSSL - Export to PFX format from origin certificate and private key.sh
Created August 1, 2019 08:50
OpenSSL - Export to PFX format from origin certificate and private key.
# "x" represent file name.
# "*" represent password.
openssl pkcs12 -export -out xxxxxxxx.pfx -inkey xxxxxxxx-private.pem.key -in xxxxxxxx-certificate.pem.crt -passout pass:********
@ZakFong
ZakFong / Python - Read npy.py
Created July 28, 2019 10:18
Python - Read npy.
# numpy
# pip install numpy
import numpy as np
arr = np.load('test.npy')
@ZakFong
ZakFong / Python - Read Image by skimage.py
Created July 28, 2019 10:15
Python - Read Image by skimage.
# skimage
# pip install scikit-image
import skimage.io as skio
image = skio.imread('test.jpg')
@ZakFong
ZakFong / Python - Read Image by PIL.py
Created July 28, 2019 09:46
Python - Read Image by PIL.
# pillow
# pip install pillow
from PIL import Image
image = Image.open('test.jpg')
@ZakFong
ZakFong / Python - Read Image by opencv.py
Created July 28, 2019 09:41
Python - Read Image by opencv.
# opencv
# pip install opencv
import cv2
# Read Image. (BGR format)
image = cv2.imread('test.jpg')
# Convert color mode.
@ZakFong
ZakFong / Python - Read Matrix.py
Created July 28, 2019 07:32
Python - Read Matrix.
# Matrix.
import scipy.io as sio
data = sio.loadmat('matrix.mat')