Skip to content

Instantly share code, notes, and snippets.

# -*- coding:utf-8 -*-
from fractions import gcd
from random import randint
from itertools import count
def gen_prime(N=10 ** 8, bases=range(2, 20000)):
p = 1
while any(pow(base, p - 1, p) != 1 for base in bases):
p = randint(N)
ilgiz@ilgiz-nb:~/Dev/sprint/flask$ python2.6 --version
Python 2.6.8
ilgiz@ilgiz-nb:~/Dev/sprint/flask$ python2.6 --version
Python 2.6.8
ilgiz@ilgiz-nb:~/Dev/sprint/flask$ pypy --version
Python 2.7.2 (1.9+dfsg-1~ubuntu12.04.1~ppa1, Jun 22 2012, 08:21:23)
[PyPy 1.9.0 with GCC 4.6.3]
ilgiz@ilgiz-nb:~/Dev/sprint/flask$ python3.3 --version
Python 3.3.0
@islamgulov
islamgulov / compute
Last active December 11, 2015 04:58
# -*- coding:utf-8 -*-
from functools import partial
import httplib
from libcloud.compute import providers
from libcloud_rest.api.handlers import ServiceHandler, invoke_method,\
invoke_extension_method, list_providers, provider_info
from libcloud_rest.utils import json
@islamgulov
islamgulov / gist:3094419
Created July 11, 2012 23:27
Rackspace compute info
{
"website": "http://www.rackspace.com/",
"supported_methods": {
"list_nodes": {
"arguments": [],
"return": {
"type": "list of Node",
"description": "list of node objects"
},
"name": "list_nodes",
@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",
@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: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: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: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}
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}
"""