Skip to content

Instantly share code, notes, and snippets.

View didil's full-sized avatar

Adil H didil

View GitHub Profile
@didil
didil / iteration_sort_generics_ordered_test.go
Created January 26, 2023 14:40
test go iteration sort generics ordered
func TestInsertSortGenericInt(t *testing.T) {
items := []int{3, 55, 4, 9, 8, 7, 67, 51}
InsertSort(items)
assert.Equal(t, items, []int{3, 4, 7, 8, 9, 51, 55, 67})
}
func TestInsertSortGenericString(t *testing.T) {
items := []string{"mike", "john", "adil", "aaron", "julia"}
@didil
didil / iteration_sort_int_test.go
Created January 26, 2023 14:37
test go iteration sort no generics
func TestInsertInt(t *testing.T) {
items := []int{6, 55, 4, 9, 8, 7, 67, 51}
InsertSortInt(items)
assert.Equal(t, items, []int{4, 6, 7, 8, 9, 51, 55, 67})
}
@didil
didil / iteration_sort_generics_ordered.go
Created January 26, 2023 14:32
go iteration sort generics ordered
func InsertSort[T constraints.Ordered](items []T) {
for i := 1; i < len(items); i++ {
// loop through subslices
for j := i; j > 0; j-- {
if items[j] < items[j-1] {
// swap elements if not ordered
items[j], items[j-1] = items[j-1], items[j]
}
}
}
@didil
didil / iteration_sort_generics_any.go
Created January 26, 2023 13:46
go iteration sort generics any
func InsertSortAny[T any](items []T) {
for i := 1; i < len(items); i++ {
// loop through subslices
for j := i; j > 0; j-- {
if items[j] < items[j-1] {
// swap elements if not ordered
items[j], items[j-1] = items[j-1], items[j]
}
}
}
@didil
didil / iteration_sort_int.go
Created January 26, 2023 13:33
go iteration sort no generics
func InsertSortInt(items []int) {
for i := 1; i < len(items); i++ {
// loop through subslices
for j := i; j > 0; j-- {
if items[j] < items[j-1] {
// swap elements if not ordered
items[j], items[j-1] = items[j-1], items[j]
}
}
}
@didil
didil / deployment_test.go
Created November 19, 2020 17:19
Deployment test
Context("When creating a deployment", func() {
var deployment *appsv1.Deployment
var bucket *abv1.Bucket
It("Should create the bucket crd", func() {
ctx := context.Background()
gcpSvc.On("CreateBucket", mock.AnythingOfType("*context.emptyCtx"), BucketFullName).Return(nil)
deployment = &appsv1.Deployment{
@didil
didil / bucket_reconcile.go
Created November 19, 2020 17:13
Bucket Reconcile Loop
func (r *BucketReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
ctx := context.Background()
log := r.Log.WithValues("bucket", req.NamespacedName)
bucket := &abv1.Bucket{}
err := r.Get(ctx, req.NamespacedName, bucket)
if err != nil {
if errors.IsNotFound(err) {
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
@didil
didil / deployment_reconcile.go
Created November 19, 2020 17:09
Deployment Reconcile Loop
func (r *DeploymentReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
ctx := context.Background()
log := r.Log.WithValues("deployment", req.NamespacedName)
dep := &appsv1.Deployment{}
err := r.Get(ctx, req.NamespacedName, dep)
if err != nil {
if errors.IsNotFound(err) {
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
@didil
didil / autobucket_deployment.yaml
Created November 19, 2020 17:02
Autobucket Deployment example
apiVersion: apps/v1
kind: Deployment
metadata:
name: bucket-text-api
labels:
app: bucket-text-api
annotations:
## Custom Annotations start here
ab.leclouddev.com/cloud: gcp
ab.leclouddev.com/name-prefix: ab
@didil
didil / bucket.yaml
Created November 19, 2020 16:58
Bucket example
apiVersion: ab.leclouddev.com/v1
kind: Bucket
metadata:
name: my-app
spec:
cloud: gcp
fullName: ab-default-my-app
onDeletePolicy: destroy