Skip to content

Instantly share code, notes, and snippets.

@fission6
fission6 / touchpad.py
Created August 22, 2011 14:46
HP Touchpad tracker
import urllib2
from lxml import html
from time import sleep
from datetime import datetime
from subprocess import Popen
PRODUCT_URL = "http://www.shopping.hp.com/store/product/product_detail/FB355UA%2523ABA?jumpid=se_r1002_fp_usen_hho"
def check():
"""
@fission6
fission6 / touchpad.py
Created August 22, 2011 16:03
newegg touchpad watcher
import urllib2
from time import sleep
from datetime import datetime
from subprocess import Popen
PRODUCT_URL = "http://content.newegg.com/LandingPage/ItemInfo4ProductDetail.aspx?Item=N82E16834158004"
def check():
"""
Check product url and look for 'Out of Stock' in the specified xpath.
@fission6
fission6 / backend.py
Created October 11, 2011 17:23
django authentication using an email or username
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
class EmailorUsernameBackend(ModelBackend):
"""
Authenticate given a users email or user name.
Does a double look up on email and user name but would rather
call super for ModelBackend to keep up with any changes.
put the following in your settings.py
@fission6
fission6 / gevent_samply.py
Created December 8, 2011 04:33
gevent concurrent url request snippet
import gevent
from gevent import monkey; monkey.patch_all()
from gevent import pool
import random
from time import sleep, time
import urllib2
POOL_SIZE = 5
@fission6
fission6 / models.py
Created January 5, 2012 19:50
monkey patch django User to access Mongo Document
@property
def document(self):
user_id = self.id
user_document = UserDocument.objects.get(user_fk=user_id)
return user_document
User.add_to_class("document", document)
@fission6
fission6 / es.sh
Created January 16, 2012 19:21 — forked from aaronshaf/es.sh
Install ElasticSearch on Ubuntu 11.04
cd ~
sudo apt-get install unzip
sudo apt-get install python-software-properties -y
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin -y
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.17.6.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
@fission6
fission6 / optional_boost.py
Created January 28, 2012 17:39 — forked from toastdriven/optional_boost.py
For fission6...
>>> from haystack.inputs import Raw
>>> from haystack.query import SearchQuerySet, SQ
>>> sqs = SearchQuerySet().filter(content='python')
>>> sqs2 = SearchQuerySet().filter(SQ(content='python') | (SQ(content='python') & SQ(content=Raw('pycon^10'))))
>>>
>>> sqs.count()
16
>>> sqs2.count()
16
>>>
@fission6
fission6 / model_utils.py
Created May 3, 2012 17:40
Chaining Custome QuerySet method for Django Models
from django.db import models
# http://www.djangosnippets.org/snippets/562/#c673
class QuerySetManager(models.Manager):
# http://docs.djangoproject.com/en/dev/topics/db/managers/#using-managers-for-related-object-access
# Not working cause of:
# http://code.djangoproject.com/ticket/9643
#!/usr/env python2
from random import choice
pop = ['a', 'b', 'c',]
simulations = 0
"""
while simulations < 3:
simulations += 1
@fission6
fission6 / Deploy Notes
Last active November 19, 2015 14:16
Deployment notes for Ubuntu Instance Nginx, uwsgi, postgres, django, virtualenv stack
Deployment notes for Ubuntu Instance
Nginx, uwsgi, postgres, django, virtualenv stack
* ssh root
root access (need pem)
ssh -i whatever.pem ubuntu@ec2-*-*-*-*.compute-1.amazonaws.com
* secure box
- cut off all ports but 22 and 80 using AWS Management Console
- edit /etc/ssh/sshd_config ensure PasswordAuthentication no