Skip to content

Instantly share code, notes, and snippets.

View scribu's full-sized avatar

Cristi Burcă scribu

View GitHub Profile
@scribu
scribu / gist:906872
Created April 7, 2011 01:21
'price' sortable column example
<?php
// Register the column
function price_column_register( $columns ) {
$columns['price'] = __( 'Price', 'my-plugin' );
return $columns;
}
add_filter( 'manage_edit-post_columns', 'price_column_register' );
@scribu
scribu / wp-hooks-filters-flow.php
Created March 31, 2011 00:38
WordPress Hooks & Filters Flow
<?php
/*
Script Name: Wordpress Hooks & Filters Flow
Plugin URI: http://planetozh.com/blog/my-projects/wordpress-hooks-filter-flow/
Description: Lists hooks and their associated filters/actions for your blog. Meant to provide debugging help.
Version: 1.0
Author: Ozh
Author URI: http://planetOzh.com/
*/
@scribu
scribu / backtrace-errors.php
Created October 14, 2010 07:25
Backtrace Errors
<?php
// Forked from: http://stackoverflow.com/questions/1159216/how-can-i-get-php-to-produce-a-backtrace-upon-errors/1159235#1159235
function process_error_backtrace($errno, $errstr, $errfile, $errline) {
if(!(error_reporting() & $errno))
return;
switch($errno) {
case E_WARNING :
case E_USER_WARNING :
case E_STRICT :
@scribu
scribu / defaultdict.php
Created October 13, 2012 16:18
defaultdict in PHP
<?php
# http://scribu.net/blog/defaultdict-in-php.html
class Defaultdict implements ArrayAccess {
private $container = array();
private $default;
public function __construct( $default ) {
<?php
/**
* Iterates over results of a query, split into many queries via LIMIT and OFFSET
*/
class QueryIterator implements Iterator {
var $limit = 500;
var $query = '';
var $global_index = 0;
@scribu
scribu / gist:856587
Last active June 5, 2024 20:30
'product' post type + 'color' taxonomy
<?php
// Register the post type and taxonomy
function init_product_cpt() {
register_post_type( 'product', array(
'public' => true,
'label' => __( 'Products', 'my-plugin' )
) );
register_taxonomy( 'color', 'product', array(
@scribu
scribu / gist:4030509
Created November 7, 2012 09:54
nginx config for multisite in a subdirectory
# site path: /var/www/wp.dev/
# wp path: /var/www/wp.dev/core/
# site url: http://wp.dev/core/
# wp url: http://wp.dev/core/
upstream php {
server unix:/var/run/phpfpm.sock;
}
@scribu
scribu / wrapping.php
Last active January 7, 2024 11:59
Theme wrapping
<?php
# License: Public Domain
# I recommend replacing 'my_' with your own prefix.
function my_template_path() {
return My_Wrapping::$main_template;
}
@scribu
scribu / array_insert.php
Created September 20, 2010 18:53
array_insert()
<?php
/**
* Insert an array into another array before/after a certain key
*
* @param array $array The initial array
* @param array $pairs The array to insert
* @param string $key The certain key
* @param string $position Wether to insert the array before or after the key
* @return array
@scribu
scribu / deferred_acceptance.py
Created September 10, 2015 22:21
Deferred Acceptance Algorithm
from collections import defaultdict
def male_without_match(matches, males):
for male in males:
if male not in matches:
return male
def deferred_acceptance(male_prefs, female_prefs):
female_queue = defaultdict(int)