Skip to content

Instantly share code, notes, and snippets.

View codescribblr's full-sized avatar

Jonathan Wadsworth codescribblr

View GitHub Profile
@codescribblr
codescribblr / Snipplr-58528.txt
Created February 13, 2014 21:41
Timestamp Selectbox 15 min intervals
<?php
for ($i = 0; $i <= 1440; $i+=15) :
$date = date("g:i A",mktime(0,$i,0,1,1,2000));
?>
<select>
<option value="<?php echo $date; ?>"><?php echo $date; ?></option>
</select>
<?php
endfor;
?>
@codescribblr
codescribblr / Snipplr-67719.txt
Created February 13, 2014 21:41
Template Finder for Wordpress
add_action( 'wp_head', 'show_me_the_template' );
function show_me_the_template() {
global $template, $current_user, $wp_admin_bar;
get_currentuserinfo();
/* If you have more than one user deny. Be sure to use your user ID! */
if ( !is_user_logged_in() && $current_user->ID != '1' )
return;
if ( is_admin_bar_showing() )
$wp_admin_bar->add_menu( array(
@codescribblr
codescribblr / Snipplr-63256.txt
Created February 13, 2014 21:41
Sort multidimensional array
<?php
$transactions = array(
0 => array('date'=>1324235252, 'day'=>'monday'),
1 => array('date'=>1326516552, 'day'=>'tuesday'),
2 => array('date'=>1333453235, 'day'=>'wednesday')
)
function sortByOrder($a, $b) {
return $b['date'] - $a['date'];
}
@codescribblr
codescribblr / Snipplr-70540.txt
Created February 13, 2014 21:41
Simple iframe shortcode for wordpress
add_shortcode('iframe', 'iframe');
function iframe($atts) {
extract(shortcode_atts(array(
'src' => "",
'width' => "800",
'height' => "600"
), $atts));
$iframe = '<iframe src="'.$src.'" width="'.$width.'" height="'.$height.'" scrolling="no" allowtransparency="yes" frameborder="0" ></iframe>';
@codescribblr
codescribblr / Snipplr-71283.js
Created February 13, 2014 21:41
JavaScript: Safe console.log usage in all browsers
// make it safe to use console.log always
(function(a){function b(){}for(var c="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),d;!!(d=c.pop());){a[d]=a[d]||b;}})
(function(){try{console.log();return window.console;}catch(a){return (window.console={});}}());
@codescribblr
codescribblr / Snipplr-69773.js
Created February 13, 2014 21:41
JavaScript: Reset tabindex on pageload
$(function(){
var tabindex = 1;
$('input,select').each(function() {
if (this.type != "hidden") {
var $input = $(this);
$input.attr("tabindex", tabindex);
tabindex++;
}
});
});
@codescribblr
codescribblr / Snipplr-70522.js
Created February 13, 2014 21:41
JavaScript: placeholder replacement
$(document).ready(function() {
if(!Modernizr.input.placeholder){
$("input").each(function(){
if($(this).val()=="" && $(this).attr("placeholder")!=""){
$(this).val($(this).attr("placeholder"));
$(this).focus(function(){
if($(this).val()==$(this).attr("placeholder")) $(this).val("");
});
$(this).blur(function(){
if($(this).val()=="") $(this).val($(this).attr("placeholder"));
@codescribblr
codescribblr / Snipplr-63258.txt
Created February 13, 2014 21:41
Pagination using twitter bootstrap styles
<?php
// Set the current page at 1 if it's not already set
if(!isset($_GET['p'])){$_GET['p']=1;}
$per_page = 100;
$count_transactions = count($transactions);
$pages = ceil($count_transactions / $per_page);
$current_page = (isset($_GET['p'])) ? $_GET['p'] : 1;
$clean_query_string = (isset($_GET['user_id'])) ? str_ireplace("p=".@$_GET['p']."&", "", $_SERVER['QUERY_STRING']) : str_ireplace("p=".@$_GET['p'], "", $_SERVER['QUERY_STRING']);
if(substr($clean_query_string,-1)=="&"){$clean_query_string = substr_replace($clean_query_string, "", -1);}
@codescribblr
codescribblr / Snipplr-70525.txt
Created February 13, 2014 21:41
Javascript touch events from click
function touchHandler(event)
{
var touches = event.changedTouches,
first = touches[0],
type = "";
switch(event.type)
{
case "touchstart": type = "mousedown"; break;
case "touchmove": type="mousemove"; break;
@codescribblr
codescribblr / Snipplr-58662.txt
Created February 13, 2014 21:41
Javascript (jQuery) markup for saef in expression engine
<script type="text/javascript">
// <![CDATA[
$(document).ready( function() {
//URL Title js
$("input#title").keyup( function() {
var titleText = $("input#title").val().replace(/ /g,"_").toLowerCase();
$("input#url_title").val(titleText);
});