Skip to content

Instantly share code, notes, and snippets.

View jveldboom's full-sized avatar

John Veldboom jveldboom

View GitHub Profile
@jveldboom
jveldboom / function.ordinal.php
Created May 31, 2013 18:36
Add (th, st, nd, rd, th) to the end of a number
<?php
function ordinal($cdnl){
$test_c = abs($cdnl) % 10;
$ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? 'th'
: (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1)
? 'th' : 'st' : 'nd' : 'rd' : 'th'));
return $cdnl.$ext;
}
for($i=1;$i<100;$i++){
echo ordinal($i);
@jveldboom
jveldboom / spreadAmount.php
Created March 5, 2013 17:23
Spread amount over a quantity. Uses a balancer amount to last item
<?php
function spreadAmount($amount,$qty)
{
if($amount % $qty === 0)
{
$start = $amount / $qty;
$last = $start;
}
else
{
<?php
function addOrdinalNumberSuffix($num) {
if (!in_array(($num % 100),array(11,12,13))){
switch ($num % 10) {
// Handle 1st, 2nd, 3rd
case 1: return $num.'st';
case 2: return $num.'nd';
case 3: return $num.'rd';
}
}
@jveldboom
jveldboom / bash-loading-spinner.sh
Created February 24, 2013 03:15
Bash Loading Spinner
#!/bin/bash
spinner()
{
local pid=$1
local delay=0.4
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
@jveldboom
jveldboom / php-cli-colors.php
Last active August 24, 2023 15:32
PHP CLI Colors - PHP Class Command Line Colors (bash)
<?php
// from http://www.if-not-true-then-false.com/2010/php-class-for-coloring-php-command-line-cli-scripts-output-php-output-colorizing-using-bash-shell-colors/
class Colors {
private $foreground_colors = array();
private $background_colors = array();
public function __construct() {
// Set up shell colors
$this->foreground_colors['black'] = '0;30';
$this->foreground_colors['dark_gray'] = '1;30';
@jveldboom
jveldboom / getMiddleRange.js
Created April 7, 2011 12:38
find the a range in between two numbers
function getMiddleRange(min,max,limit,type)
{
--limit;
var new_num
var data = '';
for(var x=0; x<=limit; x++)
{
var new_num = Math.ceil((max - min) / limit);
new_num = min + (new_num * x);
if(x==0){new_num = min;}