This file contains hidden or 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
# Ruby | |
[zuber@fish Projekty]$ ruby -v | |
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0] | |
[zuber@fish Projekty]$ time ruby test.rb > /dev/null | |
real 0m33.294s | |
user 0m31.745s | |
sys 0m0.303s |
This file contains hidden or 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 fib(n): | |
if n < 2: | |
return n | |
else: | |
return fib(n - 1) + fib(n - 2) | |
This file contains hidden or 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 fib2(n): | |
a, b = 0, 1 | |
for x in range(n): | |
a, b = b, a + b | |
return a |
This file contains hidden or 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 fib(n): | |
"""Działa, ale tylko dla n równego 1 lub 2. Poprawność częściowa ;-)""" | |
return n |
This file contains hidden or 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
class Die(object): | |
def __init__(self, n): | |
self.n = n | |
def roll(self): | |
"""Niestety ta funkcja jest jeszcze mało losowa. Dopracować!""" | |
return n |
This file contains hidden or 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
class Die(object): | |
def __init__(self, n): | |
self.n = n | |
def roll(self): | |
return random.randint(1, self.n) |
This file contains hidden or 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 django.db import models | |
from django.contrib.auth.models import User | |
class Gallery(models.Model): | |
title = models.CharField( max_length=80) | |
owner = models.ForeignKey(User) | |
created_at = models.DateTimeField(auto_now_add=True) | |
class Meta: | |
ordering = ['title', 'created_at'] |
This file contains hidden or 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
# Create your views here. | |
from django.shortcuts import render_to_response | |
from gallery.models import Gallery | |
def gallery_list(request): | |
galleries = Gallery.objects.all() | |
return render_to_response('gallery/gallery_list.html', {'galleries': galleries}) |
This file contains hidden or 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 annoying.decorators import render_to | |
@render_to('template.html') | |
def foo(request): | |
bar = Bar.object.all() | |
return {'bar': bar} | |
# equals to | |
from django.views.generic.simple import direct_to_template |
OlderNewer