Skip to content

Instantly share code, notes, and snippets.

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

Sandip B sandiprb

🏠
Working from home
View GitHub Profile
@sandiprb
sandiprb / convert.py
Last active November 23, 2023 06:41
Conver Django qs Pandas dataframe to non timezone column
from django.utils.timezone import pytz
def formatted_date(naive_date):
aware_date = naive_date.astimezone(pytz.timezone(settings.TIME_ZONE))
return aware_date.strftime("%d-%m-%Y, %H:%M:%S")
df['date'] = df['date'].apply(formatted_date)
@sandiprb
sandiprb / install.MD
Last active August 23, 2022 08:51
Install Docker Compose on EC2 20.02 Ubuntu

Install Docker Compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
@sandiprb
sandiprb / remove_duplicates.py
Created April 15, 2021 10:31 — forked from victorono/remove_duplicates.py
Django - remove duplicate objects where there is more than one field to compare
from django.db.models import Count, Max
unique_fields = ['field_1', 'field_2']
duplicates = (
MyModel.objects.values(*unique_fields)
.order_by()
.annotate(max_id=Max('id'), count_id=Count('id'))
.filter(count_id__gt=1)
)
@sandiprb
sandiprb / gist:296aaaa1eb5401fea2f16841a8431e6d
Last active June 6, 2023 16:09 — forked from anthonyray/gist:398fde676a7704c03d6624155ba0011e
Set up OhMyZsh on Amazon EC2 instance running Ubuntu Server 14.04
  1. Connect to your EC2 instance
  2. Install zsh : sudo apt-get update && sudo apt-get install zsh -y
  3. Edit your passwd configuration file to tell which shell to use for user ubuntu : sudo vim /etc/passwd
  4. Look for ubuntu user, and replace bin/bash by bin/zsh
  5. Install OhMyZsh : sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
  6. Disconnect from your instance and reconnect it.
  7. Optional - Set hostname in .zshrc export PROMPT="%{$fg_bold[white]%} %{$bg[red]%}%{$reset_color%} ${PROMPT}"
@sandiprb
sandiprb / script.js
Created February 16, 2021 18:15
Strapi App Script
const moment = require('moment')
const path = require('path');
const createStrapiApp = async projectPath => {
if (!projectPath) {
throw new Error(`
-> Path to strapi project is missing.
-> Usage: node migrate-3.4.0.js [path]`);
}
@sandiprb
sandiprb / gist:771bcbd100a3ebf53682903a627a40df
Created August 26, 2020 07:20
Set up OhMyZsh on Amazon EC2 instance running Ubuntu Server
  1. Connect to your EC2 instance
  2. Install zsh : sudo apt-get update && sudo apt-get install zsh
  3. Install OhMyZsh : sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" 4.sudo chsh -s /bin/zsh ubuntu to change the user ubuntu's default shell. Replace 'ubuntu' with your username.
  4. Disconnect from your instance and reconnect it.
@sandiprb
sandiprb / db-backup.sh
Created July 28, 2020 20:25
Shell file to back up Postgres db & copy to s3 bucket
DB_NAME=$1
DB_USER=$2
DB_PASS=$3
BUCKET_NAME='bucket-name'
TIMESTAMP=$(date +%F_%T | tr ':' '-')
DB_FILE="$TIMESTAMP.sql"
PGPASSWORD=$DB_PASS pg_dump -Fc --no-acl -h localhost -U $DB_USER $DB_NAME > $DB_FILE
@sandiprb
sandiprb / 📊 Weekly development breakdown
Last active October 29, 2020 01:09
Weekly Development Breakdown
Vue.js 5 hrs 29 mins ███████████▍░░░░░░░░░ 54.5%
Python 2 hrs 59 mins ██████▏░░░░░░░░░░░░░░ 29.7%
JavaScript 28 mins █░░░░░░░░░░░░░░░░░░░░ 4.8%
HTML 21 mins ▊░░░░░░░░░░░░░░░░░░░░ 3.6%
GraphQL 14 mins ▍░░░░░░░░░░░░░░░░░░░░ 2.4%
@sandiprb
sandiprb / Dockerfile
Created June 17, 2020 20:29
Deploy React / Vue / Front-end node projects with nginx Docker image
# Use a lighter version of Node as a parent image
FROM node:10 as project-build
# Set the working directory to /frontend
WORKDIR /project
COPY package*.json /project/
RUN npm install
@sandiprb
sandiprb / admin.py
Last active June 6, 2020 13:54
Django admin register all models of an app dynamically
from django.contrib import admin
from django.apps import apps
from django.contrib.auth.admin import UserAdmin as DjUserAdmin
from . import models
# Register your models here.
@admin.register(models.User)
class UserAdmin(DjUserAdmin):
pass