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
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
# 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
# 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
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, |
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
# change port number to clear the neccessary port | |
sudo lsof -t -i tcp:8000 | xargs kill -9 |
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
# Picking specific commits from one git branch to a new one | |
#. 1. Create a new branch off master or any clean branch and checkout into the new branch | |
# 2. Use git log --pretty=oneline # on the branch with the needed commits to see the <sha> for the commits needed | |
# command | |
git cherry-pick 108e055..3f7cf07 # does not include commits from 108e055. 108e055 being the oldest commit and 3f7cf07 the lastest | |
git cherry-pick 108e055^..3f7cf07 # to include commits from 108e055 |
OlderNewer