Skip to content

Instantly share code, notes, and snippets.

@abackstrom
abackstrom / gist:1301756
Created Oct 20, 2011
Determine if a table exists (MySQL)
View gist:1301756

On a WordPress MU install that contains 21,511 tables.

Table does exist (DESCRIBE)

mysql@delphinus:~$ time printf "DESCRIBE wp_users ; %.0s" {1..100} | mysql -P 3308 wordpress -f &>/dev/null

real    0m0.094s
user    0m0.005s
sys     0m0.004s
@abackstrom
abackstrom / wordpress.dev.sql
Created Nov 18, 2011
Update WordPress Network URLs
View wordpress.dev.sql
UPDATE wp_blogs SET domain = 'www.example.dev';
UPDATE wp_site SET domain = REPLACE(domain, 'example.com', 'example.dev');
UPDATE wp_sitemeta SET meta_value = REPLACE(meta_value, 'example.com', 'example.dev') WHERE meta_key = 'siteurl';
UPDATE wp_domain_mapping SET meta_value = REPLACE(meta_value, 'example.com', 'example.dev');
DROP PROCEDURE IF EXISTS wploop;
DELIMITER $$
CREATE PROCEDURE wploop()
BEGIN
DECLARE done INT DEFAULT 0;
@abackstrom
abackstrom / functions.php
Created Jan 4, 2012
Support Markdown syntax in P2 posts and comments
View functions.php
<?php
// http://michelf.com/projects/php-markdown/extra/
require_once( dirname(__FILE__) . '/markdown-extra/markdown-extra.php' );
/**
* Format posts/comments with Markdown at display time. Only process
* blocks starting with \^md\s+.
**/
function p2mis_comment_markdown( $text ) {
@abackstrom
abackstrom / gist:1601019
Created Jan 12, 2012
P2 jQuery.animate() fixes: transparency and callback
View gist:1601019
Index: js/p2.js
===================================================================
--- js/p2.js (revision 8687)
+++ js/p2.js (working copy)
@@ -141,9 +141,10 @@
var cnt = newComment.contents();
newComment.children('li.newcomment').each(function() {
if (isElementVisible(this) && !showNotification) {
- $(this).animate({backgroundColor:'transparent'}, {duration: 1000}, function(){
- $(this).removeClass('newcomment');
@abackstrom
abackstrom / GitHub_URL.php
Created Jan 19, 2012
Fetch short URL using git.io
View GitHub_URL.php
<?php
class GitHub_URL {
protected $long;
public function __construct( $url ) {
$this->long = $url;
}
public function long() {
@abackstrom
abackstrom / .bashrc
Created Jan 24, 2012
Adam's Environment
View .bashrc
#
# adam's .bashrc file.
#
#
# See also:
#
# - [Subversion: Missing Features](http://sixohthree.com/972/subversion-missing-features)
# only run if we have an interactive shell.
@abackstrom
abackstrom / gist:1668119
Created Jan 24, 2012
wTerm launch fail
View gist:1668119
adam@fsck:~:0$ palm-log us.ryanhope.wterm -f
following logs for application us.ryanhope.wterm on device "topaz-linux" {d838c86b826af29b280165c5ec607572dc78bb7b} usb 60618
[20120124-00:10:16.732978] error: Not allowed to load local resource: file:///opt/PalmSDK/0.1/share/framework/enyo/1.0/framework/enyo.js
[20120124-00:10:16.737886] error: Uncaught ReferenceError: enyo is not defined, index.html:
@abackstrom
abackstrom / nginx
Created Jan 31, 2012
choo configuration
View nginx
./configure \
--prefix=/usr/local/server/nginx \
--conf-path=/usr/local/etc/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
View irc-log.js
#!/usr/bin/env node
/*
Send UDP packets to the daemon listening on port 8888,
and they will be echoed to the configured IRC channel:
echo "my hovercraft is full of eels" | nc -w1 -u 127.0.0.1 8888
create a config.js file in the same directory as this
@abackstrom
abackstrom / mu.sixohthree.com.conf
Created Mar 26, 2012
Nginx + php-fpm for WordPress Network
View mu.sixohthree.com.conf
server {
listen 69.164.216.5:80;
listen 69.164.216.5:443 default ssl;
server_name _;
ssl_certificate ssl/sixohthree.com.cert.pem;
ssl_certificate_key ssl/sixohthree.com.key.pem;
root /var/www/mu.sixohthree.com/html;