Skip to content

Instantly share code, notes, and snippets.

View uurtech's full-sized avatar
✈️
Works

Ugur KAZDAL uurtech

✈️
Works
View GitHub Profile
@uurtech
uurtech / main.go
Created January 14, 2020 13:35
JSON unmarshalJson Timestamp to ISO Date
package main
import (
"encoding/json"
"fmt"
"strconv"
"time"
)
type CustomTime struct {
@uurtech
uurtech / main.go
Last active January 17, 2020 17:15
Encode Bytes of Json String with omiting empty fields
//delete the key if valueOf type is empty
reader := strings.NewReader(string(message))
// writer := os.Stdout
dec := json.NewDecoder(reader)
// enc := json.NewEncoder(writer)
for {
var m map[string]interface{}
if err := dec.Decode(&m); err == io.EOF {
break
} else if err != nil {
@uurtech
uurtech / purge_cache.sh
Created February 11, 2020 10:34
Bash command to purge cloudflare cache
echo alias purge_cache=\"curl -X POST "https://api.cloudflare.com/client/v4/zones/YOUR_ZONE/purge_cache" -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" --data "{"purge_everything":true}"\" >> ~/.zshrc && source
#then you can use purge_cache in your terminal to purge caches in cloudflare zone that you provided
@uurtech
uurtech / script.groovy
Created February 28, 2020 16:41
Delete Old Builds Jenkins Script
//you can go to Manage Jenkins > Script Console
import jenkins.model.Jenkins
import hudson.model.Job
MAX_BUILDS = 55
Jenkins.instance.getAllItems(Job.class).each { job ->
println job.name
def recent = job.builds.limit(MAX_BUILDS)
for (build in job.builds) {
@uurtech
uurtech / logger.ts
Created March 12, 2020 16:05
Typescript Nodejs Logger script
import * as dotenv from 'dotenv';
import winston from 'winston'
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'user-service' },
transports: [
new winston.transports.File({ filename: process.env.ERROR_LOGS, level: 'error' }),
new winston.transports.File({ filename: process.env.WARNING_LOGS, level: 'warning' }),
new winston.transports.File({ filename: process.env.INFO_LOGS, level: 'info' }),
@uurtech
uurtech / dockerfile
Created March 20, 2020 10:57
Golang Docker Multistage builder
FROM golang:latest
COPY main.go main.go
COPY controllers.go controllers.go
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
FROM scratch
MAINTAINER Uğur Kazdal girisiyorum@gmail.com
COPY --from=0 /go/main .
@uurtech
uurtech / controller.go
Created March 22, 2020 14:31
Return Http Response and then Perform other tasks
package main
import (
"fmt"
"net/http"
"sync"
"time"
)
func ping(w http.ResponseWriter, r *http.Request) {
@uurtech
uurtech / Dockerfile
Created April 28, 2020 16:37
Keep Git Container Running
FROM alpine:latest
RUN apk --update add ca-certificates
RUN apk add git
RUN apk add bash
ENTRYPOINT ["tail", "-f", "/dev/null"]
#You can now run it via docker run -d IMAGE_ID
@uurtech
uurtech / Dockerfile
Created May 13, 2020 21:15
Kubernetes app that can access to gcloud vms
FROM golang:latest
COPY main.go main.go
RUN go get github.com/joho/godotenv
RUN go get github.com/lib/pq
RUN go get golang.org/x/oauth2/google
RUN go get google.golang.org/api/compute/v1
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
@uurtech
uurtech / that.sh
Created May 16, 2020 07:37
Replace html tag recursively on linux
find . -type f -not -path '*/\.*' -exec sed -i -e "s@<base href=\"\/\/www.mydomain.com.\"\/>@\/@" {} \;