Skip to content

Instantly share code, notes, and snippets.

View RaidoS's full-sized avatar

Pavel RaidoS

  • free-lance
  • Russia
View GitHub Profile
@RaidoS
RaidoS / update_with_join.sql
Created May 24, 2019 09:13
Postgresql script example UPDATE table with INNER JOIN
WITH a AS (
SELECT sportsmen_id FROM chalenge_results r
INNER JOIN
chalenge_chalengesporter s
ON r.sportsmen_id = s.id
WHERE date_part('year', s.date_req) = 2017
)
UPDATE chalenge_results as c
SET chalenge_id = 2
@RaidoS
RaidoS / gist:cec9a44d2930a2302ac5aaa312a389f0
Last active November 25, 2017 03:04
Django sending html email
We couldn’t find that file to show.
@RaidoS
RaidoS / admin.py
Created September 12, 2017 07:02
Django Flatpage Redactor Field
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from redactor.widgets import RedactorEditor
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin as FlatPageAdminOld
class FlatPageAdmin(FlatPageAdminOld):
formfield_overrides = {
models.TextField: {'widget': RedactorEditor},
<head>
<!-- Facebook – 1,200 x 628
Twitter – 1,024 x 576
Instagram – 1,080 x 1,080
LinkedIn – 552 x 368
Pinterest – 600 x 900
Google+ – 800 x 320
-->
<title>Заголовок страницы</title>
@RaidoS
RaidoS / python_django_regexps.py
Created June 21, 2017 12:16
python / django regexp
# python / django regexp for phone validating
# regexp
r'^\+?1?\d{9,15}$'
# django validator
from django.core.validators import RegexValidator
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message=u'Phone number must be like: +79999999999')
@RaidoS
RaidoS / shell
Created April 19, 2017 02:52
shell commands
// remove .pyc files
rm -r *.pyc
// recursive
find . -name "*.pyc" -exec rm -f {} \;
// http://stackoverflow.com/questions/785519/how-do-i-remove-all-pyc-files-from-a-project
@RaidoS
RaidoS / comma_separated_items.html
Created April 10, 2017 14:54
Django templates trick for comma separated lists, exclude "comming" last item
<!-- template.html -->
{% for item in items %}
<a href="{{item.slug}}">{{item.name}}</a>{% include "comma.html" %}
{% endfor %}
<!-- comma.html -->
{% if not forloop.last %}
{% ifequal forloop.revcounter 2 %} и {% else %}, {% endifequal %}
{% else %}
// 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 + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));