Skip to content

Instantly share code, notes, and snippets.

View davidkryzaniak's full-sized avatar

David Kryzaniak davidkryzaniak

View GitHub Profile
@davidkryzaniak
davidkryzaniak / gist:4046850
Last active October 12, 2015 15:18
PHP Explode VS Unserialize (Who's Faster?)
<?php
//This is the list of elements. There are 500 items in this array.
/* From PHP.net */
function convert($size){
$unit=array('b','kb','mb','gb','tb','pb');
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
@davidkryzaniak
davidkryzaniak / responsive.html
Created December 1, 2012 04:43
Responsive Image Download Test
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Created by: David Kryzaniak (http://dave.kz/) -->
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title></title>
<style>
/* Please don't download this ever. */
@davidkryzaniak
davidkryzaniak / example-filter-val.php
Created December 5, 2012 19:33
Example of filter_var()
<?php
//Lists the available filters you can select from
print_r(filter_list());
//returns 100000000.10
echo filter_var("$100,000,000.10", FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
//returns -23423
echo filter_var("-2,3423.2343", FILTER_SANITIZE_NUMBER_FLOAT);
@davidkryzaniak
davidkryzaniak / cookiemonster.php
Last active December 13, 2015 20:28
Test to see if Googlebot can set and get cookies
<?php
$expire=time()+1468800;//14days
$cookieName='CookieMonster';
$cookieData='Chocolate Chip';
if(isset($_COOKIE[$cookieName])){
echo "Yep, cookie found!";
}else{
echo "No cookie here! Let me bake one up for you...";
setcookie($cookieName,$cookieData,$expire);
@davidkryzaniak
davidkryzaniak / gist:5109218
Created March 7, 2013 16:18
Articles Plugin for MODx
//inside both create.js and update.js
xtype: 'superboxselect'
,fieldLabel: _('articles.article_tags')
,description: _('articles.article_tags_help')
,name: 'tags'
,id: 'modx-resource-tags'
,anchor: '100%'
,store: [
['Tag 1','Tag 1'],
@davidkryzaniak
davidkryzaniak / RemoveAddMediaButtonsForNonAdmins.php
Created July 18, 2013 16:26
Remove "Add Media" Buttons For Non-Admins
function RemoveAddMediaButtonsForNonAdmins(){
if ( !current_user_can( 'level_10' ) ) {
remove_action( 'media_buttons', 'media_buttons' );
}
}
add_action('admin_head', 'RemoveAddMediaButtonsForNonAdmins');
@davidkryzaniak
davidkryzaniak / shortcode.class.php
Last active December 20, 2015 00:48
Generic WP ShortCode Boilerplate (OOP)
<?php
/**
* Plugin Name: ShortCode
*
* Usage: [MyShortcode]
*/
class myShortCode {
public function __construct(){
@davidkryzaniak
davidkryzaniak / gist:6982961
Created October 14, 2013 22:01
FargoPHP - Getting started
<?php
//Get the class
require_once('FargoPHP/FargoPHP.class.php');
//Create a new FargoPHP object.
//Takes in the IP address (or DNS/Domain name) of the Fargo. Do not include the "http://" or the ending /
//Username, Password
$myFargo = new FargoPHP('192.168.1.34','admin','admin');
@davidkryzaniak
davidkryzaniak / gist:6983007
Last active December 25, 2015 13:19
FargoPHP getting started
<?PHP
//shutoff all relays
$myFargo->setAllTo(FALSE);
//change the state of relay #1
$myFargo->relayFlipState(1); //#1 is now ON
//change the state of relay #0 (Labeled "Relay1" on the board)
echo "Relay #0 is currently: ".($myFargo->relayFlipState(0) ? 'On' : 'Off'); //#0 is now ON
@davidkryzaniak
davidkryzaniak / test.php
Last active December 26, 2015 03:39
WP Shortcode example
<?php
//add the shortcode
add_shortcode(
'testgetusers', //name of the shortcode [getusers]
'sample1' //the function associated with the shortcode ( get_site_users() )
);
function sample1($attributes,$content){
//make sure there is a value for each attribute