Skip to content

Instantly share code, notes, and snippets.

var currentScript = document.scripts[document.scripts.length - 1];
var container = document.createElement("div");
container.appendChild(document.createTextNode("CREATIVE"));
currentScript.parentNode.insertBefore(container, currentScript);
@kohnmd
kohnmd / main.js
Created November 29, 2015 06:23
React JS - Product Search
// https://facebook.github.io/react/docs/thinking-in-react.html
var React = require('react');
var ReactDOM = require('react-dom');
var ProductCategoryRow = React.createClass({
render: function() {
return(
<tr>
<th colSpan="2">
@kohnmd
kohnmd / index.php
Last active August 29, 2015 14:20
CareerCup min range
<?php
/**
* CareerCup min range.
*
* This is NOT a working solution. By dumb luck it happened to solve the problem
* for the example lists, but completely crumbles when presented with:
* - more than 3 lists.
* - sadistic lists like:
* array(0, 1, 2, 3, 4)
* array(5, 6, 7, 8, 9)
@kohnmd
kohnmd / Slidey-Loader.markdown
Created May 13, 2014 04:43
A Pen by Mike Kohn.

Slidey Loader

CSS loader animation.

Is there a way to condense the HTML/CSS so it works with an arbitrary number of loading bars?

A Pen by Mike Kohn on CodePen.

License.

@kohnmd
kohnmd / page.php
Created April 23, 2014 17:42
WordPress WP_Query on a diet (performs only 2 queries)
<?php
// Found here: http://alexking.org/speaking/core-competency/index.php#/queries-04-wp-query-modifiers
$example = new WP_Query(array(
'posts_per_page' => 2,
'orderby' => 'date',
'order' => 'DESC',
'no_found_rows' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
@kohnmd
kohnmd / flatten.php
Last active September 20, 2021 12:48
Function to recursively flatten multidimensional PHP array.
<?php
// Requires PHP 5.3+
// Found here: http://stackoverflow.com/a/1320156
function flatten_array(array $array) {
$flattened_array = array();
array_walk_recursive($array, function($a) use (&$flattened_array) { $flattened_array[] = $a; });
return $flattened_array;
}
@kohnmd
kohnmd / hdpicanvas.js
Created April 13, 2014 17:28
Scale canvas element for high DPI monitors.
/**
* Resizes the canvas for high DPI (retina) screens.
*
* Modified from here: http://www.html5rocks.com/en/tutorials/canvas/hidpi/
*
* By Paul Lewis, customized by Mike Kohn
*/
var HDPICanvas = (function() {
function scale(canvas) {
@kohnmd
kohnmd / str_to_slug.js
Last active August 29, 2015 13:58
Converts a string into a slug. JS and PHP versions.
function str_to_slug(str, sep) {
if (typeof sep == 'undefined') {
sep = '-';
}
// remove extra spaces and convert to lowercase
str = str.toString().trim().toLowerCase();
// convert any character that's not alphanumeric into a separator
str = str.replace(/[^a-z0-9]/g, sep)
// replace any successive separators with a single one
@kohnmd
kohnmd / functions.php
Created March 5, 2014 03:51
Remove Post Locked Dialog in WP Admin
<?php
add_filter('show_post_locked_dialog', '__return_false');
@kohnmd
kohnmd / gist:9197077
Last active August 29, 2015 13:56
Wrapper function that makes print_r more browser friendly.
<?php
function pre_print($var, $title="", $return=false) {
$output = "";
$output .= ($title) ? '<strong>'.$title.'</strong>' : "";
$output .= '<pre>';
$output .= print_r($var, true);
$output .= '</pre>';
if($return) {