Skip to content

Instantly share code, notes, and snippets.

@ErDmKo
ErDmKo / new_database
Last active July 20, 2018 11:42
Sql create new database and create user.
CREATE DATABASE <BDname> CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON <BDname>.* to <user_name>@localhost identified by '<user_password>';
for crone:
mysqldump -u <user_name> '-p<user_password>' <oldBDname> | gzip > ~/$(date +/var/sqlDump/<oldBDname>.sql.%Y%m%d.gz)
gunzip < `date +/var/sqlDump/<oldBDname>.sql.%Y%m%d.gz` | mysql -u <user_name> '-p<user_password>' <BDname>
CREATE USER <un> WITH PASSWORD '<up>';
CREATE DATABASE sales ENCODING 'utf8' OWNER <un>;
data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==
@ErDmKo
ErDmKo / row_numbers.py
Created October 22, 2013 16:00
Django extra row number column for mySQL ROW_NUMBER()
Obj.objects.extra(select={'num': "(select @f2 := @f2 +1 from (select @f2 := 0) as t )"})
@ErDmKo
ErDmKo / content_type.py
Created October 11, 2013 15:49
Python content_type get from django datebase field
import magic
with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m:
content_type = m.id_filename(self.file._get_path())
@ErDmKo
ErDmKo / >Exp MAX
Last active December 23, 2015 10:29
Exp max
y = MAX*(1-e^-x)
@ErDmKo
ErDmKo / scheme.js
Created September 3, 2013 08:15
Jquery plugin that will breathe new life into the Html tag <map>
;(function($)
{
var jqPluginName = 'scheme',
Init = function(element, options)
{
var config = $.extend(true, {}, $.fn[jqPluginName].defaults, options),
self = this,
cats_counter = [],
create_cav = function()
{
@ErDmKo
ErDmKo / nginx.conf
Last active December 21, 2015 23:19
nginx server conf and uwsgi for django project
server {
listen 80;
server_name www.<domain>;
return 301 $scheme://<domain>$request_uri;
}
server {
listen 80;
server_name localhost <ip> <domain>;
location ~* ^.+\.(xml|html|txt|png|jpg|gif|ico)$ {
@ErDmKo
ErDmKo / redirect.py
Last active December 20, 2015 06:59
www redirect
if request.get_host().split(".")[0] == 'www':
return HttpResponseRedirect((request.is_secure() and "https" or "http")+ "://"+".".join(request.build_absolute_uri().split(".")[1:]))
server {
listen 80;
server_name www.dom.ru;
return 301 $scheme://dom.ru$request_uri;
}
server {
@ErDmKo
ErDmKo / scaleKepper.js
Last active December 20, 2015 00:49
A simple example of the function of maintaining the scale and position of the image window is resized.
var scaleKepper = function(e){
var obj = $(/*selector*/)[0],
windowWidth = $(window).innerWidth(),
windowHeight = $(window).innerHeight(),
aspect = obj.clientWidth/obj.clientHeight,
result = windowWidth/aspect > windowHeight ?
'width:'+windowWidth+"px;height:"+windowWidth/aspect+"px;margin-top:-"+((obj.clientHeight-windowHeight)/2)+"px;" :
'width:'+windowHeight*aspect+'px;height:'+windowHeight+'px;margin-left:-'+((obj.clientWidth-windowWidth)/2)+'px';
obj.setAttribute('style', result);
};
#server
def socketer(s, ...):
s.bind(...)
s.listen(10)
while 1:
conn, addr = s.accept()
out = (....).encode('zlib')
out = str(len(out))+"data_length"+out
conn.sendall(out)