Skip to content

Instantly share code, notes, and snippets.

Avatar

Georgi Popov magadanskiuchen

View GitHub Profile
@magadanskiuchen
magadanskiuchen / wp-markdown-markdownify-updates.diff
Created Apr 10, 2016
Partial update to WP-MarkDown's Markdownify class to add support for GitHub flavor-like codeblocks
View wp-markdown-markdownify-updates.diff
diff --git a/markdownify/markdownify.php b/markdownify/markdownify.php
index e9b43bd..24ddac3 100644
--- a/markdownify/markdownify.php
+++ b/markdownify/markdownify.php
@@ -816,15 +816,39 @@ class Markdownify {
*/
public function handleTag_pre() {
if ($this->keepHTML && $this->parser->isStartTag) {
- # check if a simple <code> follows
- if (!preg_match('#^\s*<code\s*>#Us', $this->parser->html)) {
@magadanskiuchen
magadanskiuchen / post-merge.sh
Created Mar 21, 2015
A GIT post-merge hook to auto combine and minify all of your JavaScript files when merging a branch into "production"
View post-merge.sh
current_branch="$(git rev-parse --abbrev-ref HEAD)";
if [[ $current_branch == 'production' ]]; then
find js -name *.js | xargs cat > js/combined.js
curl -X POST -s --data-urlencode 'input@js/combined.js' http://javascript-minifier.com/raw > js/combined.min.js
rm js/combined.js
git commit -a -m "[automated] combined and minified JS"
@magadanskiuchen
magadanskiuchen / functions.js
Created Nov 16, 2014
semi-fixed-semi-scrolling (sidebar)
View functions.js
jQuery(function ($) {
var $win = $(window);
var $scrollPanel = $('#scrollPanel');
var windowTop = 0;
var lastDelta = 0;
var fixed = false;
$win.scroll(function (e) {
var newTop = $win.scrollTop();
var delta = newTop - windowTop;
View functions.js
function Slider() {
// private variables
var container = slider.addClass('js');
var ul = container.find('ul');
var lis = ul.find('li');
var btnNext = null;
var btnPrev = null;
var currentSlide = 0;
// public variables
@magadanskiuchen
magadanskiuchen / relevant-posts-query.sql
Last active Dec 20, 2015
Get related posts by number of shared terms (WordPress). Update {POST_ID} and {TAXONOMY_NAME}
View relevant-posts-query.sql
SELECT `posts`.`ID`, `posts`.`post_title`, COUNT(`posts`.`post_title`) AS `connections`
FROM `wp_posts` AS `posts`
INNER JOIN `wp_term_relationships` AS `term_rel` ON (`term_rel`.`object_id` = `posts`.`ID`)
INNER JOIN `wp_term_taxonomy` AS `term_tax` ON (`term_tax`.`term_taxonomy_id` = `term_rel`.`term_taxonomy_id`)
WHERE `term_rel`.`term_taxonomy_id` IN (
SELECT `term_rel`.`term_taxonomy_id`
FROM `wp_term_relationships` AS `term_rel`
WHERE `term_rel`.`object_id` = {POST_ID}
)
AND `term_tax`.`taxonomy` = '{TAXONOMY_NAME}'
@magadanskiuchen
magadanskiuchen / func.js
Last active Dec 15, 2015
Google+ Default Cover Photo Effect
View func.js
Array.prototype.shuffle = function () {
for (var i = this.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var tmp = this[i];
this[i] = this[j];
this[j] = tmp;
}
return this;
}
View gist:4671302
$('.form').submit(function() {
var valid = true;
var errors = '';
$(this).find('.required').each(function() {
if ($(this).val() == '') {
$(this).addClass('field-error');
errors += 'The "' + $(this).attr('title') + '" field is required\n';
if (valid) {
$(this).focus();
View gist:4250872
<?php
/*
Plugin Name: Theme Mobile Detector
Version: 1.0
*/
# Replace all occurrences of "theme" with your theme name
if (get_option('template') == 'theme') {
if (!session_id()) session_start();
@magadanskiuchen
magadanskiuchen / gist:4215541
Created Dec 5, 2012
Posts2Posts -- can't get connection title
View gist:4215541
<?php
global $post;
$connections = P2P_Connection_Type_Factory::get_all_instances();
if (!empty($connections)) {
foreach ($connections as $type => $conn) {
p2p_connection_box($type, $conn, $post);
}
}
@magadanskiuchen
magadanskiuchen / gist:4118565
Created Nov 20, 2012
Posts2Posts plugin p2p_query
View gist:4118565
// new WP_Query( array( 'p2p_query'=>array( array('p2p_type'=>'', 'direction'=>'') ) ) );
// set p2p_type to an existing registered p2p_type
// set direction to the direction for queries post type in the connection p2p_type
// this will return only items that have connections from the p2p_type
add_filter('posts_join', 'mu_p2p_join', 10, 2);
add_filter('posts_where', 'my_p2p_where', 10, 2);
function my_p2p_join($join, $query) {
if (isset($query->query_vars['p2p_query'])) {