Skip to content

Instantly share code, notes, and snippets.

View nskeip's full-sized avatar
🕶️

Nikita Hismatov nskeip

🕶️
View GitHub Profile
@nskeip
nskeip / ElementFlowAtomicOutputWrapper.py
Created February 17, 2012 08:35
Atomic wrapper for ElementFlow
# If you create xml via ElementFlow and make some bad things (and exceptions raise)
# you will get invalid xml (only a criple part of the xml you wish to have).
#
# This is a wrapper for ElementFlow for 'atomic' xml: it either created or not.
import shutil
import tempfile
class ElementFlowAtomicOutputWrapper(object):
def __init__(self, out_file_path):
@nskeip
nskeip / Gemfile
Created February 22, 2012 07:56
Configuring rails for haml + sass + compass (960)
source 'https://rubygems.org'
gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
@nskeip
nskeip / permutations.py
Created February 23, 2012 06:06
Permutations algorythm implementation.
def permutations(l):
"""
>>> f = permutations
>>> f(['a', 'b'])
[('a', 'b'), ('b', 'a')]
>>> f(['a', 'b', 'c'])
[('a', 'b', 'c'), ('a', 'c', 'b'), ('b', 'a', 'c'), ('b', 'c', 'a'), ('c', 'a', 'b'), ('c', 'b', 'a')]
"""
if len(l) == 1:
@nskeip
nskeip / regognize_phone.py
Created March 17, 2012 18:00
Helps to recognize a celular phone number in a string with non-celular numbers.
#-*- coding: UTF-8 -*-
import re
def recognize_phone(s):
"""
>>> f = recognize_phone
>>> f(u'8-912-234-56-78')
u'8-912-234-56-78'
@nskeip
nskeip / compass-create-960
Created March 22, 2012 19:00
Все время забываю как создать проект в компасе, чтобы с 960
compass create -r ninesixty vizavi-layout --using 960 --syntax sass --sass-dir "sass" --css-dir "css" --javascripts-dir "js" --images-dir "images"
@nskeip
nskeip / pagination.html
Created May 29, 2012 10:53 — forked from cspanring/pagination.html
linaro django pagination template for Bootstrap framework
{# use in combination with https://github.com/zyga/django-pagination #}
{# and http://twitter.github.com/bootstrap/ #}
{# project-dir/templates/pagination/pagination.html #}
{% if is_paginated %}
{% load i18n %}
<div class="pagination">
<ul>
{% block previouslink %}
{% if page_obj.has_previous %}
@nskeip
nskeip / any_model_htmlfield.py
Created May 31, 2012 12:14
Registering any_model extension for tinymce's HTMLField
import tinymce
from django_any import xunit
from django_any.models import any_model, any_field
@any_field.register(tinymce.models.HTMLField)
def any_tinymce_html_field(*_):
return xunit.any_string(min_length=1, max_length=400)
@nskeip
nskeip / yandex_email_for_domain_settings.py
Last active February 23, 2024 15:03
Django SMTP settings for yandex_for_domain mail (pdd.yandex.ru)
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_HOST_USER = 'login@example.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
@nskeip
nskeip / smsintel.py
Created September 13, 2012 09:37
smsintel.ru django snippet
from django.conf import settings
def send_sms(phone, text):
q = ("<?xml version='1.0' encoding='UTF-8'?><data><login>%(login)s</login>" +
"<password>%(password)s</password><text>%(text)s</text><to number='%(phone)s'></to></data>") % {
'phone': phone.encode('utf-8'),
'text': text.encode('utf-8'),
'login': settings.SMS_INTELL_LOGIN,
'password': settings.SMS_INTELL_PASSWORD,
}
@nskeip
nskeip / parser_target.py
Created September 20, 2012 09:15
making an xml-parser more readable: an abstract target that tries to call methods like TAGNAME_start, TAGNAME_end etc.
class AbstractParseTarget(object): # http://lxml.de/parsing.html#the-target-parser-interface
def __init__(self):
self.current_tag = None
def start(self, tag, attrib):
self.current_tag = tag
method = getattr(self, '%s_start' % tag, None)
if method: