Skip to content

Instantly share code, notes, and snippets.

@xdissent
xdissent / WordPress word count for all posts.
Created October 2, 2009 02:26
SQL to get the WordPress word count for all posts.
SELECT SUM(LENGTH(post_content) - LENGTH(REPLACE(post_content, ' ', '')) + 1) as 'Word Count' FROM `wp_posts` WHERE post_status='publish' AND post_type='post';
@xdissent
xdissent / jcroft regex
Created February 19, 2010 01:04
Regex to convert "Last, First" to "First Last"
s/([^,]+),\s+(.*)/\2 \1/
@xdissent
xdissent / thesis-span-logo-words.php
Created February 19, 2010 23:55
Wrap logo words in spans for Thesis WordPress theme.
<?php
// Override default header.
function custom_default_header() {
// Get the default header.
ob_start();
thesis_default_header();
$output = ob_get_clean();
@xdissent
xdissent / parametize_links.php
Created March 3, 2010 23:11
Add GET params to links in HTML.
@xdissent
xdissent / doctrine.php
Created March 19, 2010 14:25
Doctrine CLI script for Zend Server CE on Snow Leopard
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
@xdissent
xdissent / flac_batch.sh
Created March 26, 2010 23:52
Batch convert FLAC audio files to WAV
mkdir -p wav && for a in *.flac; do flac -d -o "wav/`basename -s .flac $a`.wav" "$a"; done
@xdissent
xdissent / super_group_acl.sh
Created March 27, 2010 15:12
Grant all file permissions to a group
chmod +a "group:<group name>:allow:delete,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown,list,search,add_file,add_subdirectory,delete_child,read,write,append,execute,file_inherit,directory_inherit" <directory | file>
@xdissent
xdissent / middleware.rb
Created December 8, 2010 05:25
delete vagrant vm's chef client and node from chef server on destroy
class OnDestroyMiddleware
def initialize(app, env)
@app = app
end
def call(env)
`knife client show #{env["config"].chef.node_name}`
if $?.to_i == 0
env.ui.info "Removing client #{env["config"].chef.node_name}"
`knife client delete #{env["config"].chef.node_name} -y`
@xdissent
xdissent / questionmarks.js
Created January 19, 2011 21:10
Wrap question marks in headers with span in jQuery 1.4+
$('h1, h2').html(function(i, h) {
return h.replace(/\?/g, '<span class="question-mark">?</span>');
});
@xdissent
xdissent / post-receive
Created June 20, 2011 21:41
Git post-receive hook to update Redmine changesets
#!/bin/sh
# Add this hook to /usr/share/git-core/templates/hooks to enable for all new repositories.
REPO_URL=`echo $PWD | sed 's:/hooks$::'` /usr/share/redmine/script/runner /usr/share/redmine/extra/update_repository.rb -e production > /dev/null 2>&1 &