This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
from itertools import islice, tee | |
def cut_chunks(iterable, size): | |
it = iter(iterable) | |
while True: | |
test_chunk, chunk = tee(islice(it, size)) | |
try: | |
next(test_chunk) | |
yield chunk |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
# starting with https://www.codewars.com/kata/stack-arithmetic-machine/train/python | |
import operator | |
class Machine(object): | |
def __init__(self, cpu): | |
self.cpu = cpu | |
def execute(self, instr): |
{% block extrahead %}{{ block.super }} | |
{% url 'admin:jsi18n' as jsi18nurl %} | |
<script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script> | |
{{ media }} | |
<script src="{{STATIC_URL}}js/jquery-ui-1.8.17.custom.min.js"></script> | |
<script> | |
function jqVersion() { | |
alert(jQuery.fn.jquery); | |
} |
class LoginMixin(object): | |
"""Mixin for securing a class. | |
Taken from here: | |
https://groups.google.com/d/msg/django-users/g2E_6ZYN_R0/tnB9b262lcAJ | |
""" | |
def do_logout(self, request): | |
"""Logs the user out if necessary.""" | |
logout(request) |
# -*- coding: utf-8 -*- | |
from django.forms.models import ModelForm | |
from django import forms | |
from models import Profile | |
import bleach | |
class EditProfileForm(ModelForm): | |
phone = forms.CharField(required=False, | |
help_text=u"Рекомендуемый формат: +74951234567") |
function hightlight(highlight_string, part){ | |
workstring = highlight_string; | |
var indices = []; | |
var cut = all_cut = 0; | |
while (workstring.indexOf(part) != -1) { | |
index = workstring.indexOf(part); | |
indices.push(index+all_cut); | |
cut = index + part.length; | |
workstring = workstring.substr(cut); | |
all_cut = all_cut + cut; |
$("#control_checkbox").click(function(){ | |
$(".concealable").css('display', (this.checked)?"block":"none"); | |
}); |
def random_string(length): | |
'''visually similar characters were deliberately removed''' | |
import random | |
letters = u"346789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY" | |
return "".join([letters[random.randint(0,len(letters)-1)] for i in range(length)]) | |
if __name__ == "__main__": | |
for i in range(10): | |
print random_string(10) |
# -*- coding: utf-8 -*- | |
import decimal | |
from django.conf import settings | |
from shop.cart.cart_modifiers_base import BaseCartModifier | |
class FixedShippingCosts(BaseCartModifier): | |
# """ | |
# This will add a fixed amount of money for shipping costs. | |
# """ |