Skip to content

Instantly share code, notes, and snippets.

@m5wdev
m5wdev / mixed_dict.py
Last active December 7, 2015 09:44
Pynton 3 mixed dict example
"""
Mixed dict type:
"""
blog_posts = {"Blog disclamer": "Here you can create anything text, integers, lists etc.",
1: {"post_title": "Title1", "post_content": "Content1"},
2: {"post_title": "Title2", "post_content": "Content2"},
3: {"post_title": "Title3", "post_content": "Content3"},
4: {"post_title": "Title4", "post_content": "Content4"}}
# let's print out our type just in case ))
@m5wdev
m5wdev / Price for one item in Cart page Ubercart 3
Last active August 5, 2016 08:41
How to add price for one product item column in cart page (Ubercart 3)
/**
* Add Price for one item in Cart page Ubercart 3
* Autor: http://stackoverflow.com/a/11046318
* [HOW TO USE]
* You can create additional module or add this code into your template.php, change 'YOUR_MODULE_NAME' into 'YOUR_THEME_NAME'
*/
// Add 'Price' column in table Cart
function YOUR_MODULE_NAME_form_uc_cart_view_form_alter(&$form, &$form_state) {
$form['items']['#columns']['remove']['weight'] = 0;
$form['items']['#columns']['total']['weight'] = 5;
@m5wdev
m5wdev / Encapsulation.py
Last active March 31, 2019 20:53
Python 3: Encapsulation, Inheritance, Polymorphism
# Encapsulation
class Human():
# __private - переменная
__privateVar = "this is __private variable"
def __init__(self):
self.className = "Human class constructor"
self.__privateVar = "this is redefined __private variable"
:: By DeN www.m5-web.com
@echo off
:: Hour
set year=%date:~-4%
:: Mounth
set mounth=%date:~-7,2%
@m5wdev
m5wdev / pagination_blog.html
Last active March 21, 2018 22:56
Django 2.* Bootstrap 4 Pagination [by DeN] www.m5-web.com
{% if paginator %}
<nav aria-label="pagination">
<ul class="pagination justify-content-center">
{% if blog_posts.has_previous %}
<li class="page-item"><a class="page-link" href="?page=1">Начало</a></li>
<li class="page-item"><a class="page-link" href="?page={{ blog_posts.previous_page_number }}">Назад</a></li>
{% if blog_posts.number >= 4 %}
<li class="page-item"><a class="page-link" href="?page=1">1</a></li>
<li class="page-item disabled"><a class="page-link" href="#">...</a></li>
@m5wdev
m5wdev / skype_call.html
Created March 21, 2018 15:52
Links for Skype call
<!-- Звонок по логину пользователя: -->
<a href="skype:skype_login?call>Call to: skype_login</a>
<!-- Звонок на любой телефонный номер: -->
<a href="callto://+79880002266">Call to: +79880002266</a>
@m5wdev
m5wdev / flask_https.py
Last active March 25, 2019 19:03
Flask redirect from http:// to https://
# Redirect to https
@app.before_request
def before_request():
if request.url.startswith('http://'):
url = request.url.replace('http://', 'https://', 1)
return redirect(url, code=301)
@m5wdev
m5wdev / flask_without_www.py
Created April 9, 2018 13:37
Flask redirect from www to without www
# Redirect without WWW
from urllib.parse import urlparse, urlunparse
@app.before_request
def redirect_without_www():
urlparts = urlparse(request.url)
if urlparts.netloc == 'www.YOUR-DOMAIN.com':
urlparts_list = list(urlparts)
urlparts_list[1] = 'YOUR-DOMAIN.com'
return redirect(urlunparse(urlparts_list), code=301)
@m5wdev
m5wdev / TypeError.js
Created May 4, 2018 07:08
jQuery: Uncaught TypeError: $ is not a function
(function($) {
$(document).ready(function() {
// ...
});
}(jQuery));
@m5wdev
m5wdev / models.py
Last active November 16, 2018 20:38
Django 2.* positive integers validation
from django.core.validators import MaxValueValidator, MinValueValidator
class SomeModel(models.Model):
# ...
posiitive_integer = models.PositiveIntegerField(verbose_name='Some amount from 0 to 100', help_text='from 0 to 100', validators=[MinValueValidator(0), MaxValueValidator(100)])
# ...