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 / gist:a01f22437818a001af80e7f6f0963c88
Created August 24, 2018 07:20 — forked from BrandonLWhite/gist:235fa12247f6dc827051
Import .cer and .pvk certificate files programmatically in C# for use with `netsh http add sslcert`
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
var abyPublicKey = AssemblyUtility.GetEmbeddedFileAsByteArray("WebServer.SslCertificate.cer");
var abyPrivateKey = AssemblyUtility.GetEmbeddedFileAsByteArray("WebServer.SslCertificate.pvk");
var certificate = new X509Certificate2(abyPublicKey, string.Empty,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
var cspParams = new CspParameters
{
@ZakFong
ZakFong / OracleDynamicParameters.cs
Created July 1, 2017 07:56 — forked from vijayganeshpk/OracleDynamicParameters.cs
OracleDynamicParameters class for Dapper
using Dapper;
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
public class OracleDynamicParameters : Dapper.SqlMapper.IDynamicParameters {
private static Dictionary<SqlMapper.Identity, Action<IDbCommand, object>> paramReaderCache = new Dictionary<SqlMapper.Identity, Action<IDbCommand, object>>( );