Skip to content

Instantly share code, notes, and snippets.

@disnet
disnet / let_async.js
Last active December 31, 2015 04:28
sweet.js: async macro
let let = macro {
rule { async $vars ... = $fname ... ($params ...); $rest ...} => {
$fname ... ($params ..., function (err, $vars ...) {
if (err) throw err;
$rest ...
})
}
}
var buffer = new Buffer(1024);
@Ivanca
Ivanca / gist:4264971
Created December 12, 2012 04:57
Drag and drop functionality for "requirements.txt" files for http://python3wos.appspot.com/ Tested in latest Google Chrome and Firefox-
(function(){
document.addEventListener("drop", function( e ) {
e.preventDefault();
var blob = e.dataTransfer.files[0].slice();
var binaryReader = new FileReader();
$('.req').removeClass('.req');
binaryReader.addEventListener("load", function( file ) {
var notFound = '';
file.target.result.trim().replace(/==.*/g,'').split(/\n/).forEach(function(pack){
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@newhouseb
newhouseb / gist:1620133
Created January 16, 2012 10:20
MySQL vs PostgreSQL Schema changes benchmarks
The basic idea here is to substantiate the claims made by this square post:
http://corner.squareup.com/2011/06/postgresql-data-is-important.html
In PostgreSQL, and MySQL (MyISAM and InnoDB) I create millions of rows and then add
and remove columns and add and remove indexes. For columns without defaults this is
basically free in PostgreSQL and O(n) in MySQL. For adding indexes its at best O(n)
everywhere, but with PostgreSQL it claims not to do any locking that would otherwise
prevent table interaction.
Also, PostgreSQL has _awsome_ documentation (it has real examples!). I always get
@pydanny
pydanny / field.html
Created November 8, 2011 16:33
django-uni-form + Twitter Bootstrap
<!-- this usually goes in <project-root>/templates/uni_form/field.html -->
{% if field.is_hidden %}
{{ field }}
{% else %}
<div class="clearfix {% if field.errors %}error{% endif %}">
<label for="{{ field.auto_id }}" {% if field.field.required %}class="requiredField"{% endif %}>
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
<div class="input">
@wesbos
wesbos / log.coffee
Created August 31, 2011 18:22
log - Coffeescript version of Paul Irish's log() Wrapper
# Based on http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
# Converter to coffeescript by Wes Bos - http://wesbos.com
window.log = ->
log.history = log.history or []
log.history.push arguments
console.log Array::slice.call arguments if @console
return
anonymous
anonymous / bootstrap.sh
Created June 2, 2011 17:19
Django on Heroku with Celery and Sentry
virtualenv --no-site-packages .
source bin/activate
bin/pip install Django psycopg2 django-sentry
bin/pip freeze > requirements.txt
bin/django-admin.py startproject mysite
cat >.gitignore <<EOF
bin/
include/
lib/
EOF
@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
@JasonGiedymin
JasonGiedymin / Advanced Django 1.3.x+ Logging
Created March 25, 2011 18:47
A Django 1.3.x+ settings.py snippet with Advanced logging formatters using RFC 2822, TimedRotatingFileHandler, and a WatchedFileHandler.
#
# Advanced Django 1.3.x+ Logging
#
# Author:
# Jason Giedymin < jasong _[_a-t_]_ apache d-o-t org >
#
# Description:
# A Django 1.3.x+ settings.py snippet with Advanced logging formatters using RFC 2822,
# TimedRotatingFileHandler, and a WatchedFileHandler.
#
'''Manager-based polymorphic model inheritance.
This module provides a non-intrusive approach for accessing polymorphically
instances of a model hierarchy. Non-intrusive means:
- It does not require extending a custom ``Model`` base class or metaclass.
- It does not require a ``ForeignKey`` to ``ContentType`` or the ``contenttypes``
app in general. Instead the real class of an instance is determined based on
the value (**polymorphic identity**) of a user-specified discriminating field
(**polymorphic on**).
- It does not override the default (or any other) model ``Manager`` (unless