Skip to content

Instantly share code, notes, and snippets.

View zsiciarz's full-sized avatar

Zbigniew Siciarz zsiciarz

View GitHub Profile
#include "aquila/tools/TextPlot.h"
#include <cstddef>
int main(int argc, char *argv[])
{
const std::size_t SIZE = 64;
int arr[SIZE];
for (std::size_t i = 0; i < SIZE; ++i)
{
arr[i] = i % 10;
--- D:/Python26/Lib/site-packages/django_notification-0.1.4-py2.6.egg/notification/views.py Tue Jun 08 14:21:04 2010
+++ D:/Python26/Lib/site-packages/django_notification-0.1.4-py2.6.egg/notification/views2.py Tue Jun 08 14:21:12 2010
@@ -19,7 +19,7 @@
@login_required
def notices(request):
notice_types = NoticeType.objects.all()
- notices = Notice.objects.notices_for(request.user, on_site=True)
+ notices = Notice.objects.notices_for(request.user, on_site=True).select_related(depth=1)
settings_table = []
for notice_type in NoticeType.objects.all():
@zsiciarz
zsiciarz / mixins.py
Created November 12, 2010 13:37
A few useful mixin classes for Django object managers.
from django.contrib import comments
from django.contrib.contenttypes.models import ContentType
from django.db import connection
from django.db import models
from django.utils.datastructures import SortedDict
class RecentManagerMixin(object):
pub_date_field_name = 'pub_date'
@zsiciarz
zsiciarz / gist:722396
Created November 30, 2010 21:04
Saving .wav files - coming soon to Aquila :)
Aquila::SineGenerator generator(44100);
generator.setAmplitude(2000).setFrequency(500).generate(10 * 44100);
Aquila::WaveFile::save(generator, "L:\\sin.wav");
@zsiciarz
zsiciarz / sfml_imperial_march.cpp
Created December 26, 2010 10:37
You can use Aquila with SFML to join the Dark Side of the Force!
/**
* Playing the Imperial March from Star Wars.
*
* Notes and timings found at:
* http://processors.wiki.ti.com/index.php/Playing_The_Imperial_March
*/
#include "aquila/source/generator/SineGenerator.h"
#include "aquila/wrappers/SoundBufferAdapter.h"
#include <SFML/Audio.hpp>
# -*- coding: utf-8 -*-
import string
vowels, consonants = 'aąeęioóuy', 'bcćdfghjklłmnńpqrsśtvwxzźż'
trans = string.maketrans(vowels + consonants, 'V' * len(vowels) + 'C' * len(consonants))
patterns = [w.lower().translate(trans, string.punctuation + string.digits) for w in open('in.txt', 'r').read().split()]
for p, count in sorted(dict((p, patterns.count(p)) for p in set(patterns)).iteritems(), key=lambda (k,v): (v,k), reverse=True):
print '%24s: %d' % (p, count)
@zsiciarz
zsiciarz / testcase.py
Created May 4, 2011 11:42
Context managers are sexy for testing.
# -*- coding: utf-8 -*-
from django.test import TestCase
class _ObjectContext(object):
u"""
Context manager returned by assertObjectCreated/assertObjectDeleted.
"""
def __init__(self, enter_assertion, exit_assertion, model_class, **kwargs):
@zsiciarz
zsiciarz / fb.css
Created October 13, 2012 22:53
Bring back text emoticons on Facebook
.UFIComment .emote_text {
display: inline !important;
}
.UFIComment .emote_img {
display: none !important;
}
@zsiciarz
zsiciarz / utils.py
Created October 16, 2012 13:53
HTML diff of most recent changes in model
import reversion
from reversion.helpers import generate_patch_html
def get_html_diff(instance):
versions = reversion.get_for_object(instance)
if len(versions) < 2:
return "New object, no diff"
else:
diffs = []
@zsiciarz
zsiciarz / models.py
Created October 21, 2012 11:30
Unique slugs for Django models
from django.template.defaultfilters import slugify
def get_unique_slug(model_class, value):
slug = base_slug = slugify(value)
i = 1
while model_class.objects.filter(slug=slug).exists():
slug = '%s%d' % (base_slug, i)
i += 1
return slug