Skip to content

Instantly share code, notes, and snippets.

View jveldboom's full-sized avatar

John Veldboom jveldboom

View GitHub Profile
@jveldboom
jveldboom / class.move_db_files.php
Last active December 22, 2015 13:19
PHP class to move database files (like MYD, MYI and frm)
<?php
/*
|--------------------------------------------------------------------------
| Move Database Files (like MYD, MYI and frm)
|--------------------------------------------------------------------------
|
| $config = array(
| 'tables' => array('table1','table2'), // array of tables / filenames to move
| 'extensions' => array('MYD','MYI','frm'), // required extensions for each database
| 'from' => dirname(__DIR__).'/transfer', // from location of files
@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 / 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 / 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 / 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
{
@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 / order.json
Last active October 20, 2015 16:27
test order
{
"order_num": "5066",
"customer_id": "1",
"po_num": null,
"email": "john@veldboom.com",
"phone": "",
"billing_name": "JOHN VELDBOOM",
"billing_addr1": "289 W MAIN ST",
"billing_addr2": "",
"billing_city": "NESS CITY",
@jveldboom
jveldboom / json.lua
Last active October 9, 2015 06:38
Heka JSON Decoder
require "cjson"
local dt = require "date_time"
--[[
From trink in IRC - thanks!
Example use:
[HttpListenInput]
address = "0.0.0.0:8325"
@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;}