Skip to content

Instantly share code, notes, and snippets.

View moimikey's full-sized avatar
:shipit:
ship it

Michael Scott Hertzberg moimikey

:shipit:
ship it
View GitHub Profile
@moimikey
moimikey / gist:1389985
Created November 23, 2011 21:31
a more proper way to display posts from a specific category
<?php
add_filter( 'parse_query', 'hertzberg_filter_posts' );
/**
* Hook into parse_query to only return display posts from category id #1 in search & blog/index
*
* @access public
* @return void
*/
function hertzberg_filter_posts( $query ) {
@moimikey
moimikey / gist:1441514
Created December 7, 2011 04:52
Creating a temporary chroot jail to successfully install APC via pecl on a Media Temple (ve) server running Plesk Parallels
[root@hertzberg ~]# pecl install apc
downloading APC-3.1.9.tgz ...
Starting to download APC-3.1.9.tgz (155,540 bytes)
.................................done: 155,540 bytes
54 source files, building
running: phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
@moimikey
moimikey / gist:1450332
Created December 9, 2011 05:34
An alternative to glob() using SPL
<?php
/**
* Some words of wisdom:
* http://php.net/manual/en/class.directoryiterator.php
*/
class HertzbergFilterDots extends FilterIterator {
public function __construct( $path ) {
parent::__construct( new DirectoryIterator( $path ) );
}
@moimikey
moimikey / gist:1487428
Created December 16, 2011 19:04
Filtering WordPress output
<?php
/**
* Filter get_post() array with only the relative information that we need
*
* @access public
* @param integer $post_id
* @return array
* @author moimikey
*/
function hertzberg_filter_post_data( $post_id ) {
@moimikey
moimikey / gist:1860519
Created February 18, 2012 18:20
my own relative time converter
<?php
class Time {
/**
* Seconds
*/
const SECOND = 1;
/**
* Minutes
@moimikey
moimikey / gist:2313104
Created April 5, 2012 18:32
Check if you're infected with Flashback
cat ~/Library/LaunchAgents/* > /tmp/.hi && cat /Library/LaunchAgents/* >> /tmp/.hi && cat /tmp/.hi | grep -E 'zeo|mkeeper' | wc -l && rm -rf /tmp/.hi
@moimikey
moimikey / gist:3704281
Created September 12, 2012 04:26
super fast random WordPress tag
<?php
/**
* Return a random post tag from the wp_terms table
*
* average 0.4ms on a 3K table
*
* @author Michael Scott Hertzberg
* @return mixed|string
*/
function m_random_tag() {
@moimikey
moimikey / gist:5042795
Created February 26, 2013 22:15
latest pinterest feed using their simple rss feed transcoded to json.
<?php
class XmlToJson {
public function Parse( $url ) {
$fileContents = file_get_contents( $url );
$fileContents = str_replace( array(
"\n",
"\r",
"\t"
), '', $fileContents );
$fileContents = trim( str_replace( '"', "'", $fileContents ) );
([0...1000].filter (m) -> m % 3 is 0 or m % 5 is 0).reduce (s,h) -> s + h
@moimikey
moimikey / gist:7310211
Last active December 27, 2015 10:19
calculate data transfer bits
# Convert bit rate from and to another rate
#
# amount: data being converted
# unitFrom: `from` unit. bps|kbps|mbps|gbps
# unitTo: `to` unit. bps|kbps|mbps|gbps
#
# uses double bitwise not `~~` as `Math.floor`
# uses `+` as type coercion to `int`
Util.bitCalculate = (amount, unitFrom, unitTo, maxDecimals=2) ->
base = 1000