Skip to content

Instantly share code, notes, and snippets.

View cnp96's full-sized avatar

Chinmaya Pati cnp96

View GitHub Profile
@cnp96
cnp96 / docker-compose.yml
Last active December 31, 2023 16:12
Docker compose for Go app with Redis and MongoDB
version: "3.9"
services:
web:
build:
context: .
target: image-dev
restart: on-failure
ports:
- 9000:9000
volumes:
@cnp96
cnp96 / Dockerfile
Created December 14, 2021 00:02
Docker build for Go app
FROM golang:1.16.4-alpine as base
WORKDIR /app/go
COPY . .
RUN go mod download
FROM base as image-dev
RUN go get github.com/cosmtrek/air
EXPOSE 9000
CMD $(go env GOPATH)/bin/air
@cnp96
cnp96 / test-redis.sh
Last active December 20, 2020 15:37
Test Redis connection
docker run --rm -it redis redis-cli -h HOST -p PORT -a SERVER_PASSWORD
# It should open a shell
HOST:PORT > ping
PONG
@cnp96
cnp96 / redis-memory.sh
Last active December 20, 2020 15:38
Redis memory management
# Replace 1gb with a suitable value depending on the server
maxmemory 1gb
# Setting an eviction policy is very helpful to free memory when required.
maxmemory-policy volatile-afu
@cnp96
cnp96 / redis-persistence.sh
Created December 20, 2020 15:22
Redis persistence
appendonly yes # set no to disable aof
appendfsync everysec # tells the OS to write data on disk instead of waiting for more data in the buffer.
# Available options for appendfsync are
# always : sync after every write. Slowest, safest
# everysec : sync only once every second. Compromise
# no : don't sync, just let the OS flush data as it wants. Faster, risky
@cnp96
cnp96 / start-redis.sh
Created December 20, 2020 15:19
Start redis instance
docker run --rm -d --name my-redis \
-p 6379:6379 \
-v $(pwd)/data:/data \
-v $(pwd)/redis.conf:/usr/local/etc/redis/redis.conf \
redis redis-server /usr/local/etc/redis/redis.conf
@cnp96
cnp96 / delta-sync.sh
Created November 3, 2020 18:55
Sync MongoDB instances
#!/bin/bash
# DB info
old_db="source_database_name"
# Connection info
uri="source_db_connection_string"
to_uri="target_db_connection_string"
# Storage info
@cnp96
cnp96 / git-stages.md
Created June 9, 2020 07:50
Git Stages

One time things

ignored

  • added to .gitignore

untracked

  • any new file
  • track by git add filename/pattern
@cnp96
cnp96 / sw-custom.js
Last active November 9, 2020 18:18
src/sw-custom.js
try {
if ("function" === typeof importScripts) {
importScripts(
"https://storage.googleapis.com/workbox-cdn/releases/3.5.0/workbox-sw.js"
);
// Global workbox
if (workbox) {
// console.log("Workbox is loaded");
@cnp96
cnp96 / sw-build.js
Last active April 15, 2020 23:29
src/sw-build.js
const workboxBuild = require("workbox-build");
const buildSW = () => {
// The build is expected to fail if the
// sw install rules couldn't be generated.
// Add a catch block to handle this scenario.
return workboxBuild
.injectManifest({
swSrc: "src/sw-custom.js", // custom sw rule