Skip to content

Instantly share code, notes, and snippets.

View mbijon's full-sized avatar
🎯
Focusing

Mike Bijon mbijon

🎯
Focusing
View GitHub Profile
@mbijon
mbijon / meta-regex-formatting.php
Created April 21, 2013 21:37
Improving Regex readability in PHP: In a very meta twist, you can build a multiline, indented regular expression and then use a regular expression to condense it before being parsed: (posted: http://www.mbijon.com/regex-your-regex-much/)
// match first <p><a><img class="size-large wp-image-[0-9]+"></a>
// special cases spotted in the wild:
// - content prepended by <p>&nbsp;</p>, we can take care of this one easy
// - misplaced wrappers eg <p>&nbsp;<a><img></a>blah blah blah<p>, well try to
handle this in the filter function
// - misc whitespace all over, lets get sloppy
// - no link wrapping the image, we'll try to handle this
// - some posts are stuck in the db without a class on the images, luckily it
should still be present in the rel on the wrapping anchor
// match guide: [0]match [1]p a? img /a? [2]a? [3]img [4]img.class
@mbijon
mbijon / quiet-startups.vbs
Created April 22, 2013 17:49
Quiet startup scripts in Windows: WHY? Startup scripts can be a pain when using Windows with many open source dev tools. You're forced to run the GUI ... and end up with console wondiws cluttering the desktop. HOW? Add this VBS script to your Windows startup. Regex is best, but worst case add a shortcut to the Start Menu > Programs > Startup. Th…
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\srv\apache24\startup.bat" & Chr(34), 0
WshShell.Run chr(34) & "C:\srv\redis\quiet-start.bat" & Chr(34), 0
WshShell.Run chr(34) & "C:\tmp\misc.bat" & Chr(34), 0
Set WshShell = Nothing
# Go to plugins/jetpack/jetpack.php into the folder of your WP local website.
# Find the line (276) below:
/**
* Is Jetpack active?
*/
public static function is_active() {
return (bool) Jetpack_Data::get_access_token( JETPACK_MASTER_USER );
}
@mbijon
mbijon / class-twitter.php
Created May 16, 2013 23:26
Dear Yoast, There's a big gap in how the Open Graph og:image and/or Twitter:image tags are generated in the WordPress SEO plugin. A description of the problem and a fix is in the following gist. A FIX: See the gist below. The first version is the WP SEO 1.4.7 code, second version is my [not exhaustively tested] code. In my newer version the Twit…
<?php
/**
* @package Frontend
*/
if ( !defined('WPSEO_VERSION') ) {
header('HTTP/1.0 403 Forbidden');
die;
}

#Create bitbucket branch

##Create local branch

$ git checkout -b sync
Switched to a new branch 'sync'
$ git branch
  master
* sync
<?php
// Confusion Matrix Init
$tp = 0;
$fp = 0;
$fn = 0;
$tn = 0;
$arrFP = array();
$arrFN = array();
@mbijon
mbijon / gist:6227125
Created August 14, 2013 00:54
Algorithm to maximize photo sizes in a row-based gallery grid (for comparison, Pinterest is "column-based") --From: Chromatic, http://www.crispymtn.com/stories/the-algorithm-for-a-perfectly-balanced-photo-gallery
viewport_width = $(window).width()
ideal_height = parseInt($(window).height() / 2)
summed_width = photos.reduce ((sum, p) -> sum += p.get('aspect_ratio') * ideal_height), 0
rows = Math.round(summed_width / viewport_width)
if rows < 1
# (2a) Fallback to just standard size
photos.each (photo) -> photo.view.resize parseInt(ideal_height * photo.get('aspect_ratio')), ideal_height
else
# (2b) Distribute photos over rows using the aspect ratio as weight
SCARF stands for status, certainty, autonomy, relatedness, and fairness. “Basically, when a person is honest with themselves, they’re most motivated by one of those qualities,” Stirman explains. “As a manager, you can figure out which one motivates which employee, and reward them accordingly. A lot of managers will look at their team and think, ‘We should do a round of compensation increases because everyone’s been working so hard,’ but this isn’t the best incentive for everyone.” Here’s how it looks:
Status-oriented employees can be motivated by a possible title change, or having their name attached to more important projects.
Certainty-oriented employees are motivated simply by the reassurance that their job is important and they are excelling.
Autonomy-oriented employees may need the ability to work from home, or simply slip on their head phones to tune everyone else out.
Relatedness-oriented employees are energized by opportunities to socialize with their coworkers – happy hours, softball games, etc.
Fai
/**
* $.parseParams - parse query string paramaters into an object.
*/
(function($) {
var re = /([^&=]+)=?([^&]*)/g;
var decodeRE = /\+/g; // Regex for replacing addition symbol with a space
var decode = function (str) {return decodeURIComponent( str.replace(decodeRE, " ") );};
$.parseParams = function(query) {
var params = {}, e;
while ( e = re.exec(query) ) {
<?php
/*
* Example code showing how to hook WordPress to add fields to the taxonomny term edit screen.
*
* This example is meant to show how, not to be a drop in example.
*
* This example was written in response to this question:
*
* http://lists.automattic.com/pipermail/wp-hackers/2010-August/033671.html
*