Skip to content

Instantly share code, notes, and snippets.

View cheekybastard's full-sized avatar

cheekybastard

View GitHub Profile
# ========================================
# Testing n-gram analysis in ElasticSearch
# ========================================
curl -X DELETE localhost:9200/ngram_test
curl -X PUT localhost:9200/ngram_test -d '
{
"settings" : {
"index" : {
"analysis" : {
# ========================================
# Testing n-gram analysis in ElasticSearch
# ========================================
curl -X DELETE localhost:9200/test
curl -X PUT localhost:9200/test -d '
{
"settings" : {
"index" : {
"analysis" : {
@cheekybastard
cheekybastard / gist:17f5b67ea8db4137b8ed
Created July 16, 2014 03:03
Hidden Markov model example
#http://sujitpal.blogspot.com.au/2013/03/the-wikipedia-bob-alice-hmm-example.html
#http://en.wikipedia.org/wiki/Hidden_Markov_model
from __future__ import division
import numpy as np
from sklearn import hmm
states = ["Rainy", "Sunny"]
n_states = len(states)
@cheekybastard
cheekybastard / filtering.py
Created November 23, 2012 01:57 — forked from robgolding/filtering.py
Django Class-Based View Mixins: Part 2
class FilterMixin(object):
"""
View mixin which provides filtering for ListView.
"""
filter_url_kwarg = 'filter'
default_filter_param = None
def get_default_filter_param(self):
if self.default_filter_param is None:
raise ImproperlyConfigured(
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
import selenium.webdriver.support.wait
selenium.webdriver.support.wait.POLL_FREQUENCY = 0.05
import re
import random
import collections
class AdwordsAutomater(object):
from datetime import datetime
from datetime import timedelta
def queryset_generator(queryset, chunksize=1000):
"""
Iterate over a Django Queryset ordered by the primary key
This method loads a maximum of chunksize (default: 1000) rows in its
memory at the same time while django normally would load all rows in its
memory. Using the iterator() method only causes it to not preload all the
#-*- coding:utf-8 - *-
def load_dataset():
"Load the sample dataset."
return [[1, 3, 4], [2, 3, 5], [1, 2, 3, 5], [2, 5]]
def createC1(dataset):
"Create a list of candidate item sets of size one."
"""
https://groups.google.com/forum/#!topic/django-oscar/BMibGnLb6w0
I've replaced the Partner model. AbstractPartner already carries a ManyToMany field to users (which is not used as far as I can tell). My model instead got a OneToOne field to users and duck-typing to ensure compatibility with Oscar. https://gist.github.com/4690160
I create a Partner instance for every User via a post_save signal.
When a Product with StockRecord is created, Stockrecord.partner gets set to self.request.user.partner, and hence the connection is made.
The dirty work is overriding all the get_query_set functions in dashboard views to limit results to the logged in user. An example:
# views.py
# coding=UTF-8
import time
from gevent import monkey, spawn, sleep
monkey.patch_all()
import urllib2
import Tkinter as tk
run_forever = True
class App(object):
@cheekybastard
cheekybastard / scrapy_plus_selenium
Created February 13, 2013 14:10
Scrapy + selenium to scrape a page and a subpage from a list
Using Scrapy to Scrape a Page and a Subpage from a list
from scrapy.contrib.spiders.init import InitSpider
from scrapy.http import Request, FormRequest
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from selenium import selenium