Skip to content

Instantly share code, notes, and snippets.

@honzakral
honzakral / run_django_tests.sh
Created December 29, 2009 05:32
Script for paralel execution of django's test suite.
#!/bin/bash
set -e
##
# Script for paralel execution of django's test suite.
#
# Usage: place it in the same directory as your django checkout (not inside)
# and run it
#
# Params: you can optionally supply number of processes to spawn

Stackoverflow to Elasticsearch

This script will load any stackoverflow site from the XML dump (retrievable at https://archive.org/details/stackexchange via torrent) into Elasticsearch.

To use just call:

python load_stack.py PATH
@honzakral
honzakral / snake.py
Last active October 31, 2021 02:20
snake game in python
import pygame
from pygame.locals import *
from random import randint
import os, sys
ARRAY_SIZE = 50
DIRECTIONS = {
"LEFT": (-1, 0),
"RIGHT": (1, 0),
@honzakral
honzakral / search.py
Last active March 11, 2021 09:47
Super simple inverted index in Python
import re
from collections import defaultdict, Counter
def bold(txt):
return '\x1b[1m%s\x1b[0m' % txt
DATA = [
{
'title': 'Django',
'description': 'Django is a high-level Python Web framework that '
@honzakral
honzakral / -README.rst
Last active August 24, 2020 09:24
WebExpo demo
"""
This is a simple benchmark that tests the performance of several
locking implementations. Each example implements a connection
pool that provides `get_connection()` to retrieve a connection
from the pool and `release()` to return a connection back to the
pool.
The `test()` function creates an instance of `pool_class` and
creates `num_threads` `threading.Thread` instances that simply call
`pool.get_connection()` and `pool.release()` repeatedly until
@honzakral
honzakral / pres.sh
Created December 2, 2019 10:20
External display switcher
#!/bin/sh
PRIMARY=$(xrandr| grep -P '^[[:alnum:]-]+ connected primary' | cut -d ' ' -f 1)
SECONDARY=$(xrandr| grep -P '^[[:alnum:]-]+ connected (?!primary)' | head -n 1 | cut -d ' ' -f 1)
OUTPUTS=$(xrandr | sed -ne '2,$s;^\([^ ]\{1,\}\).*;\1;p' | grep -v "^$PRIMARY\$")
CMD="xrandr --output $PRIMARY --primary --auto "
function resolution {
xrandr | sed -ne "/$1/,/^[^ ]/s;^ [[:space:]]*\([0-9xip]\{1,\}\) .*;\1;p"
@honzakral
honzakral / README.rst
Last active September 27, 2018 19:38
CLI for elaasticsearch-py helpers

Elasticsearch CLI

Experimental CLI interface for the helpers in the python library.

Main purpose is to expose the bulk functionality to enable rapid loading of data into an elasticsearch cluster. Combined with the scan command it can also be used to reindex data from elasticsearch into a different index or cluster.

Keybase proof

I hereby claim:

  • I am honzakral on github.
  • I am honzakral (https://keybase.io/honzakral) on keybase.
  • I have a public key ASC44AI9qQetZNTdBWjaYJitFwRRI-X7g3dMXl6Pp0hQWQo

To claim this, I am signing this object:

@honzakral
honzakral / doc.py
Created April 15, 2016 17:44
Dynamic template mappings in python DSL
from elasticsearch_dsl import DocType, Object, MetaField
class MyDoc(DocType):
inner = Object()
class Meta:
dynamic_templates = MetaField([
{
'strings_in_inner': {
'path_match': 'inner.*',