Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Kohn kohnmd

View GitHub Profile
View async-test.js
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 Nov 29, 2015
React JS - Product Search
View main.js
// 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 Aug 29, 2015
CareerCup min range
View index.php
<?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)
View Slidey-Loader.markdown

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 Apr 23, 2014
WordPress WP_Query on a diet (performs only 2 queries)
View page.php
<?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 Feb 8, 2019
Function to recursively flatten multidimensional PHP array.
View flatten.php
<?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 Apr 13, 2014
Scale canvas element for high DPI monitors.
View hdpicanvas.js
/**
* 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 Aug 29, 2015
Converts a string into a slug. JS and PHP versions.
View str_to_slug.js
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 Mar 5, 2014
Remove Post Locked Dialog in WP Admin
View functions.php
<?php
add_filter('show_post_locked_dialog', '__return_false');
@kohnmd
kohnmd / gist:9197077
Last active Aug 29, 2015
Wrapper function that makes print_r more browser friendly.
View gist:9197077
<?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) {
You can’t perform that action at this time.