Skip to content

Instantly share code, notes, and snippets.

View wellic's full-sized avatar

Valerii Savchenko wellic

View GitHub Profile
@wellic
wellic / example_command.py
Last active December 11, 2017 12:17 — forked from epicserve/example_command.py
Example of how to setup logging for a Django management command.
from django.core.management.base import BaseCommand
from mymodule import main
import logging
class Command(BaseCommand):
help = 'Do foo'
def handle(self, *args, **options):
@wellic
wellic / jQueryPluginPatterns.js
Created December 19, 2017 12:47 — forked from addyosmani/jQueryPluginPatterns.js
jQuery Plugin Patterns
/*
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
@wellic
wellic / django_raw_sql_without_model.py
Last active December 26, 2017 08:23 — forked from tkrajina/django_raw_sql_without_model.py
Django raw sql without model
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]
@wellic
wellic / Dockerfile
Created July 12, 2018 13:59 — forked from Faheetah/Dockerfile
Docker patterns/anti-patterns
### 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
#!/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
@wellic
wellic / jsonhandler.py
Created September 3, 2018 15:18 — forked from mminer/jsonhandler.py
A JSON request handler for Tornado.
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:
function generatorID (len) {
return (Date.now().toString(36) + Math.random().toString(36).substr(2))
.split("").reverse().join("").substr(0, len || 10)
.toUpperCase();
}
@wellic
wellic / fix_ui_dialog_select2.js
Created September 26, 2019 13:14
Fix old jquery dialog with select2
//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;
@wellic
wellic / arrow-table.js
Created September 26, 2019 13:16
Add arrays key to table
(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;
@wellic
wellic / singleton.py
Last active November 29, 2019 12:40
Example python 3.6+ Singleton
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