Skip to content

Instantly share code, notes, and snippets.

View arehmandev's full-sized avatar
🎯
Focusing

Abdul Rehman arehmandev

🎯
Focusing
  • Freelance
  • London, UK
View GitHub Profile
@arehmandev
arehmandev / main.go
Created October 3, 2017 15:00
Remove duplicates in a slice
func removeDuplicates(elements []string) []string { // change string to int here if required
// Use map to record duplicates as we find them.
encountered := map[string]bool{} // change string to int here if required
result := []string{} // change string to int here if required
for v := range elements {
if encountered[elements[v]] == true {
// Do not add duplicate.
} else {
// Record this element as an encountered element.
@arehmandev
arehmandev / 01-Before.json
Last active October 5, 2017 09:47
Best way of doing this?
{
"containers": [{
"path": "pathA",
"components": [{
"image": "Image1",
"name": "Name1"
}]
},
{
"path": "pathB",
@arehmandev
arehmandev / consul.groovy
Last active February 25, 2022 08:28
Store keyvalue pair in Consul using groovy (java Ecwid/consul-api)
@Grab( 'com.ecwid.consul:consul-api:1.2.4' )
import com.ecwid.consul.v1.*
client = new ConsulClient("172.20.20.10:8500")
setvalue("Abskey", "Absvalue")
println getvalue("Abskey")
@arehmandev
arehmandev / 1-redditexample.go
Last active October 10, 2017 14:37
Hi buddy - gave it a go
package main
import (
"encoding/json"
"fmt"
"log"
"time"
)
// Fulldata - test
@arehmandev
arehmandev / kube_config.ctmpl
Last active October 28, 2017 03:04
kube config ctemplate
apiVersion: v1
kind: Config
clusters:
{{- if eq (env "KUBE_ENVIRONMENT") "pr-kops" "pr" }}
{{- with secret (printf "secret/jenkins/kubernetes/%s" (env "KUBE_ENVIRONMENT"))}}
- cluster:
api-version: v1
server: "{{ .Data.api }}"
{{- if .Data.token}}
insecure-skip-tls-verify: true
@arehmandev
arehmandev / forloops.groovy
Created November 7, 2017 21:13
Jenkinsfile groovy for loop behaviour
abcs = ['a', 'b', 'c']
node('master') {
stage('Test 1: loop of echo statements') {
echo_all(abcs)
}
stage('Test 2: loop of sh commands') {
loop_of_sh(abcs)
}
stage('Test 3: loop with preceding SH') {
@arehmandev
arehmandev / main.go
Created November 22, 2017 23:01
Golang - Concurrent for loop to increment 10 times using waitgroups
package main
import "fmt"
import "sync"
func main() {
var wg sync.WaitGroup
count := 10
wg.Add(count)
@arehmandev
arehmandev / vars.sh
Last active November 24, 2017 21:02
#!/bin/bash
( set -o posix ; set ) > vars
sed -i '/BASHOPTS/d' vars
sed -i '/BASH_VERSINFO/d' vars
sed -i '/EUID/d' vars
sed -i '/PPID/d' vars
sed -i '/SHELLOPTS/d' vars
sed -i '/UID/d' vars
@arehmandev
arehmandev / insertlogrotate.sh
Last active November 30, 2017 12:02
Insert logrotate into all jenkins seed jobs with a nifty script
#!/bin/zsh
#### Uses the-silver-surfer (ag) and zsh
touch rotatelogdone.txt
ag -L logRotator --nocolor | xargs ls -1 > rotatelogdone.txt
ARRAY=($(cat rotatelogdone.txt))
for VAR in ${ARRAY[@]}
@arehmandev
arehmandev / groovy.json
Last active August 9, 2022 19:59
VSCode Jenkins groovy snippets
{
/*
//Please click VSCode -> Preferences -> User Snippets -> groovy
//Then copy and paste this into groovy.json
*/
/*
// Place your snippets for Groovy here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: