Skip to content

Instantly share code, notes, and snippets.

View SeanJA's full-sized avatar
🦑
🦖

SeanJA SeanJA

🦑
🦖
View GitHub Profile
<?php
//to have multiple sidebars in wordpress:
function mytheme_widgets_init() {
register_sidebar(array(
'name' => __( 'sidebar1', 'mytheme' ),
'id' => 'sidebar1-area',
'description' => __( 'The first sidebar area', 'mytheme' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
@SeanJA
SeanJA / php_shorttags.sh
Created October 28, 2010 13:31
grep php short tags
grep -r "<?[^php]" *.php
@SeanJA
SeanJA / array_functions.php
Created November 18, 2010 22:16
extra array functions
<?php
/**
* return the first element of the array
* @note If you are in a foreach loop, this will not reset the pointer to the first element of the array like calling reset($myarray) would
* @see reset
* @param array $array The array
* @return mixed the first element of the array
*/
function array_first(array $array){
@SeanJA
SeanJA / example.php
Created November 19, 2010 05:04
Compress images
<?php
$s = new smushit();
$smushed = $s->compress('http://thechronicleherald.ca/sites/default/files/imagecache/story_thumb/stories/photos/11-18-10_cl111710auditor2_1.jpg');
print_r($smushed);
@SeanJA
SeanJA / false_singleton.php
Created November 30, 2010 03:32
Make the clone/construct methods private and final, so I cannot do this:
<?php
abstract class Singleton {
private function __construct() {
// empty
}
public static function getInstance() {
static $instance = null;
<?php
//make sure that page is an int, and at least 1...
$data['page'] = (isset($_GET['page'])) ? (int) $_GET['page'] : 1;
//make sure that page is at least 1
if ($data['page'] <= 0) {
$data['page'] = 1;
}
//remove one from page for the query
$offset = $data['page'] - 1;
@SeanJA
SeanJA / ci_patch.patch
Created January 13, 2011 03:40
valums file uploader code igniter patch
# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
--- fileuploader.js
+++ fileuploader.js
@@ -1195,7 +1195,9 @@
// build query string
params = params || {};
params['qqfile'] = name;
@SeanJA
SeanJA / argh.html
Created January 27, 2011 19:33
abuse! abuse!
<p>
<ul>
<font class="header-md">HEADER</font>
<ul>
<table width="500">
<tr>
<td>
<p>
<a href="somewhere" class="blue-header-sm">Header</a>text<br>
<a href="somewhere" class="blue-header-sm">Header</a>text<br>
@SeanJA
SeanJA / gist:858593
Created March 7, 2011 14:58
Get the previous business day from a timestamp
<?php
function previous_business_day($timestamp, $holidays = array()) {
do {
$timestamp = $timestamp - 86400;
$day_of_week = date('l', $timestamp);
$due = date('Y-m-d', $timestamp);
} while (in_array($day_of_week, array('Sunday', 'Saturday')) || in_array($due, $holidays));
$checkdate = date('l Y-m-d', $timestamp);
return $checkdate;
}
<?php
/**
* Get the schema definition of a table, or the whole database schema.
*
*
* @param $table The name of the table. If not given, the schema of all tables is returned.
* @param $rebuild If true, the schema will be rebuilt instead of retrieved from the cache.
*/
function get_schema($table = NULL, $rebuild = FALSE) {
static $schema = array();