Skip to content

Instantly share code, notes, and snippets.

View micrypt's full-sized avatar

Seyi Ogunyemi micrypt

View GitHub Profile
anonymous
anonymous / gist:156623
Created July 27, 2009 16:41
"""
This fabric file makes setting up and deploying a django application much
easier, but it does make a few assumptions. Namely that you're using Git,
Apache and mod_wsgi and your using Debian or Ubuntu. Also you should have
Django installed on your local machine and SSH installed on both the local
machine and any servers you want to deploy to.
_note that I've used the name project_name throughout this example. Replace
this with whatever your project is called._
from django.core.cache import cache
from django.conf import settings
from django.contrib.auth.models import User
ONLINE_THRESHOLD = getattr(settings, 'ONLINE_THRESHOLD', 60 * 15)
ONLINE_MAX = getattr(settings, 'ONLINE_MAX', 50)
def get_online_now(self):
return User.objects.filter(id__in=self.online_now_ids or [])
from __future__ import with_statement
import inspect
class Test(object):
def __init__(self, name):
self.name = name
def __enter__(self):
return self
@eligrey
eligrey / strict-typing-examples.js
Created March 19, 2010 03:42
JavaScript Pseudo-Strict Typing
// assignment in function parameters
function sum1 ({Array: numbers}) {
let total = 0; // let {Number: total} = 0; would also be fine
let i = numbers.length;
while (i--) {
let {Number: n} = numbers[i];
total += n;
}
@remy
remy / gist:350433
Created March 31, 2010 14:58
Storage polyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
!function() {
var doc = document,
htm = doc.documentElement,
lct = null, // last click target
nearest = function(elm, tag) {
while (elm && elm.nodeName != tag) {
elm = elm.parentNode;
}
return elm;
};
import sbt._
class HelloworldProject(info: ProjectInfo) extends AppengineProject(info)
@stefanfoulis
stefanfoulis / search_indexes.py
Created May 4, 2010 08:08 — forked from beniwohli/search_indexes.py
fork with support for cms placeholders (upcoming cms 2.1 release)
from django.conf import settings
from django.utils.translation import string_concat, ugettext_lazy
from django.utils.html import strip_tags
from haystack import indexes, site
from cms.models.managers import PageManager
from cms.models.pagemodel import Page
from cms.models.pluginmodel import CMSPlugin
// In cases where we have an AJAX request for IE with an uploaded file, we
// assume we served through an iframe (a fairly safe assumption) and serve
// up the response with a content type of text/plain so that IE does not
// attempt to save the file.
LiftRules.responseTransformers.append {
resp =>
(for (req <- S.request) yield {
resp match {
case InMemoryResponse(data, headers, cookies, code)
if ! req.uploadedFiles.isEmpty &&

Some of you might wonder why I didn't just use one of the existing NoSQL datastores, so I've elaborated below on why they don't suit my needs. This is not to say that they won't be highly suited in other contexts -- especially since they're all quite impressive in their own ways.

Cassandra is promising, but:

  • It has no native transactions or secondary indexes.