Skip to content

Instantly share code, notes, and snippets.

View daogurtsov's full-sized avatar

Dmitry Ogurtsov daogurtsov

View GitHub Profile
@daogurtsov
daogurtsov / mixin.js
Created December 8, 2013 21:31
javascipt basic mixin
Object.prototype.mixin = function(module) {
for (method in module.prototype) {
if (module.prototype.hasOwnProperty(method))
this.prototype[method] = module.prototype[method]
}
};
@daogurtsov
daogurtsov / xss.js
Created December 1, 2013 21:57
xss escaping and parsing html entities
var entityMap = {
"&": "&",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
};
var htmlMap = {
@daogurtsov
daogurtsov / Url Regex Validation.xml
Created September 29, 2013 11:37
URL regex validation
/^((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i
@daogurtsov
daogurtsov / formvalidation.php
Created July 24, 2013 15:47
/*Date validation, fixed regex for formats which use dash as separator: added $regexp = preg_replace('/(?<=(\]|\)))'.$separator.'(?=(\[|\())/i', "\\" . $separator, $regexp); to escape dash only between groups. Removed optional two digits year and one digit day or month to fit MySQL date format requirement */
function is_valid_date($value, $format = 'dd.mm.yyyy'){
if(strlen($value) >= 6 && strlen($format) == 10){
// find separator. Remove all other characters from $format
$separator_only = str_replace(array('m','d','y'),'', $format);
$separator = $separator_only[0]; // separator is first character
if($separator && strlen($separator_only) == 2){
// make regex
$regexp = str_replace('mm', '(0[1-9]|1[0-2])', $format);
@daogurtsov
daogurtsov / placeholder.scss
Created May 24, 2013 21:19
SCSS placeholder mixin
@mixin placeholder{
&.placeholder { @content }
&:-moz-placeholder { @content }
&::-moz-placeholder { @content }
&::-webkit-input-placeholder { @content }
&:-ms-input-placeholder{ @content }
}
@daogurtsov
daogurtsov / AsyncronusGroupTesting.html
Last active December 17, 2015 12:29
Asyncronus group testing by John Riseg from JavaSript Ninja
<html>
<head>
<title>Test Suite</title>
<script>
(function() {
var queue = [], paused = false, results;
this.test = function(name, fn) {
queue.push(function() {
results = document.getElementById("results");
results = assert(true, name).appendChild(
@daogurtsov
daogurtsov / SimpleGroupAssertion.html
Last active December 17, 2015 12:19
JS assertion function with grouping by John Resig from JavaScript Ninja
<html>
<head>
<title>Test Suite</title>
</head>
<body>
<script>
(function () {
var results = document.createElement("ul");
results.id = "results";
var html = results.outerHTML;
@daogurtsov
daogurtsov / gist:3677347
Created September 8, 2012 17:14
apache virtual hosts server configurating from import file, i use only first var in while, all others use in other scripts
#!/bin/sh
#log file for settings done
log=logs/log_apache_settings.txt
#path to sites config settings file
sitesConfigSettingsPath=domains.txt
#destination directory - the only path that you
# have to change from hosting to hosting
path=test
#apache settings file path
apache_path=C:/wamp/bin/apache/Apache2.2.21/conf/extra/httpd-vhosts.conf
@daogurtsov
daogurtsov / wp create databases
Created July 20, 2012 09:12
wp create databases
#!/bin/sh
#Start vars declaration
#default domains.txt format used as input file:
#domain_name database_name user_name password hosting_url
dbList=domains.txt
createLog=logs/create_log.txt
rootUser="root"
rootPass="win7"
#on some vds set user@"%"
rootHost="localhost"
@daogurtsov
daogurtsov / gist:2927219
Created June 13, 2012 23:57
Drop databases
#!/bin/sh
#Start vars declaration
dbList=domains.txt
dropLog=droplog.txt
#End vars declaration
if [ -f "$dbList" ]; then
if [ -f "$dropLog" ]; then
rm "$dropLog"
fi
touch "$dropLog"