This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand | |
from mymodule import main | |
import logging | |
class Command(BaseCommand): | |
help = 'Do foo' | |
def handle(self, *args, **options): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A (very) WIP collection of optimized/recommended jQuery plugin patterns | |
from @addyosmani, @cowboy, @ajpiano and others. | |
Disclaimer: | |
----------------------- | |
Whilst the end-goal of this gist is to provide a list of recommended patterns, this | |
is still very much a work-in-progress. I am not advocating the use of anything here | |
until we've had sufficient time to tweak and weed out what the most useful patterns |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import connection | |
# If using cursor without "with" -- it must be closed explicitly: | |
with connection.cursor() as cursor: | |
cursor.execute('select column1, column2, column3 from table where aaa=%s', [5]) | |
for row in cursor.fetchall(): | |
print row[0], row[1], row[3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Generic Dockerfile demonstrating good practices | |
### Imports | |
# Bad-ish, we do not need Ubuntu for this, nor do we want latest if we are using in a build system, predictable is better | |
FROM ubuntu:latest | |
# Better, using a small image since our app has no dependency on Ubuntu | |
FROM alpine:3.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env | |
# coding: utf-8 | |
import asyncio | |
import requests | |
import tornado.gen as gen | |
import tornado.httpclient as httpclient | |
import tornado.httpserver as httpserver | |
import tornado.options as options |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import tornado.web | |
class JsonHandler(BaseHandler): | |
"""Request handler where requests and responses speak JSON.""" | |
def prepare(self): | |
# Incorporate request JSON into arguments dictionary. | |
if self.request.body: | |
try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generatorID (len) { | |
return (Date.now().toString(36) + Math.random().toString(36).substr(2)) | |
.split("").reverse().join("").substr(0, len || 10) | |
.toUpperCase(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Case 1:. | |
// https://github.com/select2/select2/issues/1246#issuecomment-71710835 | |
// https://stackoverflow.com/questions/19787982/select2-plugin-and-jquery-ui-modal-dialogs/32099212#32099212 | |
// For select2 v4.+ | |
(function ($) { | |
if ($.ui && $.ui.dialog && $.ui.dialog.prototype._allowInteraction) { | |
var own_allowInteraction = $.ui.dialog.prototype._allowInteraction; | |
$.ui.dialog.prototype._allowInteraction = function (e) { | |
if ($(e.target).closest('.select2-dropdown').length) return true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($, undefined) { | |
//Plugin for navigationg | |
(function () { | |
'use strict'; | |
var PLUGIN_NAMESPACE = 'keys_control_table'; | |
var DEFAULT_LISTEN_INPUTS_SELECTOR = 'input'; | |
var DEFAULT_DEBOUNCE_TIME = 50; | |
var DEFAULT_CARET_MODE = true; | |
var DEFAULT_SELECT_AFTER_MOVE = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from weakref import WeakValueDictionary | |
METHOD_GET_INSTANCE = 'get_instance' | |
METHOD_REMOVE_INSTANCE = 'remove_instance' | |
METHOD_CLEAR_INSTANCE = 'clear_instance' | |
class MetaSingleton(type): | |
""" | |
Singleton metaclass | |
Based on Python Cookbook 3rd Edition Recipe 9.13 |