Skip to content

Instantly share code, notes, and snippets.

View DrMartiner's full-sized avatar
😎

Alex Kuzmin DrMartiner

😎
View GitHub Profile
@DrMartiner
DrMartiner / backup_file_fields.py
Last active October 22, 2017 13:01
Command for backups all media files
import os
import tarfile
import progressbar
import django.apps
from datetime import datetime
from django.core.management.base import BaseCommand
from django.utils.encoding import smart_str
class Command(BaseCommand):
@DrMartiner
DrMartiner / put_pos.py
Created July 20, 2017 12:22
Put po files to shuup project
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import os
import shutil
SHUUP_PATH = '~/.pyenv/versions/project/lib/python3.5/site-packages/shuup'
SOURCE_PATH = '~/projects/project'
@DrMartiner
DrMartiner / urls.py
Created May 12, 2017 12:52
Django's URL's error handlers
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
urlpatterns = [
# ...
]
handler400 = 'apps.common.views.handler400'
handler403 = 'apps.common.views.handler403'
karma-angular
@DrMartiner
DrMartiner / views.py
Created January 5, 2014 12:39
Generate csrf token
from django.core.context_processors import csrf
str(csrf(request)['csrf_token'])
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_HOST_USER = 'login@example.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
@DrMartiner
DrMartiner / gist:7673870
Created November 27, 2013 10:54
Directive for idle timer
angular.module('app')
.directive 'idle', () ->
return {
restrict: 'E'
scope:
waitTime: '@ngIdleWaitTime'
afterRedirect: '&ngAfterRedirect'
link: (scope, element, attrs) ->
idleTimer = null
idleState = false
@DrMartiner
DrMartiner / gist:7524683
Created November 18, 2013 08:48
gruntfile.coffee
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
watch:
coffee:
files: ['static/coffee/**/*.coffee']
tasks: ['coffee:dist']
less:
files: ['static/css/**/*.less']
tasks: ['less:dist']
@DrMartiner
DrMartiner / directives.coffee
Created November 12, 2013 05:15
Directive, who set\unset toggle class at the element, when the function-condition changed
toggleClass = angular.module('jobMapApp')
.directive 'ngToggleClass', () ->
return {
restrict: 'A'
scope:
condition: '&ngToggleCondition'
link: (scope, element, attrs) ->
scope.timerId = null
scope.$watch () ->
return scope.condition()
@DrMartiner
DrMartiner / utils.coffee
Last active December 26, 2015 02:29
Convert PostGIS point to Yandex-Map point
convertPostGisToYandex = (point) ->
coords = /POINT\s*\(\s*([0-9\.]+)\s*([0-9.]+)\s*\)/.exec point
if coords.length != 2
console.error 'Bad parse PostGIS point data', point
return []
return [parseFloat(coords[1]), parseFloat(coords[2])]