Skip to content

Instantly share code, notes, and snippets.

View stevenwoodson's full-sized avatar

Steve Woodson stevenwoodson

View GitHub Profile
@stevenwoodson
stevenwoodson / KeyTerms.php
Created March 16, 2013 21:35
Determines the key terms in a provided $content string and returns the $return most popular terms. This works by clearing all the most common words from the content and counting the number of occurrences of what's left. We then find all phrases that contain any of those words that occurred more than once in an attempt to isolate the most importa…
<?php
/**
* Key Terms
*
* Determines the key terms in a provided $content string and returns the $return most popular terms. This works by
* clearing all the most common words from the content and counting the number of occurrences of what's left. We then
* find all phrases that contain any of those words that occurred more than once in an attempt to isolate the most
* important phrases. The number of terms returned can also be set or set to 0 to return all matches. If there's room
* for more returned results ($results has to be greater than zero) then we gather the most used words not in an
* existing phrase and fill the returned array.
@stevenwoodson
stevenwoodson / gist:4465615
Last active January 19, 2017 00:56
Set the local users timezone offset to a cookie with Javascript and pull it with PHP to set the default timezone
/**
* Set the local time offset to display time values in the users local time
*/
function setTimeOffset() {
// Create all the dates necessary
var now = later = d1 = d2 = new Date(),
set = { 'offset': now.getTimezoneOffset(), 'dst': 0 }
// Set time for how long the cookie should be saved - 1 year
later.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
// Date one is set to January 1st of this year
@stevenwoodson
stevenwoodson / after-binding.js
Created December 29, 2012 21:05
jQuery - Custom binding on 'after'
// Trigger any custom bindings on after
(function($) {
var origAfter = $.fn.after;
$.fn.after = function () {
return origAfter.apply(this, arguments).trigger("after");
};
})(jQuery);
// Bind 'after' and then use it to trigger function_to_trigger()
$('.element').bind("after", function() { function_to_trigger(); } }).after('<ul></ul>');
@stevenwoodson
stevenwoodson / MY_DB_mysql_driver.php
Created December 27, 2012 06:10
Codeigniter DB - Insert on Duplicate Update method Generates a platform-specific insert string from the supplied data, MODIFIED to include ON DUPLICATE UPDATE
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class MY_DB_mysql_driver extends CI_DB_mysql_driver {
final public function __construct($params) {
parent::__construct($params);
}
/**
* Insert_On_Duplicate_Update_Batch
@stevenwoodson
stevenwoodson / gist:4080143
Created November 15, 2012 18:01
Find Age from Month/Day/Year
function displayage( yr, mon, day, unit, decimal, round ) {
//Sample usage
//displayage (year, month, day, unit, decimals, rounding)
//Unit can be "years", "months", or "days"
//Decimals specifies demical places to round to (ie: 2)
//Rounding can be "roundup" or "rounddown"
//displayage(1997, 11, 24, "years", 0, "rounddown")
today = new Date();
yr = parseInt(yr, 10);