Skip to content

Instantly share code, notes, and snippets.

View pije76's full-sized avatar

panjianom pije76

View GitHub Profile

Quick and Dirty Integration of elasticsearch api with rails

Take the following with a grain of salt ...

We started prototyping with ES & Rails about 2 days ago and I quickly discovered that things became a bit unwieldy the more I utilized elasticsearch. For now I am running with this type of integration with rails 3.2.15 to assess elasticsearch.

While we have done preliminary reviews on how to set up a production environment (still scratching my head on how to handle the split brain bug) , there's certainly plenty of what I'm not aware of, so if you see a fault in this approach, please let me know.

I may update this later on with a couple of convenience methods on the data models ...

from one_session_per_user.models import User, Visitor
from django.contrib.sessions.models import Session
class OneSessionPerUserMiddleware(object):
"""http://stackoverflow.com/a/1814797"""
def process_request(self, request):
if isinstance(request.user, User):
current_key = request.session.session_key
#!/usr/bin/env python
# encoding: utf-8
import sys, os, getopt
from django.core.management import setup_environ
import settings
setup_environ(settings)
from django.db.models import Q
import csv
from cStringIO import StringIO
from scrapy.http import Request
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from scrapy_tests.items import CrunchfeedItem
class Crunchfeed(BaseSpider):
from classytags.arguments import Argument, MultiValueArgument
from classytags.values import StringValue
from cms.templatetags.cms_tags import Placeholder, PlaceholderOptions
from cms.models.placeholdermodel import Placeholder as PlaceholderModel
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
{% load i18n future static fb_tags mezzanine_tags %}
{% load sorl_thumbnail %}
{% if query.pop %}
<style>
{% if query.pop == '4' %}
#media-library-popup #header, #media-library-popup .object-tools {display: none;}
#media-library-popup h1 {margin: -60px 0 15px 0;}
{% else %}
h1 {margin:-30px 0 15px 0;}
@pije76
pije76 / gist:6773380
Last active December 24, 2015 08:49 — forked from emilepetrone/gist:3147937
Thumbnail at admin page for mezzanine on AWS
from cStringIO import StringIO
@register.simple_tag
def thumbnail(image_url, width, height, quality=95):
"""
Given the URL to an image, resizes the image using the given width and
height on the first time it is requested, and returns the URL to the new
resized image. if width or height are zero then original ratio is
maintained.
"""
if not image_url:
@pije76
pije76 / models.py
Created August 24, 2013 18:54 — forked from mbrochh/models.py
Attach the django-shop cart to a User that started shopping anonymously
# add this soewhere where it gets loaded very early, i.e.
# your shop's models.py
from django.contrib.auth import login
from django.contrib.auth.signals import user_logged_in
from django.dispatch import receiver
from registration.signals import user_activated
from shop.models.defaults.cart import Cart
@pije76
pije76 / category.php
Created July 27, 2013 02:19
see the articles/posts above the subcategories of article-directory
<?php get_header(); ?>
<?php if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); ?>
<?php if (have_posts()) : ?>
<?php
$order = "&orderby=cost&order=DESC";
$s2 = ' selected="selected"';
if ($_POST['select'] == 'title') { $order = "&orderby=title&order=ASC"; $s1 = ' selected="selected"'; $s2 = ''; }
@pije76
pije76 / page-author.php
Created July 27, 2013 02:18
enable visitors to access any author profile even if they are not a ‘Top Author’ on article-directory plugin
<ul>
<?php
$uc=array();
$blogusers = get_users_of_blog();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$post_count = get_usernumposts($bloguser->user_id);
$uc[$bloguser->user_id]=$post_count;
}
arsort($uc);