Skip to content

Instantly share code, notes, and snippets.

View pokidovea's full-sized avatar
🙃

Eugene Pokidov pokidovea

🙃
View GitHub Profile
@pokidovea
pokidovea / README.md
Created November 4, 2019 18:06
Flask- приложение для получения thumbnail изображений и видео
@pokidovea
pokidovea / comparators.js
Created December 12, 2018 10:11
Multiple fields comparator
export function compareByField(field, reverse, predicate) {
const key = predicate ? x => predicate(x[field]) : x => x[field]
reverse = !reverse ? 1 : -1
return (a, b) => {
const key_a = key(a)
const key_b = key(b)
return reverse * ((key_a > key_b) - (key_b > key_a))
}
@pokidovea
pokidovea / confirmation-dialog.js
Created December 11, 2018 19:02
A confirmation dialog on React
import React from 'react'
import ReactDOM from 'react-dom'
import PropTypes from 'prop-types'
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap'
const ConfirmationModal = props => {
return (
<Modal isOpen={true} toggle={props.onNo} backdrop={true}>
<ModalHeader toggle={props.onNo}>{props.title}</ModalHeader>
@pokidovea
pokidovea / date_matches_crontab.sql
Created February 11, 2018 15:15
Stored Postgresql function to check, that given date matches crontab with 7 positions (s, m, h, d, m, dow, year).
CREATE OR REPLACE FUNCTION check_value_in_bounds(v int, min_v int, max_v int) RETURNS void AS $$
-- Checks if v is in bounds, else throws exception
BEGIN
IF v > max_v THEN
RAISE EXCEPTION 'value too high: % > %', v, max_v;
END IF;
IF min_v > v THEN
RAISE EXCEPTION 'value too low: % < %', v, min_v;
END IF;
@pokidovea
pokidovea / date_matches_crontab.sql
Last active March 18, 2020 09:17
Stored Postgresql function to check, that given date matches crontab with 7 positions (s, m, h, d, m, dow, year).
CREATE OR REPLACE FUNCTION check_value_in_bounds(v int, min_v int, max_v int) RETURNS void AS $$
-- Checks if v is in bounds, else throws exception
BEGIN
IF v > max_v THEN
RAISE EXCEPTION 'value too high: % > %', v, max_v;
END IF;
IF min_v > v THEN
RAISE EXCEPTION 'value too low: % < %', v, min_v;
END IF;
@pokidovea
pokidovea / django_cache_tag.sublime-snippet
Last active December 20, 2015 05:19
Django {% cache %} tag for Sublime Text 2/3
<snippet>
<content><![CDATA[
{% cache ${1:timeout} ${2:cache_name} ${3:vary} %}
${4:$SELECTION}
{% endcache %}
]]> </content>
<tabTrigger>cache</tabTrigger>
<scope>text.html.django</scope>
<description>cache</description>
</snippet>
@pokidovea
pokidovea / bash_parser.py
Created April 30, 2013 09:04
С рандомной страницы баша выдирает и выводит посты с рейтингом больше 10 000
# -*- coding: utf-8 -*-
'''
Created on 28.09.2012
Created by pokidovea([email protected])
'''
import lxml.html
import urllib2
from StringIO import StringIO
@pokidovea
pokidovea / forms.py
Created March 28, 2013 09:58
Django form field on the basis of jQuery plugin Tag-It! http://aehlke.github.com/tag-it/
class TagitWidget(forms.HiddenInput):
""" Widget on the basis of Tag-It! http://aehlke.github.com/tag-it/"""
class Media:
js = (settings.STATIC_URL + 'js/tag-it.js',
settings.STATIC_URL + 'js/tagit_widget.js',)
css = {"all": (settings.STATIC_URL + 'css/jquery.tagit.css',)}
class TagitField(forms.Field):