Skip to content

Instantly share code, notes, and snippets.

@ErDmKo
ErDmKo / jar unpacker
Last active December 17, 2015 22:49
Decompile all *.class files into *.java recursively by JAva Decompiler(JAD). For windows.
@Echo Off
For /R %%F In (*.class) Do (
jad %%F
ren %CD%\%%~nF.jad %%~nF.java
move %CD%\%%~nF.java %%~dpF
)
@ErDmKo
ErDmKo / pagination.html
Last active December 18, 2015 22:49
Pages for django queryset's.
{% if pages|length > 1 %}
<ul class="page_list">
{% if sel_page > first_rand %}
<li><a href="{{ object.get_absolute_url }}{{ get_str }}&page=1">1</a><span>...</span></li>
{% endif %}
{% for page in pages %}
<li><a href="{{ object.get_absolute_url }}{{ get_str }}&page={{ page }}"{% if page == sel_page %} class="sel"{% endif %}>{{ page }}</a></li>
{% endfor %}
{% if sel_page <= last_rand %}
<li><span>...</span> <a href="{{ object.get_absolute_url }}{{ get_str }}&page={{ last }}">{{ last }}</a></li>
@ErDmKo
ErDmKo / alibaba.sql
Last active December 19, 2015 08:49
move my db
insert into orders_useradr
select
NULL as id,
p.user_id as user_id,
p.city as adr
from
orders_userprofile as p;
update
orders_userprofile,
#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)
@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);
};
@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 / 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 / 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 / >Exp MAX
Last active December 23, 2015 10:29
Exp max
y = MAX*(1-e^-x)
@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())