Skip to content

Instantly share code, notes, and snippets.

View fabrizim's full-sized avatar

fabrizim

View GitHub Profile
@fabrizim
fabrizim / events.js
Created January 2, 2012 16:34
Simple Custom Event Mixin
function EventMixin(Target){
var listeners = {};
var methods = {
emit : function(ev){
if( !listeners[ev] ) return;
var ar = listeners[ev];
var args = [].slice.call(arguments, 1);
for(var i=0; i<ar.length; i++) ar[i].apply(this, args);
},
@fabrizim
fabrizim / events-example.js
Created January 2, 2012 17:32
Example using Simple Event Mixin
/**
* A quick example of how to use Simple events on an arbitrary javascript class.
*/
var Cat = function(){
var self = this;
this.on('hairball', function(){
self.throwup();
});
};
@fabrizim
fabrizim / fabs_linkify.php
Created September 5, 2012 13:30
PHP Autolink Text
function fabs_linkify($str){
$re = "/(([a-z0-9\$\-\_\.\+\!\*'\(\)\,]+)\@)?((https?\:\/\/)?(www\.)?([a-z0-9\$\-\_\.\+\!\*'\(\)\,\/]+)\.(com|org|net|gov|us|tv)(\/[a-z0-9\$\-\_\.\+\!\*'\(\)\,\/]+)?)/i";
return preg_replace_callback($re, 'fabs_linkify_callback', $str);
}
function fabs_linkify_callback($matches){
if( $matches[1] ) {
return '<a href="mailto:'.$matches[0].'">'.$matches[0].'</a>';
}
else{
@fabrizim
fabrizim / gist:3753720
Created September 20, 2012 03:03
General CSS With Variables for Scratch Customization
/* Import Fonts */
@import url("http://fonts.googleapis.com/css?family=Petit+Formal+Script");
/* Customization variables */
// general
// bg colors
@bg_color: #444;
// buttons
@fabrizim
fabrizim / haversine_distance
Created May 13, 2013 02:36
Haversine Algorithm in Javascript
function haversine_distance(lat1,lat2,R){
R = R || 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
@fabrizim
fabrizim / gist:6523731
Created September 11, 2013 13:36
_inner_html replacement to work with < PHP 5.3.6
/**
* innerHTML style function
*
* @param DOMNode node
* @returns string the inner html string
*/
protected function _inner_html( $node )
{
$doc = new DOMDocument('1.0','utf-8');
@fabrizim
fabrizim / gist:6525184
Last active December 22, 2015 20:19
single-faculty.php
<?php
global $post;
wp_enqueue_script('department-popovers');
the_post();
get_header();
get_sidebar('breadcrumbs');
$model = Snap::inst('WSE_Model_Faculty')->load( get_the_ID() );
@fabrizim
fabrizim / gist:6829389
Last active December 24, 2015 16:39
Use wp-less to process editor stylesheets.
<?php
add_filter('mce_css', 'theme_mce_less');
function theme_mce_less($css)
{
$handle = 'editor';
$less_plugin = WPLessPlugin::getInstance();
wp_enqueue_style($handle, get_stylesheet_directory_uri()."/assets/stylesheets/editor.less");
$less_plugin->processStylesheets();
global $wp_styles;
@fabrizim
fabrizim / .htaccess
Last active December 27, 2015 18:49
RewriteRule ^(.+\.axd.*) ./proxy/index.php [NC,L]
RewriteRule ^((images|Documentation|DesktopModules|tabid/(364|622|623|624|625|626|627|628|650)|(P|p)ortals|Scripts|Developers|js|Home/Login|Gizmox/Store|Gizmox/Solutions|Gizmox/Landing)/.*) ./proxy/index.php [L]
@fabrizim
fabrizim / acf-customizer-patch.php
Last active January 17, 2024 02:30
Plugin to allow for Advanced Custom Fields to be used in widgets within the Customizer
<?php
/*
Plugin Name: ACF Customizer Patch
Plugin URI: https://gist.github.com/fabrizim/9c0f36365f20705f7f73
Description: A class to allow acf widget fields to be stored with normal widget settings and allow for use in customizer.
Author: Mark Fabrizio
Version: 1.0
Author URI: http://owlwatch.com/
*/
class acf_customizer_patch