Skip to content

Instantly share code, notes, and snippets.

View Braunson's full-sized avatar

Braunson Yager Braunson

View GitHub Profile
@ashrewdmint
ashrewdmint / gist:277528
Created January 14, 2010 21:33
Smart character limit functions for PHP
// Intelligently truncate a string to a certain number of characters.
// Each uppercase or wider-than-normal character reduces the final length.
function truncate($string, $length, $ellipsis = true) {
// Count all the uppercase and other wider-than-normal characters
$wide = strlen(preg_replace('/[^A-Z0-9_@#%$&]/', '', $string));
// Reduce the length accordingly
$length = round($length - $wide * 0.2);
@boogah
boogah / WP_Bag_of_Tricks.txt
Created April 30, 2010 00:51
Things I've learned by being a WordPress nerd.
WP Bag of Tricks
1. Helpful Scripts/Plugins:
Hacks:
http://wordpress.org/extend/plugins/tac/
http://wordpress.org/extend/plugins/exploit-scanner/ (Can be extremely resource intensive.)
http://wordpress.org/extend/plugins/wp-malwatch/
@dahnielson
dahnielson / UUID.php
Last active May 31, 2024 23:54
Pure PHP UUID generator
<?php
/**
* UUID class
*
* The following class generates VALID RFC 4122 COMPLIANT
* Universally Unique IDentifiers (UUID) version 3, 4 and 5.
*
* UUIDs generated validates using OSSP UUID Tool, and output
* for named-based UUIDs are exactly the same. This is a pure
* PHP implementation.
@jakebellacera
jakebellacera / ICS.php
Last active June 2, 2024 02:20
A convenient script to generate iCalendar (.ics) files on the fly in PHP.
<?php
/**
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
@chicagoworks
chicagoworks / jQuery.stringify.js
Created December 24, 2010 19:05
jQuery.stringify() utility
/**
* converted stringify() to jQuery plugin.
* serializes a simple object to a JSON formatted string.
* Note: stringify() is different from jQuery.serialize() which URLEncodes form elements
* UPDATES:
* Added a fix to skip over Object.prototype members added by the prototype.js library
* USAGE:
* jQuery.ajax({
@scribu
scribu / debug_filters.php
Created January 26, 2011 10:45
debug_filters()
<?php
/**
* @param string $tag The hook name
*/
function debug_filters( $tag = false ) {
global $wp_filter;
if ( $tag ) {
$hook[ $tag ] = $wp_filter[ $tag ];
@jorgepedret
jorgepedret / gist:1016695
Created June 9, 2011 13:07
Gravity Forms Custom Fields
<?php
add_action("gform_field_input", "ih_gform_field_input", 10, 5);
function ih_gform_field_input($input, $field, $value, $lead_id, $form_id){
//wp_debug($field);
if($field["type"] == "vehicleyear"){
//wp_debug($field['choices']);
//$input = 'Aha!';
}
return $input;
}
@jcsrb
jcsrb / gist:1081548
Created July 13, 2011 23:05
get avatar from google profiles, facebook, gravatar, twitter, tumblr
function get_avatar_from_service(service, userid, size) {
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
// everything else will go to the fallback
// google and gravatar scale the avatar to any site, others will guided to the next best version
@mloberg
mloberg / mysql.php
Created August 30, 2011 18:00
Simple PHP MySQL Class
<?php
class Mysql{
static private $link = null;
static private $info = array(
'last_query' => null,
'num_rows' => null,
'insert_id' => null
);
@thinkphp
thinkphp / gist:1448754
Created December 8, 2011 21:44
Binary Search Tree Implementation in PHP
<?php
/**
* by Adrian Statescu <adrian@thinkphp.ro>
* Twitter: @thinkphp
* G+ : http://gplus.to/thinkphp
* MIT Style License
*/