This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# convert to snake case, added replace - could do better with re https://stackoverflow.com/a/1176023/851056 | |
def convert(name): | |
new_name = name.replace(" ", "").replace("'","") | |
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', new_name) | |
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if pass returns it returns <NoneType> !None <str>, Explained: https://stackoverflow.com/a/36622862/851056 | |
def f(): | |
pass | |
def g(x): | |
if x > 2: | |
return x | |
def h(): | |
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_largest_num(Li): | |
if len(Li) ==1: | |
return Li[0] | |
x1 = Li[0] | |
x2 = find_largest_num(Li[1:]) | |
if x1 > x2: | |
return x1 | |
else: | |
return x2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 3.5 > | |
>>> x = {'a':3, 'b':4, 'c': 7} | |
>>> y = {'a': 6, 'b': 8, 'd': 9} | |
>>> z = {**x, **y} | |
>>> z | |
{'a': 6, 'b': 8, 'c': 7, 'd': 9} | |
# Python 2.x | |
z = dict(x, **y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given a dictionary | |
>>> ds = {'a': 4, 'b': 3, 'c': 2, 'd': 1} | |
>>> sorted(ds.items(), key=lambda y:y[1]) ## sorts values in ascending order | |
'''Result''' | |
[('d', 1), ('c', 2), ('b', 3), ('a', 4)] | |
# Or we can use itemgetter to sort by any item | |
from operator import itemgetter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build path | |
import os | |
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) | |
TEMPLATES = [ | |
{ | |
'BACKEND': 'django.template.backends.django.DjangoTemplates', | |
'DIRS': [os.path.join(BASE_DIR, "templates")], | |
'OPTIONS': { | |
'loaders': ( | |
'django.template.loaders.filesystem.Loader', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* There are about 2 ways to do tis | |
*/ | |
import firebase from 'firebase' | |
export default { | |
name: "SignUp", | |
data: () => ({ | |
successAlert: false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# trying to commit without needing to add all those extra files? just clean them | |
git clean -n -d # to see the files and folders to be deleted first before applying command below | |
git clean -f -d # -f force clean and -d cleaning directories. git just deletes. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using truncate | |
TRUNCATE TABLE table_name RESTART IDENTITY; # to reset index counts | |
TRUNCATE TABlE table_name CASCADE; # to delete foreign key dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE",'project_name.settings') # replace project_name with your project name | |
import django | |
django.setup() | |
from my_app.models import ( | |
Customers, | |
Organizations, |
OlderNewer