Skip to content

Instantly share code, notes, and snippets.

@barseghyanartur
barseghyanartur / clean_media.py
Last active November 24, 2017 18:09
Clean media by deleting those files which are no more referenced by any FileField (django command)
# -*- coding: utf-8 -*-
import os
import sys
from six.moves import input
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.apps import apps
@barseghyanartur
barseghyanartur / httpie.sh
Created April 11, 2016 13:00 — forked from chris-rock/httpie.sh
Httpie Quick Install Ubuntu 14.04
apt-get update && apt-get install -y curl && curl --silent https://bootstrap.pypa.io/get-pip.py |python3 && pip install --upgrade httpie
@barseghyanartur
barseghyanartur / README.txt
Created May 11, 2016 09:20 — forked from mattweber/README.txt
ElasticSearch Multi-Select Faceting Example
This is an example how to perform multi-select faceting in ElasticSearch.
Selecting multiple values from the same facet will result in an OR filter between each of the values:
(facet1.value1 OR facet1.value2)
Faceting on more than one facet will result in an AND filter between each facet:
(facet1.value1 OR facet1.value2) AND (facet2.value1)
I have chosen to update the counts for each facet the selected value DOES NOT belong to since we are performing an AND between each facet. I have included an example that shows how to keep the counts if you don't want to do this (filter0.sh).
@barseghyanartur
barseghyanartur / custom_elasticsearch.md
Created May 17, 2016 10:16 — forked from aolieman/custom_elasticsearch.md
Haystack provides an interface similar to Django's QuerySet, which instead enables easy querying in one or more popular search backends. Because the Haystack API is meant to hook up to several search backends, however, not all the functionality of the backends has been implemented in the API. In this post we show how Haystack's Elasticsearch bac…

Extending Haystack's Elasticsearch backend

Haystack provides an interface similar to Django's QuerySet, which instead enables easy querying in one or more popular search backends. Because the Haystack SearchQuerySet API is meant to hook up to several search backends, however, not all the functionality of the backends has been implemented in the API. In this article we show how Haystack's Elasticsearch backend can be extended with advanced querying functionality.

As an exemplary use case, we'll focus on implementing Elasticsearch's Nested Query in the SearchQuerySetAPI, to enable e.g. weighted tags on documents. The usage of this extended API will be shown first, after which we'll go through the necessary implementation steps.

ConfigurableSearchQuerySet API Usage

import search.custom_elasticsearch as ces
from files import FileObject
@barseghyanartur
barseghyanartur / mapping.sh
Created May 23, 2016 07:40 — forked from zwrss/mapping.sh
Mappings for elasticsearch not nested stuff
#!/bin/sh
echo
curl -XDELETE 'http://localhost:9200/items'
echo
curl -XPUT 'localhost:9200/items' -d '
{
"mappings" : {
"Item" : {
"dynamic" : false,
@barseghyanartur
barseghyanartur / select_requirements.py
Created May 14, 2017 21:26 — forked from pombredanne/select_requirements.py
Select Python pip requirements files based on os, platform or else
#!/usr/bin/python
# #
# Copyright (c) 2014 by nexB, Inc. http://www.nexb.com/ - All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@barseghyanartur
barseghyanartur / aggregate_concat.py
Created May 17, 2017 15:03 — forked from ludoo/aggregate_concat.py
Django aggregates GROUP_CONCAT support for MySQL
"""
From http://harkablog.com/inside-the-django-orm-aggregates.html
with a couple of fixes.
Usage: MyModel.objects.all().annotate(new_attribute=Concat('related__attribute', separator=':')
"""
from django.db.models import Aggregate
from django.db.models.sql.aggregates import Aggregate as SQLAggregate
@barseghyanartur
barseghyanartur / tetris.py
Created June 5, 2017 00:34 — forked from silvasur/tetris.py
Tetris implementation in Python
#!/usr/bin/env python2
#-*- coding: utf-8 -*-
# NOTE FOR WINDOWS USERS:
# You can download a "exefied" version of this game at:
# http://hi-im.laria.me/progs/tetris_py_exefied.zip
# If a DLL is missing or something like this, write an E-Mail (me@laria.me)
# or leave a comment on this gist.
# Very simple tetris implementation
@barseghyanartur
barseghyanartur / Kibana-readonly.md
Created September 8, 2017 13:07 — forked from r0mdau/Kibana-readonly.md
Kibana readonly over internet

#Kibana Readonly

With this tip, kibana can't be modified. So you can share the uri to anyone on the internet. It's a network method to protect kibana from changes of anonymous.

##Quick start

  1. You need to have a working kibana exposed over http on internet
  2. On the same elasticsearch server, install nginx : apt-get install nginx
  3. In the directory /etc/nginx/sites-available, create a new file and edit it, for example : vi /etc/nginx/sites-available/kibana-readonly
  4. Write the following configuration :
@barseghyanartur
barseghyanartur / ELK with Nginx.md
Created September 8, 2017 15:20 — forked from Dev-Dipesh/ELK with Nginx.md
Setting up Elasticsearch, Logstash and Kibana with Nginx.

ELK (Elasticsearch Logstash Kibana)

Though we're focused more on server setup procedure in this document, I will still give a very brief explanation in laymen terms for ELK. To those who are starting new in this stack, must have already heard of MVC (Model View Controller), so take it like this:

  • Model => Elasticsearch (for Storage, Indexing & Search)
  • View => Kibana (for DataViz & G-Man, yeah the one in half life 😏)
  • Controller => Logstash (For Logs & Filtering)