Skip to content

Instantly share code, notes, and snippets.

View greenygh0st's full-sized avatar
🏠
Working from home - like a lot of us...

Dale Myszewski greenygh0st

🏠
Working from home - like a lot of us...
View GitHub Profile
@greenygh0st
greenygh0st / delete-bad-pods.sh
Last active March 24, 2022 00:59
Removed bad and failed Kubernetes pods
# all
kubectl get pods --all-namespaces | grep -E 'ImagePullBackOff|ErrImagePull|Evicted|Terminating' | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod --grace-period=0 --force
# not terminated
kubectl get pods --all-namespaces | grep -E 'ImagePullBackOff|ErrImagePull|Evicted' | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod --grace-period=0 --force
# manual scaling adjustment
kubectl scale --replicas=0 deployment <deployment>
@greenygh0st
greenygh0st / csharp-batching-interview-question.cs
Last active July 28, 2021 18:40
A favorite interview question of mine... how to run an async batch job against a large list of objects
public class Person {
public string FirstName { get; set; }
public string LastName { get;set; }
public int Age { get; set; }
public async Task Finalize() {
// does something does not matter what
}
}
@greenygh0st
greenygh0st / app.component.ts
Created September 11, 2020 07:21 — forked from alex-okrushko/app.component.ts
Exponential backoff retry - example with fake service
import { Component } from '@angular/core';
import { of } from 'rxjs';
import { tap, switchMap} from 'rxjs/operators';
import { retryBackoff } from 'backoff-rxjs';
import { BackendService, HttpError } from './backend.service';
export const INIT_INTERVAL_MS = 100; // 100 ms
export const MAX_INTERVAL_MS = 20 * 1000; // 20 sec
@Component({
@greenygh0st
greenygh0st / start-service-if-stopped.ps2
Last active October 22, 2021 19:34
A script for starting and stepping Windows services in a controlled and non-error inducing way...
$ServiceName = 'Serenade'
$arrService = Get-Service -Name $ServiceName
while ($arrService.Status -ne 'Running')
{
Start-Service $ServiceName
write-host $arrService.status
write-host 'Service starting'
Start-Sleep -seconds 5

Git branch in prompt.

parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/ [\1]/' }

export PS1="\u@\h \W[\033[01;33m]$(parse_git_branch)[\033[00m] $ "

Here are some other terminal colour codes you can use:

Some other cool options:

@greenygh0st
greenygh0st / some-component.ts
Last active July 23, 2020 23:21
Debounce search fields in Angular
// In HTML component
// <input placeholder="Search" ... (keyup)="onSearchKeyUp()" [(ngModel)]="searchFilter" />
// in .ts file
searchFilter: string;
private searchSubject: Subject<string> = new Subject();
private searchSubscription: Subscription;
filterItems() {
// do the thing by searchFilter
List<string> errors = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage)
DateTime date = DateTime.Now;
string oracleDateString = $"to_date('{date.Now.ToString("MM/dd/yyyy hh:mm:ss tt")}','MM/DD/YYYY HH:MI:SS AM')";
/// <summary>
/// Helper methods for the lists.
/// </summary>
public static class ListExtensions
{
public static List<List<T>> ChunkBy<T>(this List<T> source, int chunkSize)
{
return source
.Select((x, i) => new { Index = i, Value = x })
.GroupBy(x => x.Index / chunkSize)
@greenygh0st
greenygh0st / uuid-segment-regex.txt
Created March 22, 2020 21:39
A regex meant to be used to safely search for uuid segments
^(?!.*--)[A-Za-z0-9_-]*$