Skip to content

Instantly share code, notes, and snippets.

View cypreess's full-sized avatar

Kris Dorosz cypreess

View GitHub Profile
@cypreess
cypreess / robot.js
Created December 4, 2012 18:13
asxs
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
cypreess@iMac ~ cat f.cc
#include <stdio.h>
int main(){
unsigned char a = 255;
unsigned long int b = (a << 24);
unsigned long int c = ((unsigned long int) a << 24);
printf("b=%lu\n", b);
printf("c=%lu\n", c);
cypreess@wierzba:~$ . /usr/local/bin/virtualenvwrapper.sh
cypreess@wierzba:~$ mkvirtualenv test1
New python executable in test1/bin/python2.7
Also creating executable in test1/bin/python
Installing setuptools............done.
Installing pip...............done.
(test1)cypreess@wierzba:~$ pip install -e git+https://github.com/agh-glk/plp.git#egg=plp-dev
Obtaining plp from git+https://github.com/agh-glk/plp.git#egg=plp-dev
Cloning https://github.com/agh-glk/plp.git to ./.virtualenvs/test1/src/plp
Unpacking objects: 100% (19/19), done.
@cypreess
cypreess / periodic_thread.py
Last active February 28, 2024 02:59
Python periodic thread using timer. You can cancel this thread any time. Thread will live at maximum to the end of one single processing run, otherwise it will end in the same time (especially during a wait time for next run). This code avoids the problem of waiting very long for thread exiting, because it does not uses time.sleep(). Please be a…
import logging
import threading
class PeriodicThread(object):
"""
Python periodic Thread using Timer with instant cancellation
"""
def __init__(self, callback=None, period=1, name=None, *args, **kwargs):
class ExtraValueMixin(object):
value = 1
def get_value(self):
return self.value
def get_context_data(self, *args, **kwargs):
context = .... super ... get_context_data
context['extra_value'] = self.get_value()
return context
@cypreess
cypreess / gist:5849702
Last active December 18, 2015 21:48
Reading from iterator N elements by a time - the python way.
>>> from itertools import *
# First try is like that - OK it works
>>> count = 5
>>> iterator = xrange(100)
>>> list(imap(None, *([iter(iterator)] * count)))
[(0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14), (15, 16, 17, 18, 19), (20, 21, 22, 23, 24), (25, 26, 27, 28, 29), (30, 31, 32, 33, 34), (35, 36, 37, 38, 39), (40, 41, 42, 43, 44), (45, 46, 47, 48, 49), (50, 51, 52, 53, 54), (55, 56, 57, 58, 59), (60, 61, 62, 63, 64), (65, 66, 67, 68, 69), (70, 71, 72, 73, 74), (75, 76, 77, 78, 79), (80, 81, 82, 83, 84), (85, 86, 87, 88, 89), (90, 91, 92, 93, 94), (95, 96, 97, 98, 99)]
# Apparently imap(None,...) is equivalent to izip() - so we can simplify it
>>> count = 5
Using worker: worker-linux-3-2.bb.travis-ci.org:travis-linux-9
$ git clone --depth=50 --branch=master git://github.com/agh-glk/pydic.git agh-glk/pydic
Cloning into 'agh-glk/pydic'...
remote: Counting objects: 155, done.
remote: Compressing objects: 100% (87/87), done.
remote: Total 155 (delta 71), reused 144 (delta 66)
Receiving objects: 100% (155/155), 43.05 KiB | 0 bytes/s, done.
Resolving deltas: 100% (71/71), done.
$ cd agh-glk/pydic
@cypreess
cypreess / scrabble_rank.py
Created September 20, 2013 05:39
MegiTeam scrabble turnament
# coding=utf-8
from pydic import PyDic
sjp = PyDic('../../data/sjp/sjp.pydic')
weights = {u'a': 1, u'ą': 5, u'b': 3, u'c': 2, u'ć': 6, u'd': 2, u'e': 1, u'ę': 5, u'f': 5, u'g': 3, u'h': 3, u'i': 1,
u'j': 3, u'k': 2, u'l': 2, u'ł': 3, u'm': 2, u'n': 1, u'ń': 7, u'o': 1, u'ó': 5, u'p': 2, u'r': 1, u's': 1,
u'ś': 5, u't': 2, u'u': 3, u'w': 1, u'y': 2, u'z': 1, u'ź': 9, u'ż': 5, }
def rank(word):
import logging
import threading
class PeriodicThread(object):
"""
Python periodic Thread using Timer with instant cancellation
"""
def __init__(self, callback=None, period=1, name=None, *args, **kwargs):
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/cypreess/dev/django/tests/forms_tests/tests/test_fields.py", line 92, in test_charfield_1
self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, None)
File "/Users/cypreess/dev/django/django/test/testcases.py", line 576, in assertRaisesMessage
re.escape(expected_message), callable_obj, *args, **kwargs)
File "/Users/cypreess/dev/django/django/utils/six.py", line 654, in assertRaisesRegex
return getattr(self, _assertRaisesRegex)(*args, **kwargs)