Skip to content

Instantly share code, notes, and snippets.

View borkweb's full-sized avatar

Matthew Batchelder borkweb

View GitHub Profile
@borkweb
borkweb / formatting.php
Created October 28, 2013 19:15
SQL Formatting in PHP
$sql = "
SELECT
p.ID AS id,
p.post_title AS name
FROM
$wpdb->posts p
LEFT JOIN $wpdb->postmeta pm ON
p.ID = pm.post_id
AND pm.meta_key = %s
WHERE
(function() {
var CSSCriticalPath = function(w, d) {
var css = {};
var pushCSS = function(r) {
// The last selector wins, so over-write
// merging existing css will happen here...
css[r.selectorText] = r.cssText;
};
var parseTree = function() {
@borkweb
borkweb / migrate-subdirectory
Created May 24, 2013 13:50
Migrate a directory (with history) to a separate repo.
# First create the blank repository, then... git clone https://github.com/borkweb/whatever.git tmp-repo git clone --no-hardlinks tmp-repo new-repo cd new-repo git filter-branch --subdirectory-filter directory-to-migrate HEAD -- --all git reset --hard git gc --aggressive git prune git remote rm origin git remote add origin https://github.com/borkweb/new-repo.git git push origin master --force
@borkweb
borkweb / bitwise-truncation.php
Created May 7, 2013 12:34
Bitwise decimal truncation test
<?php
$data = 2.345;
echo ~~$data . "\n\n"; // spits out: 2
$data = 2.8;
echo ~~$data . "\n\n"; // spits out: 2
@borkweb
borkweb / memcache-flush.php
Created May 7, 2013 12:24
Super basic memcache flush script to drop on my dev servers.
<?php
$memcache = new Memcache;
$memcache->connect( 'localhost', 11211 );
if ( $memcache->flush() ) {
echo 'BOOM! Flushed!<br>';
} else {
echo 'Memcache Y U NO FLUSH?<br>';
}//end else