Skip to content

Instantly share code, notes, and snippets.

@niski84
niski84 / gist:c1f5e733cfb90617e8573e577c1b8f6d
Created January 6, 2023 08:05
jenkins login with crumb
package main
import (
"fmt"
"github.com/bndr/gojenkins"
)
func main() {
// Create a Jenkins client
@niski84
niski84 / gist:adc7b2af9f14862ac5d5f2bdcb1ed85b
Created January 6, 2023 08:01
jenkins print login error
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
)
@niski84
niski84 / gist:e35e72ffd7ed1faa0ee1ec75d8599bb2
Created January 6, 2023 07:45
jenkins login with header set
package main
import (
"fmt"
"net/http"
"net/http/cookiejar"
"net/url"
)
func main() {
@niski84
niski84 / gist:424b31c0a93dafb3c77e57af22d7e06d
Created January 6, 2023 07:19
fetch jenkins login JSESSIONID
package main
import (
"fmt"
"net/http"
"net/http/cookiejar"
"net/url"
)
func main() {
@niski84
niski84 / gist:23930c08b1674d61ace1cee5d6444f67
Created December 15, 2022 05:20
CensorField censors a field in a JSON string by replacing everything after the first three characters with asterisks
package main
import (
"encoding/json"
"fmt"
"strings"
)
// CensorField censors a field in a JSON string by replacing everything after the first three characters with asterisks
func CensorField(jsonStr string, field string) (string, error) {
@niski84
niski84 / gist:c9002584e96e3b8fe4e926a92f537f7b
Created December 10, 2022 23:39
Fetch AWS prices for EC2 instances. Nick skich
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Product struct {
@niski84
niski84 / gist:5aceaa2e88d7378f688f7b69f3ba464d
Created December 9, 2022 09:12
implementing a safe cache
type Cache struct {
items map[string]interface{}
mu sync.Mutex
}
func NewCache() *Cache {
return &Cache{
items: make(map[string]interface{}),
}
}
@niski84
niski84 / gist:1efb552e6dd63e49bbde9f1558b4c5f4
Created December 9, 2022 04:19
This program uses the aws-sdk-go library to call the AWS Pricing API and retrieve the proposed costs for a t2.micro EC2 instance.
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/pricing"
)
@niski84
niski84 / gist:22b1682ba733062f780febacc5d894e6
Created December 8, 2022 22:20
Run your batch file on interval
package main
import (
"fmt"
"math/rand"
"os/exec"
"time"
)
func main() {
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowReadOnlyAccessToElasticBeanstalk",
"Effect": "Allow",
"Action": [
"elasticbeanstalk:Describe*",
"elasticbeanstalk:List*"
],