Skip to content

Instantly share code, notes, and snippets.

Stanislav Otovchits otov4its

Block or report user

Report or block otov4its

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
@otov4its
otov4its / null_char_field.py
Last active Jan 16, 2017
Django NullCharField subclass of the CharField that allows empty strings to be stored as NULL in database
View null_char_field.py
from django.db.models import CharField
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
class NullCharField(CharField):
"""
Subclass of the CharField that allows
empty strings to be stored as NULL in database
"""
View django_csrf.js
$(function() {
// This function gets cookie with a given name
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
@otov4its
otov4its / python_parse_hashtags.py
Last active Jul 12, 2016
This gist parses 99% twitter-like hashtags in unicode
View python_parse_hashtags.py
# -*- coding: utf-8 -*-
import re
# Because 're' module do not support \p{L} unicode class
# need to use simplistic regex with \w instead \p{L}. But such regexp
# also match digits like #123, #003 and so on.
# So it need to further filter out digit-only tags.
# See https://regex101.com/r/cK5oJ0/
HASHTAG_EXP = r'(?:^|_|[^\w&/]+)(?:#|#)([\wÀ-ÖØ-öø-ÿ]+)'
HASHTAG_REGEX = re.compile(HASHTAG_EXP, re.UNICODE | re.IGNORECASE)
You can’t perform that action at this time.