Skip to content

Instantly share code, notes, and snippets.

View pizycki's full-sized avatar

Paweł Iżycki pizycki

View GitHub Profile
@pizycki
pizycki / zad1.c
Last active July 1, 2021 18:49
Kolo 2 Tiarek
#include <math.h>
#include <stdio.h>
double a(int n)
{
return (n * (pow(n, 2) - 25.5)) / (2 * n + 1.5);
}
int main()
{
@pizycki
pizycki / Restart-UnreadyDeployments.ps1
Created April 30, 2021 13:51
Restart all unhealthy k8s deployments
kubectl get deployments -n app-team -o json `
| ConvertFrom-Json `
| % { $_.items } `
| ? { ($_.status.conditions | ? { $_.type -eq "Available" }).Status -eq "False" }
| % { $_.metadata.name }
| % { kubectl rollout restart deployments/$_ -n app-team }
@pizycki
pizycki / Replace-VersionInSolution.ps1
Created April 27, 2021 13:10
Replace text in many files
$rootDir = "C:\Users\pawel\dev\blabla"
$majorVersion = "42"
Get-ChildItem $rootDir -File -Recurse `
| Where-Object { $_.Name -match ".(csproj|cs|nuspec|config)$" } `
#| % { write $_.FullName }
| ForEach-Object {
$content = Get-Content -Encoding utf8 $_.FullName
$content = $content.Replace("Namespace.VX", "Namespace.V$($majorVersion)")
Set-Content -Encoding utf8 $_.FullName $content
}
@pizycki
pizycki / Set-KubeCluster.ps1
Created April 23, 2021 10:03
Interactive Kubernetes Context Set
function Set-KubeCluster {
$i = 1
$contexts = kubectl config get-contexts --no-headers -o name
$contexts `
| ForEach-Object {
Write-Output "$(($i++)): $_"
}
[int]$answer = Read-Host -Prompt "Which context do you choose?"
$choosen = $contexts[($answer-1)] # Counting starts from 1
@pizycki
pizycki / zad1_4_5.c
Last active April 18, 2021 11:35
Tiarkowe kolokwium
#include <stdio.h>
int main()
{
//////////////////////////
// Zad. 1
//////////////////////////1
double wiszenko;
printf("Wpisz wartosc dla nazwisko studenta:\n");
@pizycki
pizycki / Program.cs
Created April 2, 2021 10:36
Connect Octopus projects with all tenants and envs
var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey);
var repository = new OctopusRepository(endpoint);
var client = new OctopusClient(endpoint);
var space = repository.Spaces.FindByName(spaceName);
var repositoryForSpace = client.ForSpace(space);
var projects = repositoryForSpace.Projects.GetAll().Where(x => !x.IsDisabled);
var envs = repositoryForSpace.Environments.GetAll();
foreach (var project in projects)
@pizycki
pizycki / CancellationTokenSource.cs
Last active February 17, 2021 17:25
Timeout operation with .NET CancellationTokenSource
async Task Main()
{
var sw = new Stopwatch();
sw.Start();
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3));
await Foo(cts.Token);
sw.Stop();
Console.WriteLine("Elapsed " + sw.ElapsedMilliseconds);
}
@pizycki
pizycki / Restore-NugetPackege.ps1
Last active June 10, 2020 15:00
Restores recycled NuGet Package from Azure Artifacts Recycle bin
###################################################
# Params
###################################################
$p = "" # eg "bc.cqrs"
$v = "" # eg "3.1.0.48-featureupdatefluentv"
$pat = ""
$org = ""
$project = ""
@pizycki
pizycki / Install-OpenSshServer.ps1
Last active June 6, 2020 14:47
Installs OpenSSH Server on Windows 10
# Run as Administrator
$openSshStatus = Get-WindowsCapability -Online | ? Name -like 'OpenSSH.Server*'
if($openSshStatus[0].State -eq "NotPresent"){
Write-Output "OpenSSH server not detected. Processing to installation..."
$installResult = Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
if($installResult.Online -eq $true){
Write-Output "Installation succeeded."
}
} else {
@pizycki
pizycki / DeployLatestOctopusReleaseWithRequiredParam.cs
Last active April 15, 2020 16:14
Run Octopus Deployment from the newest Release and pass required parameter
void Main()
{
var server = "https://octopusdeploy....org/";
var apiKey = "API-....VYOR68S";
var endpoint = new OctopusServerEndpoint(server, apiKey);
var repository = new OctopusRepository(endpoint);
var azSpace = repository.Spaces.FindByName("Azure");
var azRepo = repository.ForSpace(azSpace);
var createVmProject = azRepo.Projects.FindByName("Create VM");
var defaultChannel = azRepo.Channels.FindByName(createVmProject, "Default");