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 / 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 / slugify.js
Created November 13, 2018 20:07 — forked from mathewbyrne/slugify.js
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@sandiprb
sandiprb / useful_pandas_snippets.py
Created August 30, 2017 18:19 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
# Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
# Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(valuelist)]