Skip to content

Instantly share code, notes, and snippets.

View mikaelz's full-sized avatar

Michal Zuber mikaelz

View GitHub Profile
@mikaelz
mikaelz / vim-snippets
Last active December 17, 2015 16:58
VIM snippets, special searching and parsing
Search empty CSS selectors
/{\n\t\n}
Change filetype, syntax (htt, tpl, etc.)
:set ft=html.php
Delete every line in the file that does match a pattern
@mikaelz
mikaelz / jquery-autocomplete.js
Created May 26, 2013 13:32
jQuyer UI autocompletion with bold search term HTML: <form action="?" class="search" method="post"> <input type="text" name="search" id="q" value="Search for" /> <button type="submit">Search</button> </form>
(function ($) {
var cache = {},
q = $( '#q' );
qval = q.val();
q.focus(function() {
if(q.val() == qval) {
q.val('');
}
@mikaelz
mikaelz / snippets.sql
Last active December 17, 2015 18:29
sql snippets for mysql querying
-- select limited rows (paging) and left join additional data, http://stackoverflow.com/a/16767018/289404
SELECT t1.*, t2.*
FROM (SELECT * FROM table t WHERE t.id > 100 LIMIT 100) t1
LEFT JOIN table2 t2 ON t1.id = t2.id
ORDER BY t1.id DESC
-- select table column names
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name='table';
-- find duplicate
@mikaelz
mikaelz / my.cnf
Last active December 17, 2015 18:49
my.cnf - mysql config file
# MySQL config file
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
<?php
$pdo = new PDO("mysql:host=HOSTNAME", "USERNAME", "PASSWORD");
$query = $pdo->prepare("SHOW DATABASES");
$query->execute();
foreach ($query->fetchAll(PDO::FETCH_OBJ) as $row) {
$db = $row->Database;
echo "= $db =" . PHP_EOL;
$pdo->exec("USE $db");
@mikaelz
mikaelz / scrollTo.js
Last active December 17, 2015 19:29
jQuery animated scroll to defined id specified by hash from URL
/*
Additional info
http://stackoverflow.com/a/7717572/289404
http://stackoverflow.com/a/3379169/289404
*/
(function ($) {
if ( window.location.hash == '#reference' ) {
$('html, body').animate({
scrollTop: $( '#reference' ).offset().top
}, 1000);
@mikaelz
mikaelz / yepnope-snippet.js
Last active December 17, 2015 19:49
yepnope snippers https://github.com/SlexAxton/yepnope.js - an Asynchronous Conditional Resource Loader
yepnope([{
load: base_url + '/include/jquery/jquery.jqtransform.js',
complete: function () {
$('.jqtransform').jqTransform();
}
}, {
load: base_url + '/include/jquery/jquery.fileinput.js',
complete: function () {
$('#file').customFileInput();
}
@mikaelz
mikaelz / wp_secondary_loop.php
Created May 29, 2013 04:40
WordPress secondary loop
// video source http://wordpress.tv/2013/03/15/andrew-nacin-wp_query-wordpress-in-depth/
// presentation http://www.slideshare.net/andrewnacin/you-dont-know-query-wordcamp-netherlands-2012
$q = new WP_Query();
while ( $q->have_posts() ):
$q->the_post();
endwhile;
wp_reset_postdata();
// or in the template functions.php
<?php
require dirname(__FILE__) . '/functions.php';
$module = md5('MODULE_NAME');
$page_url = sanitize($_SERVER['PHP_SELF']);
if (isset($_POST['firstname']))
require dirname(__FILE__) . '/save.php';
<?php
/*
Plugin Name: R Debug
Description: Set of helper dump functions for debug.
Author: Andrey "Rarst" Savchenko
Author URI: http://www.rarst.net/
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/