Skip to content

Instantly share code, notes, and snippets.

@Suor
Suor / update-sublime.pl
Created February 4, 2012 03:01
Sublime Text 2 updater for Linux
#!/usr/bin/perl
use v5.10;
use strict;
use warnings FATAL => 'all';
use Mojo::UserAgent;
my $latest_url = Mojo::UserAgent->new->get('http://www.sublimetext.com/2')
@Suor
Suor / INSTALL.markdown
Created November 7, 2011 08:41
open_file_at_cursor sublime command
cd ~/.config/sublime-text-2/Packages/User/
curl -O https://raw.github.com/gist/1344471/open_file_at_cursor.py

Open keyboard bindings file, and add a line to it

[
    ...
 { "keys": ["alt+o"], "command": "open_file_at_cursor" } // this one
@Suor
Suor / monkey.py
Created May 16, 2011 16:07
Efficient pickling of django models
from django.db.models import Model
from itertools import izip
def attnames(cls, _cache={}):
try:
return _cache[cls]
except KeyError:
_cache[cls] = [f.attname for f in cls._meta.fields]
return _cache[cls]
@Suor
Suor / jinjalink_loader.py
Created May 14, 2011 12:08
Jinja2 template loader for django
@Suor
Suor / gist:876324
Created March 18, 2011 15:59
QuerySet which returns namedtuples
from itertools import imap
from collections import namedtuple
from django.db.models.query import QuerySet, ValuesQuerySet
class NamedTuplesQuerySet(ValuesQuerySet):
def iterator(self):
# Purge any extra columns that haven't been explicitly asked for
extra_names = self.query.extra_select.keys()
@Suor
Suor / mutating_querysets.py
Created March 16, 2011 07:27
Django: mutating querysets
# THIS VERSION IS OUTDATED
# see .inplace(), .cloning(), ._clone() and .clone() methods of QuerySetMixin
# in https://github.com/Suor/django-cacheops/blob/master/cacheops/query.py
from django.conf import settings
from django.db.models import Model, Manager
MUTATING_QUERYSETS = getattr(settings, 'MUTATING_QUERYSETS', False)
class QuerySetMixin(object):
def __init__(self, *args, **kwargs):