Skip to content

Instantly share code, notes, and snippets.

View jveldboom's full-sized avatar

John Veldboom jveldboom

View GitHub Profile
@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;}
@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 / 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"}
<?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 / 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
{
@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 / smooth_scrolling.js
Created June 23, 2013 01:28
Smooth scrolling to #anchor
// HTML:
// <h1 id="anchor">Lorem Ipsum</h1>
// <p><a href="#anchor" class="topLink">Back to Top</a></p>
$(document).ready(function() {
$("a.topLink").click(function() {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top + "px"
@jveldboom
jveldboom / content_load.js
Created June 23, 2013 01:31
Simple Content Load on Scroll
var loading = false;
$(window).scroll(function(){
if((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){
if(loading == false){
loading = true;
$('#loadingbar').css("display","block");
$.get("load.php?start="+$('#loaded_max').val(), function(loaded){
$('body').append(loaded);
$('#loaded_max').val(parseInt($('#loaded_max').val())+50);
$('#loadingbar').css("display","none");
@jveldboom
jveldboom / gist:6051179
Created July 22, 2013 03:45
Fade In & Out the Most Recent Pictures in a Directory with jQuery
<?php
// Global Variables
$image_dir = "$_SERVER[DOCUMENT_ROOT]/examples/imgs"; // directory on server
$image_relative_path = '/examples/imgs'; // path to images relative to script
$file_types = array('jpg','jpeg','gif','png');
$image_time = '4000'; // seconds each image will display (4000 = 4 seconds)
if($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
@jveldboom
jveldboom / onix_code_list.sql
Created July 26, 2013 13:38
ONIX fields and values SQL
DROP TABLE IF EXISTS `onix_code_list`;
CREATE TABLE `onix_code_list` (
`list_id` int(11) unsigned NOT NULL,
`values` varchar(20) DEFAULT NULL,
`name` varchar(100) DEFAULT '',
`notes` text,
`revision` int(11) unsigned DEFAULT NULL,
KEY `list_id` (`list_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;