Skip to content

Instantly share code, notes, and snippets.

View dkrnl's full-sized avatar

Dmitri Pyatkov dkrnl

View GitHub Profile
@dkrnl
dkrnl / gist:4ae798f457fde76eb245
Last active December 14, 2015 06:58
Jquery UI.Combobox via UI.Autocomplete
$.widget("ui.combobox", {
_create: function() {
var input,
self = this,
select = this.element.hide(),
selected = select.find(":selected"),
value = selected.val() ? selected.text() : "",
wrapper = this.wrapper = $("<span>").addClass("ui-combobox").insertAfter(select);
input = $("<input>")
.appendTo(wrapper)
@dkrnl
dkrnl / gist:95f9d1809368c3c3a07b
Last active March 2, 2020 09:57
Mysql Optimize Table InnoDB
#!/usr/bin/env php
<?php
$server = "localhost";
$username = "***";
$password = "****";
$connection = mysql_connect($server, $username, $password);
if (!$connection) {
die("Connection error: " . mysql_error());
@dkrnl
dkrnl / gist:e8b1e38a92c9900af225
Last active August 29, 2015 13:56
Track Javasctipt Errors via Google Analytics
{% if not debug %}
<script>
var _gaq = window._gaq || [];
window.onerror = function(msg, url, line) {
var preventErrorAlert = true;
_gaq.push(['_trackEvent', 'JS Error', msg, '#{{ employee.id|default:"0" }} ip:{{ request.META.REMOTE_ADDR|escapejs }} ua:{{ request.META.HTTP_USER_AGENT|escapejs }} url:' + url + " line:" + line, 0, true]);
return preventErrorAlert;
};
jQuery.error = function (message) {
_gaq.push(['_trackEvent', 'jQuery Error', message, '#{{ employee.id|default:"0" }} ip:{{ request.META.REMOTE_ADDR|escapejs }} ua:{{ request.META.HTTP_USER_AGENT|escapejs }}', 0, true]);
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',
@dkrnl
dkrnl / gist:d0080bbea47b05239fbe
Last active August 29, 2015 14:06
Jinja macros for Bootstrap Forms
{% macro form_open(form, action="", method="post", class="") -%}
<form role="form"{% if class %} class="{{ class }}"{% endif %}{% if action %} action="{{ action }}"{% endif %} method="{{ method|default("post") }}" {% if form.is_multipart() %}enctype="multipart/form-data" {% endif %}>
{%- for field in form.hidden_fields() -%}
{{ field|safe }}
{%- endfor -%}
{% endmacro %}
{% macro form_open_horizontal(form, action="", method="post") -%}
{{ form_open(form, action=action, method=method, class="form-horizontal") }}
@dkrnl
dkrnl / gist:dcde14462523ef8a30a2
Last active August 29, 2015 14:06
Django KLADR models
# _*_ coding: utf-8 _*_
# http://xn--80aiqe1a.xn--p1ai/kladr.html
from django.db import models
class KladrManager(models.Manager):
def filter_state(self, code=None, actual=True, queryset=None):
if queryset is None:
queryset = self.get_query_set()
queryset = queryset.extra(where=["code LIKE %s"], params=["%000000000__"])
@dkrnl
dkrnl / gist:c5cb5e3bac9486ab8831
Created February 8, 2015 10:36
django-pipeline + less + glue
import os
from django.conf import settings
from pipeline.compilers import SubProcessCompiler
class LessCompiler(SubProcessCompiler):
output_extension = "css"
def match_file(self, filename):
return filename.endswith(".less")
@dkrnl
dkrnl / selectize-optgroup_checkbox.js
Last active December 6, 2023 10:52
Selectize optgroup checkbox
/**
* Plugin: "optgroup_checkbox" (selectize.js)
* Copyright (c) 2015 Dmitri Piatkov & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
@dkrnl
dkrnl / gist:e1a24b7072ca60987477
Last active August 29, 2015 14:20
Jquery Clipboard Copyright
jQuery(function($){
$(document).on("copy", function () {
var selection, html = "";
if (window.getSelection || document.getSelection) {
selection = window.getSelection ? window.getSelection() : document.getSelection();
if (selection.rangeCount) {
html = document.createElement("div");
for (var i = 0, n = selection.rangeCount; i < n; ++i) {
html.appendChild(selection.getRangeAt(i).cloneContents());
@dkrnl
dkrnl / gist:9fdd1a93c9a83e889098
Created May 7, 2015 03:59
Input Password Type Toggle
<div class="input-group">
<input class="form-control" id="id_password" name="password" required="required" type="password" value="" />
<label class="input-group-addon" for="id_password" id="id_password_toggle">
<i class="fa fa-eye-slash"></i>
</label>
</div>
<script>
jQuery(function($) {
var input = $("#id_password");
$("#id_password_toggle").on("mousedown", function() {