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 / 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>>( );
@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 / InitializeNLog.cs
Last active November 18, 2018 08:00
C# - NuGet - NTRPRS.NLog.Slack - Programmatically set the NLog.config to log to Slack.
/// <summary>
/// Initialize NLog settings. Mainly for Slack sync use.
/// </summary>
private void InitializeNlog()
{
var slackWebHookUrl = AppSettings["NLogToSlackWebHookUrl"];
if (string.IsNullOrWhiteSpace(slackWebHookUrl))
{
return;
@ZakFong
ZakFong / Python - Read Text File.py
Created July 28, 2019 07:25
Python - Read Text File.
# Text File.
with open('test.txt', 'r') as f:
data = f.readlines()
print(data)
@ZakFong
ZakFong / Python - Read JSON.py
Created July 28, 2019 07:29
Python - Read JSON.
# JSON.
import json
with open('test.json', 'r') as f:
data = json.load(f)
print(data)
@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')
@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 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 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 npy.py
Created July 28, 2019 10:18
Python - Read npy.
# numpy
# pip install numpy
import numpy as np
arr = np.load('test.npy')