Skip to content

Instantly share code, notes, and snippets.

@jmc734
jmc734 / print_object.php
Last active October 7, 2015 03:08
Readable PHP Object Print
<?php
/**
* @param mixed $expression The expression to be printed
* @param bool $return When true, output string will be returned rather than printed
* @return bool|string When the return parameter is true, the output string will be returned.
* Otherwise, the boolean true will be returned
*/
function print_object($expression , $return = false){
return highlight_string(print_r($expression, true), $return);
@jmc734
jmc734 / bcrypt.php
Created July 13, 2012 15:00
PHP Bcrypt Password Hashing Class
<?php
/**
* Bcrypt
*
* Methods to hash and validate passwords
*/
class Bcrypt {
/**
* Hash
@jmc734
jmc734 / MassDiscount.php
Created August 12, 2012 01:19
Shopify Batch Discount Automation (Create, Enable/Disable, Delete)
<?php
/**
* Discount
*
* Create, modify, and delete Shopify discounts
*
* PHP version 5
*
* @author Jacob McDonald <jmc734@gmail.com>
*/
@jmc734
jmc734 / structure.php
Created August 19, 2012 13:28
Build a tree structure from an array of nodes with IDs and parent IDs
<?php
class Structure {
private static $structure;
private static $lookup;
// Nodes can be any objects that have IDs (id) and a parent IDs (parent)
public static function buildTree($nodes){
// Initialize structure and lookup arrays
@jmc734
jmc734 / str_crc62.php
Last active December 14, 2015 21:49
Get the 32-bit CRC code for a string in base 62 (0-9A-Za-z)
<?php
/**
* Get the 32-bit CRC code for a string in base 62
*
* @param string $str The string to get the CRC for
* @param array $chars Optional. An array mapping the integer keys 0-61 to distinct characters.
* If not supplied, the character for each value will be calculated on the fly.
* @return string The base 62 CRC code
*/
@jmc734
jmc734 / moving_add.php
Last active December 19, 2015 10:19
Basic Moving Aggregation Methods
<?php
class Aggregate {
public static function avg($value, $index, &$avg) {
$avg = ($value + $index * $avg) / ($index + 1);
}
public static function sum($value, $index, &$sum) {
$sum += $value;
@jmc734
jmc734 / mergesort.asm
Created September 19, 2013 22:09
Merge Sorting an Indirect Array in MIPS Assembly
.text
la $a0, info # Load the start address of the array
lw $t0, length # Load the array length
sll $t0, $t0, 2 # Multiple the array length by 4 (the size of the elements)
add $a1, $a0, $t0 # Calculate the array end address
jal mergesort # Call the merge sort function
b sortend # We are finished sorting
##
<?php
function compare_keys($a, $b) {
if(abs($a) == abs($b)) return 0;
return (abs($a) > abs($b))?1:-1;
}
function compare_values($a, $b){
$tempA = is_array($a)?$a[0]:$a;
$tempB = is_array($b)?$b[0]:$b;
@jmc734
jmc734 / snowfall.md
Last active January 4, 2016 15:59
Top 100 Snowiest Colleges (2013)
  1. Johnson, Vermont (171.7)
  • Johnson State College
  1. Meadville, Pennsylvania (148.3)
  • Allegheny College
  1. Houghton, Michigan (146.3)
  • Michigan Technological University
  1. Edinboro, Pennsylvania (143.6)
  • Edinboro University of Pennsylvania
  1. Erie, Pennsylvania (143.6)
  • Gannon University
@jmc734
jmc734 / chromecast_audio.php
Created March 15, 2014 00:34
Use MKVMerge and Handbrake to check every video file in a directory and its subdirectories for the proper audio encoding for playback on a Chromecast and transcode it if it does not.
<?php
// This is going to take a while
set_time_limit(0);
/**
* Path to MKVMerge executable
*/
$mkvmerge = 'mkvmerge.exe';
/**
* Path to HandbrakeCLI executable