Category Hierarchy (PHP/MySQL)

When using an adjacency list model, you can generate the structure in one pass. Taken from One Pass Parent-Child Array Structure (Sep 2007; by Nate Weiner): $refs = array(); $list = array(); $sql = “SELECT item_id, parent_id, name FROM items ORDER BY name”; /** @var $pdo \PDO */ $result = $pdo->query($sql); foreach ($result as $row) … Read more

Custom sorting (non-alphabetical)

The levels should be specified explicitly: A$animal <- factor(A$animal, levels = c(“dog”, “elephant”,”cat”)) A$color <- factor(A$color, levels = c(“green”, “blue”, “red”)) Then you order by the 2 columns simultaneously: A[order(A$animal,A$color),] # animal color # 6 dog green # 4 dog blue # 5 dog red # 9 elephant green # 7 elephant blue # 8 … Read more

Remove category & tag base from WordPress url – without a plugin

If you want to remove /category/ from the url, follow these two steps: Go to Settings >> Permalinks and select Custom and enter: /%category%/%postname%/ Next set your Category Base to . Save it and you’ll see your URL changed to this format: http://yourblog.com/quotes/ (Source: http://premium.wpmudev.org/blog/daily-tip-quick-trick-to-remove-category-from-wordpress-url/)

Objective-C: Property / instance variable in category

.h-file @interface NSObject (LaserUnicorn) @property (nonatomic, strong) LaserUnicorn *laserUnicorn; @end .m-file #import <objc/runtime.h> static void * LaserUnicornPropertyKey = &LaserUnicornPropertyKey; @implementation NSObject (LaserUnicorn) – (LaserUnicorn *)laserUnicorn { return objc_getAssociatedObject(self, LaserUnicornPropertyKey); } – (void)setLaserUnicorn:(LaserUnicorn *)unicorn { objc_setAssociatedObject(self, LaserUnicornPropertyKey, unicorn, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } @end Just like a normal property – accessible with dot-notation NSObject *myObject = [NSObject new]; myObject.laserUnicorn … Read more