This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getArrayElement($array, $path, $pathDelimiter = '->') | |
{ | |
// searching for element | |
$current_array = &$array; | |
$keys = explode($pathDelimiter, $path); | |
foreach ($keys as $key) | |
{ | |
$current_array = &$current_array[$key]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function _insertOrUpdateData(&$dbAdapter, $table, $data, $where) | |
{ | |
$select = $dbAdapter->select()->from($table); | |
foreach ($where as $condition => $value) | |
{ | |
$select->where($condition, $value); | |
} | |
if ($dbAdapter->fetchOne($select)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from copy import copy | |
class NotAllowedError(Exception): | |
code = 503 | |
def __init__(self, *args, **kwargs): | |
super(NotAllowedError, self).__init__(*args, **kwargs) | |
def _base_decorator(check_rights_function, *decorator_args, **decorator_kwargs): | |
def real_decorator(function): | |
def wrapper(handler, *function_args, **function_kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import json, urllib2 | |
#адрес для отправки json-запросов | |
url = 'https://api.direct.yandex.ru/v4/json/' | |
#данные для OAuth-авторизации | |
token = '6bfc962472504a2b99fb6a5b0b181d98' | |
#логин в Директе |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Пример программного кода для работы с API сервиса Яндекс.Директ | |
В примере использован рекомендуемый синтаксис для работы с API сервиса Яндекс.Директ | |
на языке PHP с использованием протокола JSON и авторизацией по токенам. | |
Обращаем внимание, что все текстовые данные должны быть в кодировке UTF8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine | |
from sqlalchemy import select | |
from sqlalchemy import MetaData, Table, Column, String, Integer | |
engine = create_engine("sqlite://") | |
metadata = MetaData() | |
user_table = Table('user', metadata, | |
Column('id', Integer, primary_key=True), | |
Column('username', String(50)), | |
Column('fullname', String(50)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################# | |
def compile_query(query): | |
return str(query.statement.compile(compile_kwargs={"literal_binds": True})) | |
################################################################# | |
############################## EXAMPLE ############################## | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column, Integer, String | |
from sqlalchemy import create_engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.ext.declarative import declarative_base | |
Base = declarative_base() | |
from sqlalchemy import * | |
from sqlalchemy.orm import relationship, backref, joinedload | |
class Request(Base): | |
__tablename__ = 'request' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find(db, id_): # db is better to be global IMHO | |
db.query(self.__class__).filter(self.__class__.__mapper__.primary_key[0] == id_).one() |
OlderNewer