Skip to content

Instantly share code, notes, and snippets.

View glebcha's full-sized avatar
👨‍💻
do my best

Gleb glebcha

👨‍💻
do my best
View GitHub Profile
@glebcha
glebcha / parse JSON.js
Last active August 29, 2015 13:56
Parse JSON array and create multi-dimensional array
var jsonObj = [{"forget":"me","leave":"alone"}, {"take":"them", "not":"him"}];
var arr = [];
for(var i = 0; i < jsonObj.length; i++) {
var val = jsonObj[i];
var def = Object.keys(val);
//console.log("all keys: " + def);
for(var j = 0; j < def.length; j++) {
arr.push([ def[j], val[def[j]] ]);
@glebcha
glebcha / words array.js
Created February 5, 2014 08:48
Get array from string with words separated with comma
var text = "one, two";
var text1 = text.split(",");
Array.prototype.slice.call(text1).map(function(item) {
return item.replace(" ", "");
});
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/query.php
*/
$args = array(
@glebcha
glebcha / gulpfile.js
Created November 25, 2014 05:19
Запуск модульных тестов для PHP в Gulp
//Запуск модульных тестов при изменении какого-либо php-файла в проекте
var phpunit = require('gulp-phpunit');
var gulp = require('gulp'),
notify = require('gulp-notify'),
phpunit = require('gulp-phpunit');
gulp.task('phpunit', function() {
var options = {debug: false, notify: true};
@glebcha
glebcha / xmlToJson
Last active August 29, 2015 14:21 — forked from feedmypixel/xmlToJson
/**
* Originally from http://davidwalsh.name/convert-xml-json
* This is a version that provides a JSON object without the attributes and places textNodes as values
* rather than an object with the textNode in it.
* 27/11/2012
* Ben Chidgey
*
* @param xml
* @return {*}
*/
@glebcha
glebcha / list_cookies
Created August 30, 2013 10:42
List all cookies for domain in list
function listCookies() {
var theCookies = document.cookie.split(';');
var aString = '';
for (var i = 1 ; i <= theCookies.length; i++) {
aString += i + ' ' + theCookies[i-1] + "\n";
}
return aString;
}
@glebcha
glebcha / domSelector.js
Created September 16, 2013 07:08
jQuery-like vanilla.js selector
function $$(selector){
return Array.prototype.slice.call(document.querySelectorAll(selector), 0);
}
$$('div').length
var arr = [];
var testValues = function(value) {
return /keyword_here/.test(value);
};
var addPrefix = function(value) {
return 'prefix '+value;
};
function do_smth_with_arguments(/* lots of arguments here */){
var args = Array.prototype.reverse.call(arguments);//call array method whatever you like
for(var i=0; i<args.length; i++){
alert(args[i]);//do whatever you want with each argument passed
}
};
do_smth_with_arguments.apply(null, ['one','two','three']);//null points to 'this' context
@glebcha
glebcha / thumb-popup.js
Created November 27, 2013 04:22
Simple full-size preview popup.
var thumbModal = function (thumbs, fullImgContainer) {
for (var i = 0; i < thumbs.length; i++) {
var thumb = thumbs[i];
var show = function (event) {
event.preventDefault();
var imgBlock = this.querySelector(fullImgContainer);
if (imgBlock.style.display != 'block') {
$(fullImgContainer).hide();
$(imgBlock).fadeIn(500);
} else {