Skip to content

Instantly share code, notes, and snippets.

View JoeSz's full-sized avatar

Joe JoeSz

View GitHub Profile
<?php
function minify_css( $buffer ) {
if( trim( $buffer ) === "") return $buffer;
// Remove comments
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
// Remove whitespace
$buffer = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $buffer);
@JoeSz
JoeSz / debounce.js
Created September 24, 2016 11:36
JavaScript debounce function
/**
* @link https://davidwalsh.name/javascript-debounce-function
*
* Here's the basic JavaScript debounce function (as taken from Underscore.js):
*/
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
@JoeSz
JoeSz / debounce.min.js
Created September 24, 2016 11:37
JavaScript debounce function minfied and compressed version
function debounce(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}
@JoeSz
JoeSz / onElementHeightChange.js
Created September 24, 2016 14:29
Detect Element Height Change (eg. Window)
// Source: http://stackoverflow.com/questions/14866775/detect-document-height-change
var $j = jQuery.noConflict();
$j( document ).ready(function($) {
function onElementHeightChange(elm, callback){
var lastHeight = elm.clientHeight, newHeight;
(function run(){
newHeight = elm.clientHeight;
if( lastHeight != newHeight )
callback();
@JoeSz
JoeSz / throttle.js
Last active September 28, 2016 10:20
JavaScript Throttle
// Returns a function, that, when invoked, will only be triggered at most once
// during a given window of time.
// Source: https://gist.github.com/killersean/6742f98122d1207cf3bd
function throttle(callback, limit, callbackArgs) {
var wait = false;
return function() {
if (wait) {
return;
}
callback.call(callbackArgs);
@JoeSz
JoeSz / ie.css
Created September 30, 2016 15:31
Apply style ONLY on IE
/* Source: http://stackoverflow.com/questions/11173106/apply-style-only-on-ie/36448860#36448860 */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
#myElement {
/* Enter your style code */
}
}
@JoeSz
JoeSz / timedInterval.js
Last active October 7, 2016 14:43
Timed Interval
/**
* timedInterval
*
* The method calls a function or evaluates an expression at specified intervals (in milliseconds)
* until a specified number of milliseconds.
*
* @param {Function} callback
* @param {int} interval - run every [interval] ms
* @param {int} expiration - run until [expiration] in ms
* @param {mixed} callbackArgs - arguments for callback function
@JoeSz
JoeSz / html5.sublime-snippet
Created October 19, 2016 09:43
Basic HTML5 boilerplate for Sublime Text 2
<snippet>
<!-- put this file in /packages/User/<Folder Name>/html5.sublime-snippet then restart your Sublime Text 2 -->
<content><![CDATA[<!doctype html>
<html lang="en">
<head>
<!--
ToDo: HTML, CSS, JS -> concatenate and minify for production
- JavaScript: https://jscompress.com/
@JoeSz
JoeSz / console_log.sublime-snippet
Last active October 19, 2016 09:45 — forked from hzlzh/gist:3128038
console.log() snippet for Sublime Text 2
<snippet>
<!-- put this file in /packages/User/<Folder Name>/console_log.sublime-snippet then restart your Sublime Text 2 -->
<content><![CDATA[console.log( '$1' );$0]]></content>
<tabTrigger>conl</tabTrigger>
<scope>text.html,source.js</scope>
<description>console.log()</description>
</snippet>
<snippet>
<!-- put this in another file /packages/User/<Folder Name>/console_dir.sublime-snippet then restart your Sublime Text 2 -->
@JoeSz
JoeSz / jquery.sublime-snippet
Last active October 19, 2016 09:53
Basic jQuery boilerplate for Sublime Text 2
<snippet>
<!-- put this file in /packages/User/<Folder Name>/jquery.sublime-snippet then restart your Sublime Text 2 -->
<content><![CDATA[
/**
* This gist demonstrates how to properly load jQuery within the context of WordPress-targeted JavaScript so that you don't
* have to worry about using things such as 'noConflict' or creating your own reference to the jQuery function.
*
* @version 1.1
*
* ToDo: concatenate and minify for production -> https://jscompress.com/