Skip to content

Instantly share code, notes, and snippets.

View sgsharma's full-sized avatar
💭
Sleeping

Sasha Sharma sgsharma

💭
Sleeping
View GitHub Profile
@sgsharma
sgsharma / git_delete_branch
Created February 4, 2021 14:27
Delete git branch locally and remote
// From: https://www.freecodecamp.org/news/how-to-delete-a-git-branch-both-locally-and-remotely/
// delete branch locally
git branch -d localBranchName
// delete branch remotely
git push origin --delete remoteBranchName
@sgsharma
sgsharma / terraform_plan
Created February 3, 2021 19:27
Terraform plan
$ git checkout -b your-branch
$ tox
$ cd <path to terraform directory>
$ terragrunt init
$ terragrunt plan -out plan.file
$ git push
$ terraform show -no-color plan.file | pbcopy
@sgsharma
sgsharma / git_rebase
Created January 6, 2021 18:54
Git rebase on master
git rebase -i HEAD~2
git checkout master
git pull
git checkout ssharma-addname
git rebase -i master
git rebase --continue
git add <FILENAME>
git rebase --continue
@sgsharma
sgsharma / create_role_db.sql
Created April 27, 2020 21:42
Initial create role and database for Django app
CREATE USER admin WITH PASSWORD 'admin';
CREATE DATABASE api_db;
ALTER ROLE admin SET timezone TO 'UTC';
ALTER ROLE admin SET default_transaction_isolation TO 'read committed';
GRANT ALL PRIVILEGES ON DATABASE api_db TO admin;
@sgsharma
sgsharma / get_date.py
Created January 2, 2020 21:22
Get previous month's last date
import datetime
datetime.date.today().replace(day=1) - datetime.timedelta(days=1)
@sgsharma
sgsharma / helm_install
Created November 15, 2019 05:10
Fix for helm incompatible versions client[v2.16.1] server[v2.15.2]
# find the compatible version of the client here: https://github.com/Homebrew/homebrew-core/search?q=kubernetes-helm&type=Commits
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/dddb831d66da48588fc3efbcec0508155af9e16a/Formula/kubernetes-helm.rb
brew switch kubernetes-helm 2.15.2
brew link kubernetes-cli
brew unlink kubernetes-helm && brew link kubernetes-helm
@sgsharma
sgsharma / docker_container_start.sh
Created November 8, 2019 23:01
Get docker container start date
docker inspect --format='{{.State.StartedAt}}' <containerid> | xargs date +%s -d
@sgsharma
sgsharma / serializers.py
Created September 30, 2019 23:01
Serializer nullable field
class CommentsSerializer(serializers.ModelSerializer):
jid = serializers.CharField(required=True)
# having required=False allows the field details to be absent from the data when constructing the serializer.
# e.g. s = SerializerA(data={})
# whereas allow_null permits the the param to be specified but be null.
j_s_id = serializers.CharField(required=False, allow_null=True)
comment = serializers.CharField(required=True)
created_by = serializers.HiddenField(
default=serializers.CurrentUserDefault()
)
@sgsharma
sgsharma / serializer.py
Created August 15, 2019 21:56
DRF current user with request and field level validation
## This works in the case of multiple databases and data with no primary keys
class CommentsSerializer(serializers.ModelSerializer):
somefield = serializers.CharField(required=True)
comment = serializers.CharField(required=True)
created_by = serializers.HiddenField(
default=serializers.CurrentUserDefault()
)
def validate_somefield(self, value):

1. Create new branch:

git checkout -b otherrepo-master master

2. Get the contents of the PR

git pull https://github.com/otherrepo/my-repo-name.git master