Skip to content

Instantly share code, notes, and snippets.

View teserak's full-sized avatar
🏠
Working from home

Konrad Rymczak teserak

🏠
Working from home
View GitHub Profile
@teserak
teserak / simplify.py
Created February 4, 2012 11:14
simplify-py
# python version of http://mourner.github.com/simplify-js/
class Point(object):
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return "<Point x=%s y=%s>" % (self.x, self.y)
def sqDist(p1, p2):
@teserak
teserak / staritems.py
Created April 18, 2012 06:17
Migrate stars and likes in Google Reader
#! python2
#
# Gaute Hope <eg@gaute.vetsj.com> 2011
#
# Note: This script was only made to serve its purpose one time, and is not
# necessarily very user friendly. But have been used with success migrating
# Google Reader data to a Google Apps account.
#
# Stars and likes items in Google Reader, used to migrate starred
# and liked items from old account to new. Subscriptions already
@teserak
teserak / dropbox_upload_handler.py
Created July 19, 2012 05:22 — forked from theju/dropbox_upload_handler.py
Upload files to dropbox from your django app
from django.core.files.uploadhandler import TemporaryFileUploadHandler
from django.core.files.base import File
from dropbox.client import DropboxClient
from dropbox.session import DropboxSession
from django.conf import settings
import os
class DropboxFileUploadHandler(TemporaryFileUploadHandler):
def __init__(self, *args, **kwargs):
super(DropboxFileUploadHandler, self).__init__(*args, **kwargs)
def run_pg_fouine():
info = host_info[env.host_string]
db_name = info.tags.get('Name')
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 0/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
time.sleep(30)
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 500/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
run('tail -n 100000 /var/log/postgresql/postgresql-9.*-main.log > /tmp/pgfouine.txt')
run('gzip -f /tmp/pgfouine.txt')
@teserak
teserak / main.py
Created August 25, 2012 09:50
Tornado, MongoDB, WebSockets -chat
import logging
import tornado.escape
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.websocket
import os.path
import asyncmongo
import time
import functools
@teserak
teserak / SimpleFilteringListView.py
Created September 18, 2012 12:07 — forked from mateuszpohl/SimpleFilteringListView.py
Django generic list view with simple filtering
from django.views.generic import ListView
class SimpleFilteringListView(ListView):
"""
List view with extra filtering and grouping in context data.
``filters`` dict is created as follows: {'context_variable_name', 'filtering_object_method_name'}
It calls filtering method on each object in object_list and if it returns True - this object is added
to proper context variable.
@teserak
teserak / webtail.py
Created October 11, 2012 22:03 — forked from maximebf/webtail.py
Web tail / tail -f as a webpage using websocket
#!/usr/bin/python
# Equivalent of "tail -f" as a webpage using websocket
# Usage: webtail.py PORT FILENAME
# Tested with tornado 2.1
# Thanks to Thomas Pelletier for it's great introduction to tornado+websocket
# http://thomas.pelletier.im/2010/08/websocket-tornado-redis/
import tornado.httpserver
@teserak
teserak / gist:4027591
Created November 6, 2012 21:12 — forked from aita/gist:1300634
ListFormView
class ListFormMixin(MultipleObjectMixin, FormMixin):
'''フォームを持つListViewの実装のためのMixin
memo:
get_context_dataメソッドが重複する
'''
class BaseListFormView(ListFormMixin, View):
def get(self, request, *args, **kwargs):
@teserak
teserak / ctags_autocomplete.py
Created November 7, 2012 08:07 — forked from BlackMac/ctags_autocomplete.py
autocomplete over project for Sublime Text 2
# CTags based autocompletion plugin for Sublime Text 2
# You can add the file to the User Package in ~/Library/Application Support/Sublime Text 2/Packages and restart Sublime Text 2.
# generate the .tags file in your project root with "ctags -R -f .tags"
import sublime, sublime_plugin, os
class AutocompleteAll(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
tags_path = view.window().folders()[0]+"/.tags"
@teserak
teserak / login_required.py
Created November 23, 2012 19:18 — forked from robgolding/login_required.py
Django Class-Based View Mixins: Part 1
class LoginRequiredMixin(object):
"""
View mixin which requires that the user is authenticated.
"""
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
return super(LoginRequiredMixin, self).dispatch(
self, request, *args, **kwargs)