Skip to content

Instantly share code, notes, and snippets.

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

Tomáš Bouda TomasBouda

🏠
Working from home
View GitHub Profile
@TomasBouda
TomasBouda / CI_Functions_Core.ps1
Last active February 25, 2019 20:22
Extending Azure Build Pipeline with PowerShell
<#
.SYNOPSIS
Creates common headers for Azure Devops API
.DESCRIPTION
Creates common headers for Azure Devops API with prepared Authorization token and Content-Type application/json.
Must be executed from Azure Devops Pipeline to have the $env:SYSTEM_ACCESSTOKEN variable available.
.INPUTS
None. You cannot pipe objects to Get-CommonHeaders.
@TomasBouda
TomasBouda / Azure Devops.postman_collection.json
Last active February 17, 2019 19:11
Azure Devops API Requests
{
"info": {
"_postman_id": "bad5bcb8-d07d-498a-92c7-6f85c7429d4d",
"name": "Azure Devops",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "AddComment",
"request": {
@TomasBouda
TomasBouda / SendGridEmail.ps1
Last active April 28, 2019 10:17
Send email trough Send Grid API with powershell
function Send-GridEmail(){
Param(
[Parameter(Mandatory=$true)]
[string]$From,
[Parameter(Mandatory=$true)]
[object[]]$To,
[Parameter(Mandatory=$true)]
[string]$Subject,
[Parameter(Mandatory=$true)]
[string]$Body,
@TomasBouda
TomasBouda / SendGridEmail.ps1
Created April 28, 2019 19:42
Send email trough SendGrid SMTP relay with powershell
function Send-GridEmail(){
Param(
[Parameter(Mandatory=$true)]
[string]$From,
[Parameter(Mandatory=$true)]
[string[]]$To,
[Parameter(Mandatory=$true)]
[string]$Subject,
[Parameter(Mandatory=$true)]
[string]$Body,
@TomasBouda
TomasBouda / DivideEqualy.cs
Created May 23, 2019 09:09
Divides amount equaly between array of amounts
private decimal[] DivideEqualy(decimal[] array, decimal amount)
{
if (array.Length == 1)
{
return new decimal[] { amount };
}
decimal sum = array.Sum();
var precalculated = array.Select(l => amount * l / sum);
var ints = new LinkedList<int>(precalculated.Select(l => (int)l).OrderByDescending(x => x));
@TomasBouda
TomasBouda / DynVar.ps1
Created July 23, 2019 08:05
Dynamicaly create powershell variable
# config.json
#{
# "variables": [
# {
# "name": "basePath",
# "value": "C:\\inetpub\\approot"
# }
# ],
# "test": "$basePath\\test"
#}
@TomasBouda
TomasBouda / App_offline.htm
Last active November 12, 2019 18:35
Offline page for IIS, with auto reload
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv="refresh" content="10"/>
<title>Site Maintenance</title>
<style>
param(
[Parameter(Mandatory = $true)]
[string]$Source,
[Parameter(Mandatory = $true)]
[string]$Destination
)
$global:appOfflineGistUrl = 'https://gist.githubusercontent.com/TomasBouda/176632ebcccaf684ea09231935f4d300/raw/ff6662b3131ed43fe206403b62ec2129fae81a83/App_offline.htm'
function Copy-WithProgress {
public static class StringEncryption
{
private static readonly byte[] Entropy = Encoding.Unicode.GetBytes("4asd894a9d8as5d4sad4asd48sa9w8d4aw8da1d");
public static string EncryptString(this SecureString input)
{
var encryptedData = ProtectedData.Protect(
Encoding.Unicode.GetBytes(ToInsecureString(input)),
Entropy,
DataProtectionScope.CurrentUser);
@TomasBouda
TomasBouda / profiles.json
Last active June 25, 2020 11:19
Windows Terminal Settings
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"alwaysShowTabs": true,
"showTabsInTitlebar": true,