Skip to content

Instantly share code, notes, and snippets.

@ProximaMonkey
ProximaMonkey / forms.html
Created April 13, 2012 07:33 — forked from gnunicorn/forms.html
Jinja2 WTForms macros for twitter bootstrap
{%- macro form_field_label(field) -%}
<label for="{{ field.id }}">{{ field.label.text }}
{%- if field.flags.required -%}
<abbr title="Diese Feld muss angegeben werden">*</abbr>
{%- endif %}</label>
{% endmacro %}
{%- macro form_field_description(field) -%}
{% if field.description %}
<span class="descr">{{ field.description }}</span>
@ProximaMonkey
ProximaMonkey / ses.py
Created April 13, 2012 07:33 — forked from fanzeyi/ses.py
session for tornado
import os
import uuid
import marshal
import binascii
import tornado.web
def Session(func):
def warpper(self, *args, **kwargs):
@ProximaMonkey
ProximaMonkey / tornado_static.py
Created April 13, 2012 07:31 — forked from peterbe/tornado_static.py
tornado_static
"""
tornado_static is a module for displaying static resources in a Tornado web
application.
It can take care of merging, compressing and giving URLs ideal renamings
suitable for aggressive HTTP caching.
(c) [email protected]
"""
# NOTE: This code was extracted from a larger class and has not been
# tested in this form. Caveat emptor.
import django.conf
import django.contrib.auth
import django.core.handlers.wsgi
import django.db
import django.utils.importlib
import httplib
import json
import logging
@ProximaMonkey
ProximaMonkey / gist:2336255
Created April 8, 2012 09:30 — forked from huacnlee/gist:1150933
redis-search 0.3 Benchmark, 用户昵称搜索(10个字以内)
redis-search 0.3 Benchmark
Core 2 Duo CPU 2.66G, 4G Memory
20W 数据
# coding: utf-8
require "benchmark"
["的","美丽","云","云儿","花","云儿的"].each do |key|
@ProximaMonkey
ProximaMonkey / result_collector.py
Created April 7, 2012 21:39 — forked from bdarnell/result_collector.py
result_collector.py
import functools
import logging
import sys
class ResultCollector(object):
'''Like a BarrierCallback, but saves results passed to the callback.
>>> rc = ResultCollector()
>>> cb_foo = rc.get_callback('foo')
>>> cb_bar = rc.get_callback('bar')
@ProximaMonkey
ProximaMonkey / dropboxmixin.py
Created April 7, 2012 21:38 — forked from adam-stokes/dropboxmixin.py
Tornado Dropbox oauth mixin
class DropboxMixin(tornado.auth.OAuthMixin):
""" Dropbox OAuth authentication.
"""
_OAUTH_REQUEST_TOKEN_URL = "https://api.dropbox.com/1/oauth/request_token"
_OAUTH_ACCESS_TOKEN_URL = "https://api.dropbox.com/1/oauth/access_token"
_OAUTH_AUTHORIZE_URL = "https://www.dropbox.com/1/oauth/authorize"
_OAUTH_VERSION = "1.0"
_OAUTH_NO_CALLBACKS = False
def authorize_redirect(self, callback_uri=None, extra_params=None,
@ProximaMonkey
ProximaMonkey / jquery.imagesloaded.js
Created April 6, 2012 07:09 — forked from desandro/jquery.imagesloaded.js
$.fn.imagesLoaded jQuery plugin
// $('img.photo',this).imagesLoaded(myFunction)
// execute a callback when all images have loaded.
// needed because .load() doesn't work on cached images
// Modified with a two-pass approach to changing image
// src. First, the proxy imagedata is set, which leads
// to the first callback being triggered, which resets
// imagedata to the original src, which fires the final,
// user defined callback.

Redis + LibUV prototype README

Special thanks to Dušan Majkic (dmajkic, https://github.com/dmajkic/redis/) for his project on GitHub that gave us the opportunity to quickly learn some on the intricacies of Redis code. His project also helped us to build our prototype quickly.

Get source repository

First clone the Redis sources from https://github.com/antirez/redis.

  • On your computer create a working folder and cd into it.
  • Clone antirez/redis repository:
@ProximaMonkey
ProximaMonkey / Generate_a_url_slug.cs
Created March 13, 2012 15:57
Generate a url slug
private string ToSeoFriendly(string title, int maxLength) {
var match = Regex.Match(title.ToLower(), "[\\w]+");
StringBuilder result = new StringBuilder("");
bool maxLengthHit = false;
while (match.Success && !maxLengthHit) {
if (result.Length + match.Value.Length <= maxLength) {
result.Append(match.Value + "-");
} else {
maxLengthHit = true;
// Handle a situation where there is only one word and it is greater than the max length.