Skip to content

Instantly share code, notes, and snippets.

View jasonreposa's full-sized avatar

Jason Reposa jasonreposa

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jasonreposa on github.
  • I am jasonmbt (https://keybase.io/jasonmbt) on keybase.
  • I have a public key ASDiitpNoGnZJM7yRfi3qu_eT2Z2XLq74xm-s6mqcg1oGgo

To claim this, I am signing this object:

if ($key == '@attributes') {
continue;
}
@jasonreposa
jasonreposa / gist:2788932
Created May 25, 2012 15:58
Double equals vs triple equals on a number and string
echo 0 == '@attributes' ? 'YES' : 'NO';
echo "<br>\n";
echo 0 === '@attributes' ? 'YES' : 'NO';
html = Nokogiri::HTML(the_content)
...
html.xpath("//ul[@id='sharebar']").each(&:remove)
html.xpath('//script').each(&:remove)
html.xpath('//@onclick').each(&:remove)
html.xpath('//@class').each(&:remove)
html.xpath('//@style').each(&:remove)
...
// http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
// http://gist.github.com/raw/63002/b53853727856bad494dcbb7ffed4fc17f289af92/gistfile1.rb
// $z is the pnormaldist with power = 0.05. I.e., pnormaldist(1-power/2)
function score($pos, $n) {
if ($n == 0) { return 0; }
$z = 1.95996397158435;
$phat = 1.0*$pos/$n;
return ($phat + $z*$z/(2*$n) - $z * sqrt(($phat*(1-$phat)+$z*$z/(4*$n))/$n))/(1+$z*$z/$n);
}
@jasonreposa
jasonreposa / functions.php
Created February 17, 2012 23:21
Wordpress word count
function my_head() {
global $post;
if (is_single()) {
$short_post = false;
$words = preg_split('/\s+/', strip_tags($post->post_content), -1, PREG_SPLIT_NO_EMPTY);
if (count($words) < 300) {
$short_post = true;
}
}
@jasonreposa
jasonreposa / array_psplice.php
Created January 19, 2012 14:49
Array splice with preserve keys
function array_psplice(&$array, $offset = 0, $length = 1) {
$return = array_slice($array, $offset, $length, true);
foreach ($return as $key => $value) {
unset($array[$key]);
}
return $return;
}
@jasonreposa
jasonreposa / functions.php
Created October 26, 2011 14:02
A quick and painless way to remove the width from a wordpress caption and optionally add a source link as nofollow
// Originally built for http://www.mybanktracker.com/bank-news/
function mbt_img_caption_shortcode($val, $attr, $content = null) {
extract(shortcode_atts(array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr));
// if it contains a pipe character, we know it's ours