Skip to content

Instantly share code, notes, and snippets.

View mattsah's full-sized avatar

Matthew J. Sahagian mattsah

View GitHub Profile
@mattsah
mattsah / gist:3104455
Created July 13, 2012 11:39
A non-recursive version of PHP's array_replace_recursive()
<?php
/**
* Many examples of pre 5.3 versions of this function use recursion
* this one avoids it for people who, like me, are only going to rely
* on this logic in a single place. In short, you can fully remove the
* function definition and implications and the actual code will still
* work. That is, the function does not need to call itself.
*/
function array_replace_recursive($base, $replacements)
@mattsah
mattsah / gist:1872454
Created February 21, 2012 00:07
inKWell iw class constructor
<?php
/**
* Constructing an iw object is not allowed, this is purely for
* namespacing and static controls.
*
* @final
* @access private
* @param void
* @return void
@mattsah
mattsah / gist:1857678
Created February 18, 2012 05:47
IE Fixes
/**
* Allows for IE's setInterval and setTimeout to pass parameters
*/
(function(f){
window.setTimeout = f(window.setTimeout);
window.setInterval = f(window.setInterval);
})(function(f){
return function(c,t){
var a=[].slice.call(arguments,2);
return f(function(){ c.apply(this,a); },t);
@mattsah
mattsah / gist:1756935
Created February 7, 2012 03:21
Convert complex input names/values to javascript object
function(inputs){
var values = {};
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].name.indexOf('[') != -1) {
var parts = inputs[i].name.split(/\[|\]\[|\]/g);
var value = inputs[i].value;
for (var j = parts.length; j > 0; j--) {
if (parts[j - 1]) {
@mattsah
mattsah / gist:1511117
Created December 22, 2011 17:31
This is Secret
gsettings set org.gnome.shell.overrides button-layout 'close:'
@mattsah
mattsah / gist:1260300
Created October 3, 2011 21:24
Canonical URLs
<?php
function get_url($with_query_string = TRUE, $canonical_filter = array())
{
$query = NULL;
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$port = ':' . $_SERVER['SERVER_PORT'];
$host = $_SERVER['SERVER_NAME'];
$scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
? 'https'
@mattsah
mattsah / recurring_events.php
Created August 13, 2011 22:41
Generates Event Occurr for Recurring Events
public function generateEventOccurrences()
{
// Flush all existing occurrences
foreach ($this->buildEventOccurrences() as $event_occurrence) {
$event_occurrence->delete();
}
// Rebuild based on the new date information
// Determine start timestamp
@mattsah
mattsah / recurring_events.sql
Created August 13, 2011 22:39
Recurring Event Database Shema
CREATE TABLE events (
id serial PRIMARY KEY,
title varchar(255) NOT NULL,
body text,
start_date date NOT NULL,
start_time time NOT NULL,
end_date date default NULL,
end_time time default NULL,
recurrence_frequency integer default 1,
recurrence varchar(10) NOT NULL default 'Never' CHECK(recurrence IN ('Never', 'Daily', 'Weekly', 'Monthly', 'Yearly')),