Skip to content

Instantly share code, notes, and snippets.

@islamgulov
islamgulov / gist:1953203
Created March 1, 2012 21:01
ГОСТ 28147-89
# -*- coding:utf-8 -*-
import sys
import numpy.random
import itertools
class GostCrypt(object):
def __init__(self, key, sbox):
assert self._bit_length(key) <= 256
self._key = None
# -*- coding:utf-8 -*-
class GostCrypt(object):
def __init__(self, key, sbox):
assert self._bit_length(key) <= 256
self._key = None
self._subkeys = None
self.key = key
self.sbox = sbox
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import math
import numpy
def sigmoid(x):
"""вроде как лучше чем 1/(1+e^-x)"""
return math.tanh(x)
@islamgulov
islamgulov / gist:2955511
Created June 19, 2012 17:45
list providers init
class BaseServiceHandler(BaseHandler):
"""
To use this class inherit from it and define _DRIVERS and _Providers
Also to encode to json response custom object add them to obj_attrs dict.
"""
_DRIVERS = None
_Providers = None
_providers_list_response = None
def _get_driver_instance(self):
def parse_docstring(docstring):
"""
@param docstring:
@type docstring:
@return: return dict which contain:
description - method description
arguments - dict of dicts arg_name: {desctiption, typename, required}
return - list of return types
@rtype: C{dict}
"""
@islamgulov
islamgulov / gist:3068307
Created July 7, 2012 22:20
Example response for supported method

Fake method:

class FakeDriver(object):
    def fake_method(self, node, volume, device='default_value', extra={}):
        """
        teachess volume to node.

        @param      node: Node to attach volume to
        @type       node: L{Node}
@islamgulov
islamgulov / gist:3073556
Created July 9, 2012 00:30
extra with default value

Fake method:

class FakeDriver(object):
    def fake_method(self, node, volume, device='/deb/sdb', extra={}):
        '''
        teachess volume to node.

        @param      node: Node to attach volume to
        @type       node: L{Node}
@islamgulov
islamgulov / gist:3073560
Created July 9, 2012 00:31
extra without default value

Fake method:

class FakeDriver(object):
    def fake_method(self, node, volume, extra, device='/deb/sdb'}):
        '''
        teachess volume to node.

        @param      node: Node to attach volume to
        @type       node: L{Node}
@islamgulov
islamgulov / gist:3080179
Created July 10, 2012 00:40
libcloud docstring

Docstrings

Libcloud follow epytext docstring formatiing.

  • Docstrings should always be used to describe the purpose of methods, functions, classes, and modules.
  • Method docstring describes all vargs and keywords (varargs and keywords are the names of the * and ** arguments).
  • All of the blocks contained by a field must all have equal indentation, and that indentation must be greater than or equal to the indentation of the field's tag.
  • All parametrs must have @param or @keyword field and @type field.
  • @param p: ... A description of the parameter p for a function or method.
  • @keyword p: ... A description of the keyword parameter p.
@islamgulov
islamgulov / gist:3087220
Created July 11, 2012 00:53
compute/providers/bluebox
{
"website": "http://bluebox.net",
"supported_methods": {
"detach_volume": {
"description": "Detaches a volume from a node.\n",
"arguments": [
{
"required": true,
"type": "string",
"name": "volume_id",