Skip to content

Instantly share code, notes, and snippets.

View mrsoftware's full-sized avatar
🏠
Working from home

Mohammad Rajabloo mrsoftware

🏠
Working from home
View GitHub Profile
@scyto
scyto / docker-swarm-architecture.md
Last active July 20, 2024 19:17
My Docker Swarm Architecture
@Theodore-Rose
Theodore-Rose / .go
Last active September 7, 2020 15:12
Adding memory profile
func writeHeap() {
log.Info("Writing profiles")
resp, err := http.Get("http://localhost:8024/debug/pprof/heap")
if err != nil {
log.Infof("Failed at http.Get error: %+v", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
@timjonesdev
timjonesdev / static.go
Created September 17, 2019 21:56
A static file server that gracefully handles resource not found errors and passes requests to the client.
func StaticFileServer(r chi.Router, public string, static string) {
// everything up to the r.Get call is executed the first time the function is called
if strings.ContainsAny(public, "{}*") {
panic("FileServer does not permit URL parameters.")
}
root, _ := filepath.Abs(static)
if _, err := os.Stat(root); os.IsNotExist(err) {
panic("Static Documents Directory Not Found")
@crgimenes
crgimenes / README.md
Last active July 12, 2023 09:42
Example of pagination using PostgreSQL, Golang and SQLx

Configure environment variable

export DATABASE_URL=postgres://postgres@localhost/dbname?sslmode=disable 

Run in CLI

go run main.go -page 1
@timjonesdev
timjonesdev / docker-cleanup.sh
Created June 29, 2019 04:42
A cleanup script for docker resources, if you don't have `docker system prune` available. WARNING: This will delete all containers, images, and volumes.
#!/usr/bin/env bash
echo "Running docker cleanup script"
echo "Stopping all containers"
docker stop $(docker ps -a -q) # Stop all containers
echo "Removing stopped containers"
docker rm $(docker ps -a -q) # Remove all stopped containers
@JakubOboza
JakubOboza / private-docker-regs-with-free-tiers.markdown
Created May 30, 2019 07:15
Private Docker registry with free tiers for Developers.

List of sites with free tier limits

  • Docker Hub - One private repo/image spot for free
  • Three Scale - Very generous free tier 50GB of space, 500 Pulls a month etc..
  • Canister - 20 private repos with almost no limits on free tier
  • Code Fresh - Free tier for developers

Setup your own private registry

version: '3.0'
services:
app:
container_name: my_go_app_container
build:
# context can/may/will be different per-project setup
context: ../
dockerfile: GitDockerfile
args:
- bitbucket_id=private_user
# ---------------------------------------------------------------------
# The first stage container, for building the application
# ---------------------------------------------------------------------
FROM golang:1.12.1-stretch as builder
COPY . /app
# Add the keys
ARG bitbucket_id
ENV bitbucket_id=$bitbucket_id
git config \
--global \
url."git@github.com".insteadOf \
"https://github.com"
git config \
--global \
url."https://${user}:${personal_access_token}@github.com".insteadOf \
"https://github.com"