Skip to content

Instantly share code, notes, and snippets.

View darklow's full-sized avatar

Kaspars Sprogis darklow

View GitHub Profile
@darklow
darklow / custom_view.html
Created October 8, 2014 14:15
Custom view template for Django
<!-- templates/admin/custom_view.html -->
{% extends "admin/base_site.html" %}
{% load i18n %}
{% block breadcrumbs %}
<ul class="breadcrumb">
<li class="active">
<i class="icon-home"></i>
{% trans "Custom view" %}
@darklow
darklow / celery_tasks_error_handling.py
Last active December 20, 2024 02:44
Celery tasks error handling example
from celery import Task
from celery.task import task
from my_app.models import FailedTask
from django.db import models
@task(base=LogErrorsTask)
def some task():
return result
class LogErrorsTask(Task):
ROOT_DIR="$1"
mkdir "$ROOT_DIR"
cd "$ROOT_DIR"
#setup venv
virtualenv env --distribute
source env/bin/activate
#install django so we can start up an app
@darklow
darklow / settings.py
Created March 3, 2014 11:06
DjangoSuit.com whole project settings.py - https://github.com/darklow/django-suit-examples
import os
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__) + '/../')
ENV_ROOT = os.path.abspath(PROJECT_ROOT + '/../')
ADMINS = (
('XX', '[email protected]'),
)
MANAGERS = ADMINS
curl -XGET "http://localhost:9200/movies/_search" -d'
{
"query": {
"nested": {
"path": "credits",
"query": {
"match": {
"credits.person_id": 1
}
}
@darklow
darklow / es_aggs_nested.sh
Last active June 19, 2017 06:31
New aggregation framework - filtering by nested object fields
#!/bin/bash
# ========================================
curl -X DELETE localhost:9200/movies
curl -X PUT localhost:9200/movies -d '
{
"mappings": {
"movie": {
"properties": {
"name": { "type": "string" },
@darklow
darklow / es_nested_facets_filter.sh
Last active December 31, 2015 07:59
Nested facets filtering by parent in ElasticSearch
#!/bin/bash
# ========================================
# Nested facets filtering by parent in ElasticSearch
# --------------------------------------------------
# I need to get facets of departments for specific person for one movie genre:
# facets for credit.department where genre=comedy, credits.person_id=1
# I am using include_in_parent:true mapping to be able to facet_filter by parent genre
# ========================================
curl -X DELETE localhost:9200/movies
@darklow
darklow / TagTrans.php
Last active December 31, 2015 02:09
Koken translation tag. <koken:trans en="Hello" fr="Bonjour" lv="Sveiki" />
<?php
class TagTrans extends Tag {
function generate()
{
$value = '""';
$lng = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en';
if(isset($this->parameters[$lng])){
$value = '"' . $this->attr_parse($this->parameters[$lng]) . '"';
@darklow
darklow / es_simple_analyzer.sh
Last active December 26, 2015 12:19
ElasticSearch simple analyzer test
#!/bin/bash
# ========================================
# Testing simple analyzer in ElasticSearch
# ========================================
curl -X DELETE localhost:9200/hotels
curl -X PUT localhost:9200/hotels -d '
{
"index": {
"analysis": {
@darklow
darklow / elasticsearch.custom.sort.py
Last active May 31, 2022 05:25
ElasticSearch custom sort, based on provided ids array order. Original code from here: http://damienalexandre.fr/post/elasticsearch-ids-query-order Rewritten to new "function_score" syntax Note: You need to remove \n new lines from "script" field in order to get it work.
q = {
"query": {
"function_score": {
"boost_mode": "replace",
"query": {
"ids": {
"values": [
50,
80,
44,