Skip to content

Instantly share code, notes, and snippets.

View dkrnl's full-sized avatar

Dmitri Pyatkov dkrnl

View GitHub Profile
@dkrnl
dkrnl / svn-backup.sh
Created August 16, 2016 05:04
Backup SVN repos
#!/usr/bin/env bash
cd /var/backups/svn
# backup svn folders
for i in `find /svn/* -type d -nowarn -maxdepth 0 -exec basename {} \;`;
do
svnadmin dump /svn/$i > /var/backups/svn/$i.$(date +%F).dump
done
@dkrnl
dkrnl / root-backup.sh
Created August 16, 2016 05:03
Backup root directory + tar gzip
#!/usr/bin/env bash
cd /var/backups/root
# backup root folders
tar -cvzf root.$(date +%F).tgz /bin/ /boot/ /etc/ /home/ /lib/ /lib64/ /opt/ /root/ /sbin/ /usr/
# remove older backups
find /var/backups/root -type f -name '*.tgz' -mtime +30 -delete
@dkrnl
dkrnl / svnindex.xsl
Created August 9, 2016 03:36
SVN XSL template via Bootstrap
<?xml version="1.0"?>
<!-- A sample XML transformation style sheet for displaying the Subversion
directory listing that is generated by mod_dav_svn when the "SVNIndexXSLT"
directive is used. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" omit-xml-declaration="yes"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
doctype-system="http://www.w3.org/TR/html4/loose.dtd" />
@dkrnl
dkrnl / resize-dir-images.sh
Last active April 28, 2016 10:38
ImageMagick Resize Images Directory
for X in *.jpg; do convert "$X" -resize "1920x1200>" -strip -quality 86 "$X"; done
@dkrnl
dkrnl / disk-usage-directory.sh
Created April 28, 2016 07:23
Disk usage directory list
du -s *|sort -nr|cut -f 2-|while read a;do du -hs $a;done
@dkrnl
dkrnl / mysql-optimize-innodb.sh
Created April 15, 2016 02:31
mysql optimize innodb
#!/bin/sh
set -x
for i in `mysql --batch --execute 'SELECT CONCAT("\`", REPLACE(table_schema, "\`", "\`\`"), "\`.\`", REPLACE(table_name, "\`", "\`\`"), "\`") as \`mysql.db\` FROM information_schema.tables where ENGINE="MyISAM" and table_schema!="information_schema"'`; do mysql --execute "OPTIMIZE NO_WRITE_TO_BINLOG table $i;"; done
for i in `mysql --batch --execute 'SELECT CONCAT("\`", REPLACE(table_schema, "\`", "\`\`"), "\`.\`", REPLACE(table_name, "\`", "\`\`"), "\`") as \`mysql.db\` FROM information_schema.tables where ENGINE="InnoDB" and table_schema!="information_schema"'`; do mysql --execute "ALTER TABLE $i ENGINE=InnoDB; ANALYZE NO_WRITE_TO_BINLOG TABLE $i;"; done
mysql --execute 'PURGE BINARY LOGS BEFORE NOW();'
mysql --execute 'FLUSH TABLES;'
@dkrnl
dkrnl / track-errors-google-analitics.js
Last active January 28, 2016 06:01
Track JS errors VIA Google Analitics
<script>
{% textstrip %}
var _gaq = window._gaq || [];
var trackError = function(msg, url, line, column, error, action) {
if (!(error !== undefined && error.stack)) {
error = function() { try { throw Error(msg) } catch(e) { return e; } }();
}
var report = (error !== undefined && error.stack ? String(error.stack).replace(/\n\s*/g, ' --> ') + ' message:' + msg : msg) + ' at ' + url + ':' + line + ':' + column + ' date:' + Date();
_gaq.push(['_trackEvent', action, report, '#{{ request.user.id|default:"0" }} ip:{{ request.META.REMOTE_ADDR|escapejs }} ua:' + window.navigator.userAgent + ' error:' + report, 0, true]);
if (typeof(console) != 'undefined') {
@dkrnl
dkrnl / x-grid-framework.less
Created December 18, 2015 04:15
Bootstrap: extra framework grid generation
// Extra framework grid generation
//
// Based on bootstrap/grid-framework.less
.x-make-grid-columns(@columns: @grid-columns, @gutter-width: @grid-gutter-width, @prefix: ".col") {
// Common styles for all sizes of grid columns, widths 1-12
.x-col(@index) { // initial
@item: ~"@{prefix}-xs-@{index}-of-@{columns}, @{prefix}-sm-@{index}-of-@{columns}, @{prefix}-md-@{index}-of-@{columns}, @{prefix}-lg-@{index}-of-@{columns}";
.x-col((@index + 1), @item);
}
@dkrnl
dkrnl / gridly.less
Last active December 15, 2015 02:44
Bootrsap 3 gridly
.make-columns(@name; @columns; @gutter-width: @grid-gutter-width) {
@class-lg: ~".col-lg-@{name}";
> @{class-lg} {
.make-lg-column((@grid-columns / @columns); @gutter-width);
}
@class-md: ~".col-md-@{name}";
> @{class-md} {
.make-md-column((@grid-columns / @columns); @gutter-width);
}
@class-sm: ~".col-sm-@{name}";
<?php
// SEEMORE: http://stackoverflow.com/questions/7620910/regexp-in-preg-match-function-returning-browser-error
var_dump(
preg_match('/\\G"((?:[^"\\\\\\r\\n]|\\\\.|\\\\\\r\\n|\\\\[\\n\\r\\f])*)"|\'((?:[^\'\\\\\\r\\n]|\\\\.|\\\\\\r\\n|\\\\[\\n\\r\\f])*)\'/','.foo {
bar: \'/00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\';
}', $match, 0, 12)
);
var_dump($match);