Skip to content

Instantly share code, notes, and snippets.

View jasonrhodes's full-sized avatar

Jason Rhodes jasonrhodes

View GitHub Profile
@jasonrhodes
jasonrhodes / calcEra.php
Created October 14, 2012 18:51
Calculate ERA
<?php
function calcERA($innings, $runs)
{
$innings = explode(".", number_format($innings, 1));
$thirds = ($innings[0] * 3) + $innings[1];
return round((9 * $runs) / ($thirds/3), 2);
}
# echo calcERA(9, 2); => 2
@jasonrhodes
jasonrhodes / less_converter.rb
Created October 23, 2012 16:41 — forked from edeustace/less_converter.rb
A Jekyll plugin to convert a .less file to .css
module Jekyll
# Compiled LESS CSS into CSS. You must specify an empty YAML front matter
# at the beginning of the file.
# .less -> .css
class LessConverter < Converter
safe true
priority :low
pygments_prefix "\n"
pygments_suffix "\n"
@jasonrhodes
jasonrhodes / less.rb
Created October 23, 2012 16:41 — forked from jasongraham/less_converter.rb
A Jekyll plugin to convert a .less file to .css
module Jekyll
# Compiled LESS CSS into CSS. You must specify an empty YAML front matter
# at the beginning of the file.
# .less -> .css
class LessConverter < Converter
safe true
priority :low
pygments_prefix "\n"
pygments_suffix "\n"
@jasonrhodes
jasonrhodes / pdo-print.php
Created November 8, 2012 01:35
SQL placeholder replacement
<?php
# for when you need to print out a PDO prepared statement or similar with ":symbol" style placeholders
function pdoprint($sql, $values)
{
return preg_replace_callback(
'/:[^\s;)]*/',
function ($matches) use (&$values) {
return "'" . array_shift($values) . "'";
@jasonrhodes
jasonrhodes / debugout.php
Created November 8, 2012 02:05
PHP print_r and die convenience
<?php
function debugout($value, $autodump = false)
{
if ($autodump || (empty($value) && $value !== 0 && $value !== "0") || $value === true) {
var_dump($value);
} else {
print_r($value);
}
die();
function stringToNumber(value) {
/**
* Interesting facts about JavaScript:
*
* 1. NaN != NaN
* 2. If you pass a string to parseFloat(), it returns NaN
*
* These facts can be exploited to convert string numbers into numbers.
*/
var floatValue = parseFloat(value);
<?php
$params = array(
"type" => "json",
"v" => 1,
"api_key" => "4539653423sa35",
"topic" => "science",
"edition" => "fall"
);
@jasonrhodes
jasonrhodes / ripwysiwyg.md
Created November 14, 2012 21:45
Kill your WYSIWYG: How structured content will make you skinny, happy, and rich

Building websites is easy. Maintaining websites is hard.

Everyone spends a lot of time choosing, using, and complaining about their CMS.

We build templates to control the design and layout of our site, except for the Big Black Hole of Most Important Content on the Page. Then, we force the content creators and maintainers to be designers and layout, ers?

The WYSIWYG promised to make content maintenance easier, but what you see is rarely very close to what you get. WYSIWYG is a lie.

But why are asking content creators to worry about formatting and layout, anyway?

@jasonrhodes
jasonrhodes / genblog.sh
Created December 11, 2012 14:15
Quick script to manage a jekyll site hosted on github, but running plugins locally
#!/bin/bash
# Replace 'notrobotic' throughout the script with the name of your blog's directory, and '~/vhosts/notrobotic' with the path to your local repo
cd ~/vhosts/notrobotic
# git add .
# git add -u
# git commit -m "My message passed in via param"
# git checkout src
@jasonrhodes
jasonrhodes / issue-select.js
Created December 19, 2012 03:23
Drupal fix for the Hub: Remove "issue" options that don't correspond to the content type of the current article, and rename the remaining ones to remove the publication name.
jQuery(document).ready(function ($) {
var options = $("#edit-field-issue-und").find("option");
var body = $("body");
var type;
if (body.hasClass("node-type-magazine-article")) {
type = "magazine";
} else if (body.hasClass("node-type-gazette-article")) {
type = "gazette";