Skip to content

Instantly share code, notes, and snippets.

type Node struct {
Data int
Left *Node
Right *Node
}
func NewNode(data int) *Node {
return &Node{data, nil, nil}
}
func DFRec(n *Node) {
if n == nil {
return
}
DFRec(n.Left)
n.Process()
DFRec(n.Right)
}
func DF(n *Node) {
s := Stack{}
current := n
for {
if s.IsEmpty() && current == nil { return }
if current != nil {
s.Push(current)
current = current.Left
} else {
current, _ = s.Pop()
func main() {
start := time.Now()
n := NewNode(1)
n.Left = NewNode(2)
n.Right = NewNode(3)
n.Left.Left = NewNode(4)
n.Left.Right = NewNode(5)
n.Right.Left = NewNode(6)
n.Right.Right = NewNode(7)
var wg sync.WaitGroup
func DFRecImproved(n *Node){
if n == nil {
return
}
wg.Add(1)
go DFRecImproved(n.Left)
n.Process()
wg.Add(1)
func main() {
n := NewNode(1)
n.Left = NewNode(2)
n.Right = NewNode(3)
n.Left.Left = NewNode(4)
n.Left.Right = NewNode(5)
n.Right.Left = NewNode(6)
n.Right.Right = NewNode(7)
n.Right.Right.Left = NewNode(8)
package main
import (
"fmt"
"sync"
"time"
)
var wg sync.WaitGroup
@esys
esys / autoscaler-eks.ts
Last active January 30, 2023 10:40
eks cdk install cluster autoscaler
import * as cdk from "@aws-cdk/core";
import * as eks from "@aws-cdk/aws-eks";
import * as ec2 from "@aws-cdk/aws-ec2";
import * as iam from "@aws-cdk/aws-iam";
import { CfnJson } from "@aws-cdk/core";
export class MyCluster extends cdk.Construct {
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
enableAutoscaling(cluster: eks.Cluster, ng: eks.Nodegroup, version: string = "v1.17.3") {
const autoscalerStmt = new iam.PolicyStatement();
autoscalerStmt.addResources("*");
autoscalerStmt.addActions(
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeLaunchConfigurations",
"autoscaling:DescribeTags",
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup",
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-scale
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template: