Skip to content

Instantly share code, notes, and snippets.

@rockymeza
rockymeza / uwsgi_params
Created February 27, 2014 09:07
nginx + Django configs
# /etc/nginx/uwsgi_params
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
@rockymeza
rockymeza / keybase.md
Created January 22, 2015 12:08
Keybase Proof

Keybase proof

I hereby claim:

  • I am rockymeza on github.
  • I am rockymeza (https://keybase.io/rockymeza) on keybase.
  • I have a public key whose fingerprint is 88B0 84DA 0420 C198 E6AA C889 37C5 522F 1DED 379A

To claim this, I am signing this object:

@rockymeza
rockymeza / makeDecorator.js
Created May 13, 2015 16:00
A function decorator to make function decorators
// Based on idea from @nolsto
function makeDecorator(decorator) {
return function(target, key, descriptor) {
if (typeof descriptor !== 'undefined') {
descriptor.value = decorator(descriptor.value);
return descriptor
} else {
return decorator(target);
}
@rockymeza
rockymeza / gist:1244432
Created September 27, 2011 05:53 — forked from gavinwahl/gist:1244417
relation algebra
function Relation(schema, data)
{
this.schema = schema;
this.data = data;
// only supports equals for now
this.s = function(attribute, value) {
var index = this.schema.indexOf(attribute);
var new_data = this.data.filter(function(datum) {
return datum[index] == value;
@rockymeza
rockymeza / input_histogram.c
Created December 29, 2011 18:12
histogram of character frequencies
#include <stdio.h>
#include <limits.h>
#define CHAR_MIN_OFFSET CHAR_MIN - CHAR_MIN
#define CHAR_MAX_OFFSET UCHAR_MAX - CHAR_MIN
main()
{
int i, count[CHAR_MAX_OFFSET];
char c;
@rockymeza
rockymeza / gist:2986238
Created June 25, 2012 03:03
backslash in LaTeX
\usepackage{xspace}
\newcommand\bs{{\textbackslash}\xspace}
%% in content later on
``Look at her, a prisoner of the gutter \bs condemned by every syllable she utters''
@rockymeza
rockymeza / chain_defaults.py
Created May 14, 2013 16:22
Chain |default in django
>>> from django.template import Template, Context
>>> Template('{{ foo|default:bar|default:"test" }}').render(Context({'bar': 1}))
u'1'
>>> Template('{{ foo|default:bar.baz|default:"test" }}').render(Context({'bar': 1}))
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/XXX/site-packages/django/template/base.py", line 140, in render
return self._render(context)
File "/XXX/site-packages/django/template/base.py", line 134, in _render
return self.nodelist.render(context)
@rockymeza
rockymeza / backupmodel.py
Created July 23, 2013 22:30
Takes a model class and backs up all of the rows in a JSON file.
from django.conf import settings
from django.core.serializers import serialize
def backupmodel(model_class):
"""
Takes a model class and backs up all of the rows in a JSON file.
"""
log.info("Backing up %s", model_class)
#!/usr/bin/env python
"""
A command to check redirects.
Expects stdin in to look like this:
http://example.com/old-url,http://example.com/new-url
Outputs to stderr:
@rockymeza
rockymeza / gist:6176247
Created August 7, 2013 17:19
vimium memory consumption over time.
2013-08-07 08:36 enabled
2013-08-07 08:36 12,992
2013-08-07 08:36 16,836
2013-08-07 08:37 19,888
2013-08-07 08:37 22,680
2013-08-07 08:39 24,556
2013-08-07 10:07 188,036
2013-08-07 10:12 195,804
2013-08-07 10:34 225,264
2013-08-07 11:18 297,664