Skip to content

Instantly share code, notes, and snippets.

View mingrammer's full-sized avatar
🧗
learn, code, and grow

MinJae Kwon (Miti) mingrammer

🧗
learn, code, and grow
View GitHub Profile
def save_ranking(**kwargs):
print(kwargs)
save_ranking(first='ming', second='alice', fourth='wilson', third='tom', fifth='roy')
# {'first': 'ming', 'second': 'alice', 'fourth': 'wilson', 'third': 'tom', 'fifth': 'roy'}
def save_ranking(*args):
print(args)
save_ranking('ming', 'alice', 'tom', 'wilson', 'roy')
# ('ming', 'alice', 'tom', 'wilson', 'roy')
def save_ranking(first, second=None, third, fourth=None):
...
# A function that shows the results of running competitions consisting of 2 to 4 runners.
def save_ranking(first, second, third=None, fourth=None):
rank = {}
rank[1], rank[2] = first, second
rank[3] = third if third is not None else 'Nobody'
rank[4] = fourth if fourth is not None else 'Nobody'
print(rank)
# Pass the 2 positional arguments
save_ranking('ming', 'alice')
# Initialize the zero-valued list with 100 length
zeros_list = [0] * 100
# Declare the zero-valued tuple with 100 length
zeros_tuple = (0,) * 100
# Extending the "vector_list" by 3 times
vector_list = [[1, 2, 3]]
for i, vector in enumerate(vector_list * 3):
print("{0} scalar product of vector: {1}".format((i + 1), [(i + 1) * e for e in vector]))
>>> 2 * 3
6
>>> 2 ** 3
8
>>> 1.414 * 1.414
1.9993959999999997
>>> 1.414 ** 1.414
1.6320575353248798
# Provisioning script
...
cd /opt/settings
git clone git@github.com/company/config.git
cd /opt/app
git clone git@github.com/company/api-server.git
...
# /opt/settings/config.py
DATABASE_CONFIG = {
'host': 'localhost',
'dbname': 'company',
'user': 'user',
'password': 'password',
'port': 3306
}
# main.py
import os
from myapp import app
secret_key = os.environ.get('SECRET_KEY', None)
if not secret_key:
raise ValueError('You must have "SECRET_KEY" variable')
app.config['SECRET_KEY'] = secert_key
// config.json.example
{
"DEFAULT": {
"SECRET_KEY": "...",
"ADMIN_NAME": "...",
"AWS_DEFAULT_REGION": "...",
"MAX_IMAGE_SIZE": 5242880
},
"TEST": {
"TEST_TMP_DIR": "tests",