Skip to content

Instantly share code, notes, and snippets.

View vladimirmyshkovski's full-sized avatar
🎯
Focusing

Vladimir Myshkovski vladimirmyshkovski

🎯
Focusing
View GitHub Profile
@vladimirmyshkovski
vladimirmyshkovski / flash.css
Created March 12, 2017 02:35
Flask flash with categories
.flash-message {
border: 0;
color: #ffffff;
margin-bottom: 0;
position: fixed;
width: 100%;
top: 0;
left: 0;
z-index: 100000;
border-radius: 0;
@vladimirmyshkovski
vladimirmyshkovski / base.py
Created March 12, 2017 03:15
Base model for Flask SQLAlchemy
from ._base import db
from sqlalchemy.exc import IntegrityError, InterfaceError
from flask import flash
from sqlalchemy import event
from sqlalchemy.event import listen
from sqlalchemy.orm.interfaces import MapperExtension
from ..utils.redis import redis_store
from sqlalchemy import inspect
from sqlalchemy.ext.declarative import as_declarative, declared_attr
from pickle import dumps, loads
@vladimirmyshkovski
vladimirmyshkovski / gist:d6b41cffe80f38adb43852a12b9a4af1
Created April 25, 2017 22:03
How to change FOREIGN KEY of an existing PostgreSQL table?
-- We are dropping the foreign key constraint on dependant table (in other case it will prevent us from updating the values)
ALTER TABLE foo_table DROP CONSTRAINT fk_e52ffdeea76ed395;
-- Then, we're swapping values in foreign key column from id to another_id
UPDATE foo_table T SET user_id = (SELECT another_id FROM users WHERE id = T.user_id);
-- And finally we're creating new foreign key constraint pointing to the another_id instead of id
ALTER TABLE foo_table ADD CONSTRAINT fk_e52ffdeea76ed395 FOREIGN KEY (user_id) REFERENCES users (another_id) ON DELETE CASCADE;
@vladimirmyshkovski
vladimirmyshkovski / More real example
Created May 1, 2017 17:41
Wait to load defer scripts.
<script>
function defer(method) {
if (window.inputmask) // Important! Wait loading last script!
method();
else
setTimeout(function() { defer(method) }, 50);
}
<script>
<script type="text/javascript" defer src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" defer src="js/bootstrap-3.3.7.min.js"></script>
for i in `find /var/lib/nginx/cache -type f`; do rm $i ; done
or
find /var/lib/nginx/cache -type f -exec rm {} \;
# /var/lib/nbinx/cache -- path of the nginx cache
<script>
z = document.getElementsByTagName('link').length
for (i = 0; i < z; i++) {
function loadStyleSheet(i){
if (document.createStyleSheet) document.createStyleSheet(i);
else {
var stylesheet = document.createElement('link');
stylesheet.href = i;
stylesheet.rel = 'stylesheet';
stylesheet.type = 'text/css';
@vladimirmyshkovski
vladimirmyshkovski / example of find *.css files
Created May 5, 2017 22:25
Python. Find files in directory
import os
...: filelist=os.listdir('static/css/')
...: for fichier in filelist[:]: # filelist[:] makes a copy of filelist.
...: if not(fichier.endswith(".css")):
...: filelist.remove(fichier)
...: print(filelist)
@vladimirmyshkovski
vladimirmyshkovski / gist:ca806ec61cd8c30669fc30b482f89a17
Created May 6, 2017 19:04
Parse python googlemaps reverse_geocode
import googlemaps
gmaps = googlemaps.Client(key='YOUR_API_KEY')
reverse_geocode_result = gmaps.reverse_geocode((53.9115621, 27.49615610000007))
reverse_geocode_result # This is a list
reverse_geocode_result[0] # This is a dict
@vladimirmyshkovski
vladimirmyshkovski / gist:a88ff6e41837da18c488e93d20e6e7d2
Created May 11, 2017 08:14
CBV paginate for django template with russian language
{% if is_paginated %}
<div class="pagination">
<span class="page-links">
{% if page_obj.has_previous %}
<a href="{% url 'cities:cities' %}?page={{ page_obj.previous_page_number }}">Предыдущая</a>
{% endif %}
<span class="page-current">
страница {{ page_obj.number }} из {{ page_obj.paginator.num_pages }}.
</span>
@vladimirmyshkovski
vladimirmyshkovski / gist:8678c5a6ce5b5e37eba64608f81fa72a
Created May 11, 2017 15:02
kill programs which ran an 8000 port (Django)
sudo lsof -t -i tcp:8000 | xargs kill -9