Skip to content

Instantly share code, notes, and snippets.

Zachary Kazanski Kazanz

Block or report user

Report or block Kazanz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Kazanz
Kazanz / api.py
Last active Jan 31, 2018
How we would adjust pricing on store via a tag on the managed-services+ option
View api.py
# This is the code in core that adjusts option pricing for discounts
@return_decimal
def get_discount(self, option_price, discount_id):
from core.api.store.carts.models import CartDiscount
discount = CartDiscount.query.get(discount_id)
return discount.calculate(option_price) if discount else 0
# This would be new code that adjust the price for the order.
@return_decimal
@Kazanz
Kazanz / reserve_provserv.py
Last active Jan 31, 2018
Provisioning by option instead of location
View reserve_provserv.py
# Current logic for reserving a device by location:
device = hapi.devices.get(server.device_id).json()
device_location = device.get('location')
if location == device_location:
target = server
# The new logic for reserving by option tags, then defaulting to location.
if has_sps_location_tag:
device = hapi.devices.get(server.device_id).json()
tag = device.option.tag
View option1.py
# init MYSQL
mysql = MySQL()
# Config MySQL
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = '1234'
app.config['MYSQL_DB'] = 'myflaskapp'
app.config['MYSQL_CURSORCLASS'] = 'DictCursor'
mysql.init_app(app)
View api_client.py
import json
def mock_api_call(path, schema):
with open(schema, 'r') as f:
data = json.loads(f.read())
if path == "http://test.net/products":
return data["properties"]["items"]
elif path == "http://test.net/products/0"
return data["properties"]["items"][0]
View A better way to get an object without throwing an exception
# This will return None if not found, as opposed to raising an exception
classroom = Classroom.objects.filter(pk=pk).first()
View val.py
class _BaseDomainNameValidator(BaseValidator):
def __call__(self, form, field):
labels = get_labels(value)
if not labels:
return False
is_valid = True
for index, label in enumerate(labels):
if index == 0 and label == '*':
continue
if not label and index + 1 != len(labels):
View gist:e58f9ff28c6c0f8a340be6bae14b7fc3
Dictionary<string, string> playlists = new Dictionary<string, string>()
{
{"pop", "PL9tY0BWXOZFt2TyOofWG0XwA8IDC8SGIN"},
{"hip hop", "PL9tY0BWXOZFv-V7FvZP-PWuE-1x2Deqqe"},
{"rock", "PL9tY0BWXOZFvrS_oXmav-as9fy3lt1i34"},
{"r&b", "PL9tY0BWXOZFupYyrDriLYu3ba9oYMUJ65"},
{"edm", "PL9tY0BWXOZFvBK4oJZylITMXRxAPJvbr8"},
{"metal", "PL9tY0BWXOZFuErwY_it1HO20Da-13FfNz"},
{"country", "PL9tY0BWXOZFtUu1HrxtZ4hv8nNLKiRseN"},
};
View app.py
from core.extensions import celery
app = Flask(__name__)
celery.init_app(app)
app.run()
@Kazanz
Kazanz / 2to3
Created Jan 5, 2016
Bash cmd for upgrading all python files recursively to python3
View 2to3
find . -exec ls -dl \{\} \; | grep ".*\.py" | awk '{print $9}' | xargs 2to3 -w
@Kazanz
Kazanz / instance_cache.py
Created Sep 4, 2015
Instance cache for classes python
View instance_cache.py
def instance_cached(meth):
cached_name = '_' + meth.__name__
@functools.wraps(meth)
def _cached(self):
if not hasattr(self, cached_name):
setattr(self, cached_name, meth(self))
return getattr(self, cached_name)
return _cached
You can’t perform that action at this time.