Skip to content

Instantly share code, notes, and snippets.

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
# 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):
@eserge
eserge / about.md
Last active May 23, 2018 08:24 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer

Keybase proof

I hereby claim:

  • I am eserge on github.
  • I am eserge (https://keybase.io/eserge) on keybase.
  • I have a public key whose fingerprint is A361 E468 4BDD A5AB 57C3 BC8A 7214 9B90 BCE4 4CF7

To claim this, I am signing this object:

@eserge
eserge / gist:3426706
Created August 22, 2012 15:21
Django template snippet creating sortable thumbnails list instead of inlines.
{% 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);
}
@eserge
eserge / gist:1926536
Created February 27, 2012 19:40
LoginMixin. A mixin for securing a class.
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")
@eserge
eserge / gist:1729974
Created February 3, 2012 12:37
highlight a 'part' part of a given string ('highlight_string')
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;
@eserge
eserge / gist:1606523
Created January 13, 2012 14:36
Hide or show element depending on checkbox state
$("#control_checkbox").click(function(){
$(".concealable").css('display', (this.checked)?"block":"none");
});
@eserge
eserge / gist:1605923
Created January 13, 2012 12:40
simple random string generator
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)