Skip to content

Instantly share code, notes, and snippets.

@benjamw
benjamw / array_filter_recursive.php
Last active June 11, 2024 09:41
PHP array_filter_recursive function
<?php
/**
* Exactly the same as array_filter except this function
* filters within multidimensional arrays
*
* @param array $array
* @param callable|null $callback optional filter callback function
* @param bool $remove_empty_arrays optional flag removal of empty arrays after filtering
*
@benjamw
benjamw / gist:3180375
Created July 26, 2012 05:10
create various repeating patterns of TRUE / FALSE in a loop
<?php
// patterns
$patterns = array( );
for ($i = 0; $i < 20; ++$i) {
// the generic alternating patterns
@benjamw
benjamw / gist:4027637
Created November 6, 2012 21:19
Get index of FEN string for given blocks
<?php
/** function get_index
*
* Gets the FEN string index for a 2D location
* of a square array of blocks each containing
* a square array of elements within those blocks
*
* This was designed for use within foreach structures
* The first foreach ($i) is the outer blocks, and the
<?php
/*
Find the length of the longest increasing sequence through adjacent numbers
(including diagonals) in a rectangular grid of numbers in a language of your
choice. The solution should handle grids of arbitrary width and height.
For example, in the following grid, one legal path (though not the longest)
that could be traced is 0->3->7->9 and its length would be 4.
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@benjamw
benjamw / combine.php
Last active August 29, 2015 14:10
Scripts for splitting and recombining large SQL dumps into more manageable pieces.
<?php
/*
Combine multiple SQL files using PHP command line.
Will combine to current working directory
Best used with files that were split using the SQL splitter: split.php
Will prepend and append the _root_.sql and _end_.sql files if found
Arguments:
@benjamw
benjamw / random.js
Last active February 1, 2017 08:14
Weighted Random Number Generator
//http://stackoverflow.com/questions/30492259/get-a-random-number-focused-on-center
// max is non-inclusive
// bellFactor = 1 is normal flat RNG
// bellFactor = 2 is sawtooth shaped
// bellFactor = 4 is basic bell curve
function weightedRandom(max, bellFactor) {
max = parseInt(max, 10);
bellFactor = parseInt(bellFactor || 1, 10);
if (bellFactor < 1) {
bellFactor = 1;
; // the thing
(function($) {
"use strict";
/**
* The Thing
*
* @constructor
*/
@benjamw
benjamw / my_round.php
Last active September 25, 2015 04:51
<?php
/** function my_round
*
* rounds a value to the closest value
* starting at another value
* e.g.- my_round(6.28318, 5, 2) => 7
*
* To round to closest of:
* 2 6 10 14 18 22 ...
@benjamw
benjamw / index.html
Last active September 22, 2016 15:55
Material Style Spinner
<div class="loader">
<svg width="2.4em" height="2.4em">
<!-- unit circle -->
<circle cx="1.2em" cy="1.2em" r="1em"/>
</svg>
</div>