Skip to content

Instantly share code, notes, and snippets.

@andy51002000
andy51002000 / APIKeyMessageHandler.cs
Last active October 22, 2019 03:54
API Key Message handler to protect the REST API Endpoint
public class APIKeyMessageHandler : DelegatingHandler
{
private const string APIKey = "ZG95b3Vrbm93dGhhdGFjZXJpc3RoZWJlc3Rjb21wYW55aW50aGV3b3JsZGJ5YW5keQ==";
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
bool validKey = false;
IEnumerable<string> requestHeaders;
var checkApiKeyExists = request.Headers.TryGetValues("MyAPIKey", out requestHeaders);
if (checkApiKeyExists)
@andy51002000
andy51002000 / QuickCreate3VM.ps1
Created September 7, 2019 03:50
Quick Create 3 VM on Hyper V
$VM_PATH='C:\Users\andy5100\Documents\export\ubuntu\ubuntu-pure\Virtual Machines\1B241D9D-7353-4977-B759-F7E0C1A126DC.vmcx'
$VM_DEST_MASTER='C:\Users\andy5100\Documents\k8s2\master'
$VM_DEST_NODE1='C:\Users\andy5100\Documents\k8s2\node1'
$VM_DEST_NODE2='C:\Users\andy5100\Documents\k8s2\node2'
$VM_DEST_LIST=@($VM_DEST_MASTER, $VM_DEST_NODE1, $VM_DEST_NODE2)
foreach ( $DEST in $VM_DEST_LIST) {
const sql = require('mssql')
const config = {
user: '',
password: '',
server: '', // You can use 'localhost\\instance' to connect to named instance
database: '',
options: {
encrypt: true // Use this if you're on Windows Azure
}
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
corpus = ['The cat sat on the mat', 'The dog sat on the mat', 'The goat sat on the mat']
vectorizer = CountVectorizer(lowercase=True, analyzer='word', binary=False)
representation = vectorizer.fit_transform(corpus)
representation_df = pd.DataFrame(data = representation.toarray(), columns=sorted(vectorizer.vocabulary_.keys()))
@andy51002000
andy51002000 / Get-Random-Filename.ps1
Last active June 17, 2019 03:18
Get Random Filename in powershell
function Get-RandomFilename {
[IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetRandomFileName() )
}
Get-RandomFilename
# Result ------------------------------
# PS C:\Windows\system32> Get-RandomFilename
# cbzivvcs
#
@andy51002000
andy51002000 / PowerShellJson.ps1
Created June 16, 2019 23:39
Query Azure resource information and access the json output
$appUserPWD= $(az webapp deployment list-publishing-profiles --name $appname --resource-group $resouceGroup --query '[0].{userPWD:userPWD,userName:userName}' -o json | ConvertFrom-Json )
$appUserPWD
$appUserPWD.userPWD
# Result >
# PS C:\Windows\system32> $appUserPWD
#
# userName userPWD
# -------- -------
# $webSite-botapp-123fz3m6x4 hm7lwb8rqpARtLki9uz5Thx6oFadERGWaX1vgjXQ1eyCrdT
@andy51002000
andy51002000 / listfile.js
Created June 15, 2019 23:44
Node.js list all files in a directory
const testFolder = './tests/';
const fs = require('fs');
fs.readdirSync(testFolder).forEach(file => {
console.log(file);
});
@andy51002000
andy51002000 / azureBlobHelper.js
Created December 18, 2018 07:00
Create Container on Azure Blob
var azure = require('azure-storage');
var blobService = azure.createBlobService("andytestapp",
"5gs4i123123adasd23423423412312323423424234234234234Mg==");
module.exports = {
createContainerIfNotExists(containerName) {
return new Promise(function(resolve, reject) {
blobService.createContainerIfNotExists(containerName, {
publicAccessLevel: 'blob'
@andy51002000
andy51002000 / Base64EncodeInSize44.cs
Last active December 7, 2018 02:33
Base64 Encoding In Limited Size 44
using System;
using System.Text;
using System.Security.Cryptography;
public class Program
{
public static void Main()
{
byte[] SHA256Data = Encoding.UTF8.GetBytes("12345678");
SHA256Managed Sha256 = new SHA256Managed();
byte[] Result = Sha256.ComputeHash(SHA256Data);
@andy51002000
andy51002000 / MVVM.cs
Created November 2, 2018 09:52 — forked from heiswayi/MVVM.cs
C# MVVM common classes in a single file. Example of usage: https://heiswayi.github.io/2016/mvvm-common-classes-in-single-file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Windows;
using System.Windows.Input;
namespace HeiswayiNrird.MVVM.Common
{