Skip to content

Instantly share code, notes, and snippets.

<?php
function isNextDateGreaterThanHalf($frequency, $seasonalEndDate, $nextDate)
{
$dateDiff = (strtotime($seasonalEndDate) > strtotime($nextDate))
? strtotime($seasonalEndDate) - strtotime($nextDate)
: strtotime($nextDate) - strtotime($seasonalEndDate);
$daysDiff = floor($dateDiff / (60*60*24)); //seconds * mins in hour * hours in day
@jasonbradley
jasonbradley / run-tests
Last active January 22, 2020 08:40
Run PHP Unit tests bash script. Looks for phpunit command availability or phpunit.phar in the same location. It will download the phar file if neither is found.
#!/bin/bash
PHPUNIT_COMMAND=""
MEMORY_LIMIT=512M
PHPUNIT_VERSION="4.1.3"
if hash phpunit 2>/dev/null;
then
PHPUNIT_COMMAND="phpunit"
elif [ -e phpunit.phar ]
@jasonbradley
jasonbradley / gist:ed46d7ea2f200ab42714
Last active August 29, 2015 14:10
Install subversion 1.7 on CentOS 6.5
## install subversion 1.7.x ##
wget http://pkgs.repoforge.org/subversion/subversion-1.7.1-0.1.el6.rfx.x86_64.rpm /tmp
sudo rpm -ivh /tmp/subversion-1.7.1-0.1.el6.rfx.x86_64.rpm

Keybase proof

I hereby claim:

  • I am jasonbradley on github.
  • I am jasonbradley (https://keybase.io/jasonbradley) on keybase.
  • I have a public key whose fingerprint is 66A3 8B66 955C E77B 5DAF 30CA 0F7E ABE6 63EE B093

To claim this, I am signing this object:

local widget = require "widget"
local scroller = widget.newScrollView{
width = 320,
height = 480,
scrollWidth = 700,
scrollHeight = 1000
}
-- event listener for button widget
local function onButtonEvent( event )
@jasonbradley
jasonbradley / gist:4357406
Created December 22, 2012 03:47
Lua convert HEX to RGB
function Util:hex2rgb(hex)
hex = hex:gsub("#","")
return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
end
@jasonbradley
jasonbradley / jsonStorage.lua
Created December 15, 2012 05:28
Lua read/write data in JSON format
-- load the JSON library.
local Json = require("json")
local JsonStorage = {}
-- Function to save a table.&nbsp; Since game settings need to be saved from session to session, we will
-- use the Documents Directory
JsonStorage.saveTable = function(t, filename)
local path = system.pathForFile( filename, system.DocumentsDirectory)
local file = io.open(path, "w")
@jasonbradley
jasonbradley / util.lua
Created December 15, 2012 05:25
Format a number in Lua
Util.format_num = function(amount, decimal, prefix, neg_prefix)
local str_amount, formatted, famount, remain
decimal = decimal or 2 -- default 2 decimal places
neg_prefix = neg_prefix or "-" -- default negative sign
famount = math.abs(Util.round(amount,decimal))
famount = math.floor(famount)
remain = Util.round(math.abs(amount) - famount, decimal)
@jasonbradley
jasonbradley / util.lua
Created December 15, 2012 05:24
Round function in Lua
Util.round = function(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
@jasonbradley
jasonbradley / util.lua
Created December 15, 2012 05:23
PHP trim for Lua
Util.trim = function(s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end