Skip to content

Instantly share code, notes, and snippets.

View Wind010's full-sized avatar

Jeff Tong Wind010

View GitHub Profile
@Wind010
Wind010 / create_fork_bomb.sh
Created March 14, 2023 21:40
Create shell fork bomb
#!/bin/sh
# Usage: create_fork_bomb <function_name> <number_of_forks> <execute>
# The <execute> argument is option and will print out the fork bomb string instead of evaluating it.
create_fork_bomb() {
fn_name=$1
n=$2
run=$3
if (($n < 2)); then n=2; fi
for (( i=0; i<=$n; i++ )); do str="${str}|x"; done
@Wind010
Wind010 / GetApiKey.ps1
Created February 25, 2023 05:13
Get API key via basic auth. Curl.exe -u functionality
function GetApiKey()
{
Param(
[Parameter(Mandatory=$false, Position=0, ValueFromPipeline=$false)]
[ValidateNotNullOrEmpty()]
[string] $userName,
[Parameter(Mandatory=$false, Position=1, ValueFromPipeline=$false)]
[SecureString] $useStaging
@Wind010
Wind010 / CopyFromFtpToBlob.ps1
Created February 21, 2023 21:36
Powershell script to copy files from FTP server to blob store.
# Script used to copy files from specified FTP server.
# Requires the WinSCP .NET Assembly and WinSCP.exe: https://winscp.net/download
# Requires Azure CLI: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli
# Usage:
# CopyFromFtpToBlob.ps1 <ftp_hostname> <ftp_username> <ftp_password> <ftp_directory_path> <source_file_names> <storage_account_connection_string> <container> <destination_path_under container>
# The <ftp_password> is expected to bee a secure string:
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/convertto-securestring?view=powershell-7.3
# The <source_file_names> is an array of filenames. If empty, all files in <ftp_directory_path> will be used.
# Additional
# Read from file into array:
@Wind010
Wind010 / AzureEventHub.psm1
Created February 3, 2023 01:46
A module that contains logic to send/publish event messages to specified Azure Event Hub.
function Get-SASToken
{
<#
.DESCRIPTION
Compute a valid SAS-token for accessing an Azure Event Hub / Service Bus
.PARAMETER EventHubNamespace
The Azure Event Hub Namespace
.PARAMETER EventHubName
@Wind010
Wind010 / standardize_values.py
Created January 16, 2023 00:34
Standardizing Input Values with Pyspark
# Databricks notebook source
from pyspark.sql import SparkSession, DataFrame, DataFrameWriter
from pyspark.sql.functions import udf, to_timestamp
import pyspark.sql.functions as f
from pyspark.sql.types import StructType, StructField, StringType, IntegerType, BooleanType, TimestampType
from typing import List, Set, Tuple, Dict
from datetime import datetime
from delta.tables import *
from pyspark.sql import Row
@Wind010
Wind010 / Encoder.py
Created December 26, 2022 00:04
Used for better understanding of Base64 encoding.
def solution(encoding, message):
class BaseEncoder():
BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
UTF_8_BYTE_SIZE, B64_BYTE_SIZE, BINARY_BASE = 8, 6, 2
@staticmethod
def encode(message, in_byte_size, out_byte_size, char_set):
enc_msg, padding = '', ''
# Get the ascii code and convert that to binary. ord('A') = 65; bin(65) = 0b1000001
@Wind010
Wind010 / UpdateTargetFramework.ps1
Last active December 23, 2022 04:52
Update the TargetFramework/TargetFrameworks tag in .csproj
###
# Usage:
# Test/DryRun and just report what would have changed.
# UpdateTargetFrameworks.ps1 -TargetFrameworks @('net6.0') -UpdateWithXmlDoc $true -Path "SomePath" -DryRun $true
# Do the update with XPATH via XmlDocument:
# UpdateTargetFrameworks.ps1 @('net6.0') $true
# Do the update with replace:
# UpdateTargetFrameworks.ps1 @('net6.0') $false
###
param(
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace CommonTests.Attributes
{
/// <summary>
/// Abstract base class for use with TestMethodWithIgnoreIfSupportAttribute.cs.
/// Interfaces don't
/// </summary>
@Wind010
Wind010 / create_azure_devops_release_definition.sh
Last active October 11, 2022 22:46
Create an Azure DevOps release definition from file.
#!/bin/bash
# Usage
# ./create_azure_devops_release_definition.sh "YOUR_ORG" "YOUR_PROJECT"
Organization=$1
Project=$2
azureDevOpsTokenUri="https://vssps.dev.azure.com/$Organization"
azureDevOpsReleaseUri="https://vsrm.dev.azure.com/$Organization"
@Wind010
Wind010 / settings.json
Created June 11, 2022 01:43
VS Code Python Pytest command line args settings
{
"cSpell.ignoreWords": [
"assertpy",
"backfilling",
"checkpointed",
"checkpointing",
"dagrr",
"databricks",
"dataframe",
"dataframes",