Skip to content

Instantly share code, notes, and snippets.

@mki
mki / form.py
Created August 23, 2012 09:04
Собственная проверка поля формы в Django (see more at http://mkifiles.ru/?p=1758)
# -*- coding: utf-8 -*-
from django import forms
from django.core.validators import email_re
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
# Наше поле для валидации
class ContactField(forms.Field):
def validate(self, value):
@mki
mki / example.php
Created August 29, 2012 19:36
Class for mailing
$objMail = new Lib_Sent();
$objMail->to = array('email кому отсылаем письмо');
$objMail->from = 'email от кого будет письмо';
$objMail->subject = 'Заголовок письма';
$objMail->body = 'Текст письма.';
$objMail->add_attachment("Содержание атача. Предварительно нужно считать из файла",
"название файла", "application/octet-stream");
$objMail->send();
@mki
mki / Connections.as
Created August 29, 2012 19:38
Action Script 3 P2P to Live example ( see more at http://mkifiles.ru/?p=1336)
package
{
import states.LiveState;
import states.PeerState;
import states.state.IConnection;
import flash.net.NetStream;
public class Connections
{
private var peerState:PeerState;
private var liveState:LiveState;
@mki
mki / example.as
Created August 29, 2012 19:48
FileReference example for package upload files (see more at http://mkifiles.ru/?p=1518)
//Функция вызывается при клике по кнопке
public function onClick(event:Event) : void
{
// Пробегаем по массиву композиций и формируем массив для
// загрузки "urlLoader"
while (i < this.arrMusic.length)
{
// Формируем Request
var urlRequest:URLRequest = new URLRequest();
urlRequest.url = ''; // ссылка куда грузим файл
@mki
mki / screen1.py
Created November 30, 2012 22:16
Gists for article
from django.contrib.auth.models import User
user = User.objects.get(pk=5)
user.set_password('super-sekrit')
user.save()
@mki
mki / gist:750a97a2a69635a79fa9
Last active August 29, 2015 14:00 — forked from Integral/gist:5156170
Backbone.Form.editors.Select2
/**
* SELECT2
*
* Renders Select2 - jQuery based replacement for select boxes
*
* Requires an 'options.values' value on the schema.
* Can be an array of options, a function that calls back with the array of options, a string of HTML
* or a Backbone collection. If a collection, the models must implement a toString() method
*/
Backbone.Form.editors.Select2 = Backbone.Form.editors.Base.extend({
@mki
mki / track_data.py
Created October 30, 2015 09:32 — forked from dcramer/track_data.py
Tracking changes on properties in Django
from django.db.models.signals import post_init
def track_data(*fields):
"""
Tracks property changes on a model instance.
The changed list of properties is refreshed on model initialization
and save.
>>> @track_data('name')
[color]
ui = true
[user]
email = [email protected]
name = xxxx.xxxx
[giggle]
main-window-maximized = true
main-window-geometry = 430x176+343+25
history-view-vpane-position = 285
main-window-view = HistoryView
@mki
mki / vkcom_audio_download.py
Created November 4, 2016 16:43 — forked from st4lk/vkcom_audio_download.py
Python: vkontakte.ru (vk.com) audio music downloader
# -*- coding: utf-8 -*-
"""
Скрипт для скачивания музыки с сайта vkontakte.ru (vk.com)
Запуск:
python vkcom_audio_download.py
Принцип работы:
Скрипт проверяет сохраненный access_token. Если его нет или срок истек,
то открывается страница в браузере с запросом на доступ к аккаунту.
import requests
r = requests.get('https://api.instagram.com/v1/users/search?q=mkispb&count=1&access_token=...')
user_id = None
for user in r.json()['data']:
if user['username'] == 'mkispb':
user_id = user['id']