Skip to content

Instantly share code, notes, and snippets.

View zsiciarz's full-sized avatar

Zbigniew Siciarz zsiciarz

View GitHub Profile
@zsiciarz
zsiciarz / config.yml
Created October 26, 2021 17:07
Nameko with sentry_sdk
AMQP_URI: ${AMQP_URI:pyamqp://guest:guest@localhost}
SENTRY:
DSN: https://your.sentry.dsn
#!/bin/bash
set -euox pipefail
IFS=$'\n\t'
INTERPOLATED_COUNT=25
PHOTOS_DIR=$1
TEMPORARY_FRAMES_DIR=tmp_frames
echo "Making timelapse from photos in $PHOTOS_DIR..."
<?php
function get_interval($older, $newer) {
$invert = $newer < $older;
if ($invert) {
list($older, $newer) = array($newer, $older);
}
$Y1 = $older->format('Y');
$Y2 = $newer->format('Y');
$Y = $Y2 - $Y1;
@zsiciarz
zsiciarz / explain.sql
Created June 2, 2013 10:01
EXPLAIN ANALYZE for unnesting PostgreSQL arrays with and without subquery.
-- without subquery
explain analyze
select
unnest(tags) as tag,
count(unnest(tags)) as tag_count
from photos_photo
group by tag
order by tag_count desc;
-- with subquery
@zsiciarz
zsiciarz / main.cpp
Last active December 15, 2015 07:59
Naive operators (too many loops), but with move semantics (less copying).
// build and run with:
// g++ -Wall -std=gnu++0x -O0 -fno-elide-constructors main.cpp -o main && ./main
// or:
// clang++ -Wall -std=gnu++0x -O0 -fno-elide-constructors main.cpp -o main && ./main
#include <cstddef>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
@zsiciarz
zsiciarz / main.cpp
Last active December 14, 2015 02:49
// build and run with:
// g++ -Wall -std=gnu++0x -O0 -fno-elide-constructors main.cpp -o main && ./main
// or:
// clang++ -Wall -std=gnu++0x -O0 -fno-elide-constructors main.cpp -o main && ./main
#include <iostream>
class MoveMe {
public:
MoveMe(int value = -1): data(new int(value)) {
std::cout << "MoveMe(): " << *data << " (" << data << ")\n";
@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
@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 / 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 / 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):