Skip to content

Instantly share code, notes, and snippets.

View Visgean's full-sized avatar

martin Visgean

View GitHub Profile
>>> voting_round_instance = models.VotingRound.objects.first()
>>> voting_round_instance.vote_set.values('vote').annotate(count=Count('vote')).distinct()
[{'vote': u'decline', 'count': 1}, {'vote': u'neutral', 'count': 1}, {'vote': u'decline', 'count': 1}, {'vote': u'approve', 'count': 1}, {'vote': u'approve', 'count': 1}]
def date_range(first_date, second_date):
"""
Returns range of dates between first and second date
:type first_date: datetime.date
:type second_date: datetime.date
:return: list of dates
"""
if first_date == second_date:
return []
elif first_date > second_date:
def date_range(first_date, second_date):
"""
Returns range of dates between first and second date
:type first_date: datetime.date
:type second_date: datetime.date
:return: list of dates
"""
if first_date == second_date:
return []
elif first_date > second_date:
# Easiest way:
# But it is without support for complex number.
from math import factorial
factorial(6)
#! /usr/bin/python
# -*- coding: UTF-8 -*-
# Pascal´s Rectangle
start = int(raw_input("Starting number: "))
pascal = [[start]] # at least one item is necessary to be here
for cycle in range(int(raw_input("Number of lines: "))-1):
line = []
#! /usr/bin/python
# -*- coding: UTF-8 -*-
# Deda vseveda by Visgean Skeloru <visgean (at) gmail.com>
# To run this script you have to EAT A CAT and force somebody to COMMIT A SUCIUDE!
from random import choice
from sys import argv
#! /usr/bin/python
# -*- coding: UTF-8 -*-
import pyinotify
class notifier(pyinotify.ProcessEvent):
def process_IN_ACCESS(self, event):
"file was accessed."
pass
#! /usr/bin/python
# -*- coding: UTF-8 -*-
# Script for discover where is some module which you want to use with starndart
# sys.path
import sys, os
desiredModule = raw_input("Module name: ")
def pseudoRange(numberOfCycles):
i = 0
while i < numberOfCycles:
i += 1
yield i
for i in pseudoRange(4):
print i
if i == 2:
#! /usr/bin/python
# -*- coding: UTF-8 -*-
# Pythagoras triangle in new version with yield!
def giveMeLines(numberOfLines):
line = [1]
for xexe in xrange(numberOfLines):
yield line
tempLine = [] # buffer for new elements