Skip to content

Instantly share code, notes, and snippets.

<?php
class swDFPBaseModule
{
private function parent_or_child($tax, $query_key)
{
$slug = $wp_query->query_vars[$query_key]
$s = get_term_by('slug', $slug, $tax);
return ($s->parent>0) ?
'get_on_'.$tax.'_page' : 'get_on_child_'.$tax.'_page';
@beezee
beezee / UploadedFileBehavior.php
Created January 29, 2013 16:46
Shows how to "extend" CUploadedFile (difficult to do classically because of private static $_files property) using a small Factory component and a behavior
<?php
//Class to provide factory methods for seamless use
class UploadedFile extends CComponent
{
public function init()
{
parent::init();
}
@beezee
beezee / gist:5521040
Created May 5, 2013 14:57
cpt extended class of post with virtual attributes based on meta
class Player extends Post
{
private $_points = false;
public static $after_save = array('update_points');
public function set_points($points)
{
$this->_points = $points;
}
@beezee
beezee / domain_controller.erl
Created February 24, 2014 03:39
Chicago Boss universal RESTFUL json resource
-module(app_name_domain_controller, [Req]).
-compile(export_all).
all('GET', [Type]) ->
% TODO: expand flexibility of filtering interface
{json, boss_db:find(list_to_atom(Type), lists:map(fun({K, V}) -> {list_to_atom(K), 'equals', V} end,
Req:query_params()), [{order_by, last_update}, {order, desc}])}.
show('GET', [Id]) ->
Model = boss_db:find(Id),
@beezee
beezee / sync_wptt_post_counts.sql
Last active August 29, 2015 14:00
Synchronize wp_term_taxonomy post counts in one query
update wp_term_taxonomy as tt
left join (select term_taxonomy_id as tid, count(term_taxonomy_id) as real_count
from wp_term_relationships as tr
left join wp_posts as p on tr.object_id = p.ID
where p.post_status = "publish"
group by tid)
as rc
on rc.tid = tt.term_taxonomy_id
set tt.count = rc.real_count
@beezee
beezee / rchiper.rb
Created January 11, 2015 06:52
Rail Fence Cipher #rdaily
class RCipher
def take(s, n, stream)
x = 0
val = s
acc = []
while x < n do
val = stream.call(val)
acc.push(val)
x += 1
@beezee
beezee / no_side_effects.rb
Last active August 29, 2015 14:14
Putting your laundry away without side effects
# An exercise in controlled side effects inspired by
# http://tmd.io/code/2015/01/27/putting-away-your-laundry-a-look-at-service-objects-for-rails.html
# Generic "immutable" wrapper for hash of values and hash of validators
# Only unvalidated or Valid values come out of #to_h
# Validators can return ValidatedParams::Error('message') to come out of #errors
# This is a great candidate for property based testing and has no dependencies beyond hashes and procs
class ValidatedParams
Valid = true
@beezee
beezee / ack-stream.scala
Created October 27, 2015 12:13
Akka Streams with acknowledgement using bcast ~> zip
package main
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, ActorAttributes}
import akka.stream.scaladsl._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
object StreamProgram {
implicit lazy val system = ActorSystem("example")
@beezee
beezee / real_arity.rb
Created December 15, 2015 14:49
Proc#real_arity
# Currying a proc causes #arity to return -1
#
# This adds a #real_arity method to a Proc that always reflects the
# number of *remaining* parameters to be accepted (minus any partially applied)
class Proc
@r_arity = nil
def real_arity
@r_arity || arity
end
@beezee
beezee / .vimrc
Created March 24, 2016 17:09
vimrc
execute pathogen#infect()
syntax on
set shiftwidth=2
set tabstop=2
set expandtab
set autoindent
set tags=~/tags
set backspace=2
let &colorcolumn=join(range(81,999),",")
highlight ColorColumn ctermbg=255 guibg=#b5baa9