Skip to content

Instantly share code, notes, and snippets.

View vansosnin's full-sized avatar
🎸
fall into the light

Ivan Sosnin vansosnin

🎸
fall into the light
View GitHub Profile
@vansosnin
vansosnin / clear_input_file.js
Created June 10, 2015 09:25
Clear input[type="file"]
var input = $("#control");
function something_happens() {
input.replaceWith(input.val('').clone(true));
};
@vansosnin
vansosnin / post_logging.php
Last active September 8, 2015 04:58
POST logging
<?php
if (isset($_POST) AND count($_POST)) {
ob_start();
print_r($_POST);
$output = ob_get_clean();
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
@vansosnin
vansosnin / explain.sql
Created June 18, 2015 05:23
So useful. Much wow.
EXPLAIN
@vansosnin
vansosnin / animate_hash.js
Last active August 29, 2015 14:23
Animated scroll plus hash in url
function filterPath(string) {
return string
.replace(/^\//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/\/$/,'');
}
var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement('html', 'body');
@vansosnin
vansosnin / php_xdebug.ini
Last active February 18, 2016 04:55
PHP config xdebug PHPStorm + OpenServer
[Xdebug]
zend_extension="%sprogdir%/modules/php/%phpdriver%/ext/php_xdebug.dll"
;xdebug.default_enable = 1
xdebug.auto_trace = 0
xdebug.collect_includes = 1
;xdebug.collect_params = 4
;xdebug.collect_return = 1
;xdebug.collect_assignments = 1
;xdebug.collect_vars = 1
xdebug.dump.REQUEST = *
@vansosnin
vansosnin / fixed_length_rand.php
Created August 12, 2015 04:24
Fixed length random number
<?php
function big_rand($len = 9)
{
$rand = '';
while (!(isset($rand[$len - 1]))) {
$rand .= mt_rand();
}
return substr($rand, 0, $len);
}
@vansosnin
vansosnin / mtm_insert.sql
Created August 27, 2015 17:03
Mass insert into many-to-many table
INSERT INTO users_orders(user_id, order_id) SELECT users.id, orders.id FROM baget JOIN orders
@vansosnin
vansosnin / multiple_columns_sort.sql
Created September 8, 2015 04:55
Sort by price products sorted by img.
SELECT * FROM prod ORDER BY IF(img,1,0) DESC, price DESC;
@vansosnin
vansosnin / clear_get.js
Last active March 27, 2016 16:28
Clear empty GET parameters
var $button = $('.js-filter-button');
$button.on('click', function(event) {
event.preventDefault();
var $this = $(this);
var $form = $this.closest('form');
var emptyTextBoxes = $form.find('input:text, input:radio, input:checkbox, select').filter(function() {
return this.value == "";
});
@vansosnin
vansosnin / seek_destroy_process.bat
Last active March 1, 2016 04:40
Find and kill process (windows)
netstat -o -n -a | findstr :8080 # find process on port 8080
taskkill /f /PID 666 # kill this process
taskkill /F /IM chrome.exe # kill all chrome processes