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 / utc-oracle.sql
Created June 5, 2024 22:33
Get the UTC date in Oracle
CREATE OR REPLACE FUNCTION SYSDATEUTC RETURN DATE AS
BEGIN
RETURN CAST(sys_extract_utc(SYSTIMESTAMP) AS DATE);
END SYSDATEUTC;
@greenygh0st
greenygh0st / random-uuid.sh
Created December 28, 2023 19:31
Random UUID in Ruby via CLI
ruby -e "require 'securerandom'; puts SecureRandom.uuid"
@greenygh0st
greenygh0st / ubuntu-only-security-updates.sh
Created October 10, 2023 04:57
Only install security updates on Ubuntu
sudo apt-get -s dist-upgrade | grep "^Inst" | grep -i securi | awk -F " " {'print $2'} | xargs sudo apt-get install -y
@greenygh0st
greenygh0st / pg-chown.sql
Created September 30, 2022 02:03
Change the owner if all objects in a schema
-- taken from: https://dba.stackexchange.com/questions/171739/change-owner-of-all-schema-objects
CREATE OR REPLACE FUNCTION public.chown(in_schema character varying, new_owner character varying)
RETURNS void
LANGUAGE plpgsql
AS $function$
DECLARE
object_types VARCHAR[];
object_classes VARCHAR[];
object_type record;
@greenygh0st
greenygh0st / prettyNumberFormatter.swift
Created July 7, 2022 17:43
Formats numbers into a short hand format for easier reading.
extension Double {
func reduceScale(to places: Int) -> Double {
let multiplier = pow(10, Double(places))
let newDecimal = multiplier * self // move the decimal right
let truncated = Double(Int(newDecimal)) // drop the fraction
let originalDecimal = truncated / multiplier // move the decimal back
return originalDecimal
}
}
@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: