Skip to content

Instantly share code, notes, and snippets.

View Walkeryr's full-sized avatar

Yuriy Khamzyaev Walkeryr

View GitHub Profile
# Django settings for stackoverflow project.
from os.path import abspath, dirname, join
PROJECT_ROOT = abspath(dirname(dirname(__file__)))
root = lambda *args: join(abspath(PROJECT_ROOT), *args)
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
@Walkeryr
Walkeryr / resize.sh
Created October 2, 2013 08:36
Resize and move images with Imagemagick with convert command
for name in `ls *.jpg`
do
convert -resize 930x $name ../Images-small/$name
done
@Walkeryr
Walkeryr / gist:6790762
Created October 2, 2013 08:38
Rename files by removing specified substring
find . -name "*.jpg" -print |sed 's/\(.*\)-big\(.*\)/mv & \1\2/' | sh
@Walkeryr
Walkeryr / gist:6851422
Created October 6, 2013 08:56
Hotlink protection in Nginx for fonts
location ~ \.(eot|svg|ttf|woff|otf)$ {
valid_referers blocked mysite.com *.mysite.com;
if ($invalid_referer) {
return 403;
}
}
@Walkeryr
Walkeryr / gist:7021910
Created October 17, 2013 09:30
Create Django fixture for single models
python manage.py dumpdata --indent 2 content.PageType content.ColumnType content.BlockType > initial_data.json
@Walkeryr
Walkeryr / gist:7211945
Last active December 26, 2015 20:49
Mercurial commands
# change commit message after commit
hg commit --amend
# undo add before commit
hg revert [file_name|directory_name]
# create new branch
hg branch new-branch-name
# push new branch to remote
@Walkeryr
Walkeryr / proc_filenames.py
Created October 31, 2013 12:21
Script that converts filenames to strings with HTML tags
from os import listdir
from os.path import isfile, join
mypath = '.'
prepend = '<a href=""><img src="'
append = '"></a>'
onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
html_tags = [prepend + f + append for f in onlyfiles]
@Walkeryr
Walkeryr / gist:7748400
Last active December 30, 2015 00:19
Creating localization files in Django
# create directory to hold translation message files
mkdir locale/en/LC_MESSAGES/
# create messages
python manage.py makemessages -l en
# compile messages
python manage.py compilemessages
@Walkeryr
Walkeryr / gist:7941061
Last active December 31, 2015 05:29
MySQL main administration commands
-- Change password for user to specific database
-- Create database
create database mydb;
-- Select database
use mydb;
-- Create user
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
@Walkeryr
Walkeryr / baron_resize
Created October 13, 2014 07:00
Window resize event to resize baron scroller
attachResizeListener: function () {
$(window).on('resize', this.resizer.bind(this));
},
resizer: function () {
if (this.scroller !== undefined) {
this.scroller.dispose();
this.scroller = undefined;
}
var $wrapper = $('.wrapper');