Skip to content

Instantly share code, notes, and snippets.

View kkemple's full-sized avatar

Kurt Kemple kkemple

View GitHub Profile
@kkemple
kkemple / jqPubSub.js
Last active December 29, 2015 14:29
quick pub/sub with jQuery
/**
* Create an observer pattern for jQuery
* allows you to alias trigger with publish,
* on with subscribe,
* and off with unsubcsribe
* Useful for custom events
*
*USAGE:
* $(el).subscribe('customEvent', function() {
* do something when customEvent is published
@kkemple
kkemple / sudo-checkbox.js
Created November 27, 2013 23:08
code to create a sudo checkbox, this way you can add any styling you like
/**
* author kkemple@pixafy.com
*/
(function( $ ) {
$('body').on('click', '.check-style', function() {
var self = $( this );
var checkbox = self.children( 'input[type="checkbox"]' );
if( $( checkbox ).prop('checked') ) {
$( checkbox ).prop( 'checked', false );
@kkemple
kkemple / getstaticblock.php
Created November 27, 2013 23:06
code snippet for getting a static blocks in Magento
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('identifier')->toHtml() ?>
@kkemple
kkemple / jqKonami.js
Created November 27, 2013 23:09
allows you to execute code after client correctly enters konami code
;(function( $, window, document, undefined ) {
var keys = [],
konami = '38,38,40,40,37,39,37,39,66,65',
timer = 0;
$( document ).keydown(function( e ) {
keys.push( e.keyCode );
if ( keys.toString().indexOf( konami ) >= 0 ){
// do something when the konami code is executed
@kkemple
kkemple / dumpAndDie.php
Created November 27, 2013 23:11
this allows you to var dump anything with code styling then dies
function dd( $anything )
{
echo '<pre>';
var_dump( $anything );
echo '</pre>';
die(0);
}
@kkemple
kkemple / gaq.js
Created November 27, 2013 23:12
Google analytic code
<script>
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
@kkemple
kkemple / rAF.js
Created December 7, 2013 02:01 — forked from paulirish/rAF.js
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@kkemple
kkemple / chromeJSeditor
Created December 8, 2013 07:19
save as a bookmark to have an on the fly js syntax highlighted text editor (ace)
data:text/html, <style type="text/css">#js-editor{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="js-editor"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var jsEditor=ace.edit("js-editor");jsEditor.setTheme("ace/theme/monokai");jsEditor.getSession().setMode("ace/mode/javascript");</script>
import request from 'superagent'
import Promise from 'bluebird'
Promise.config({ cancellation: true })
export function get(url, {
headers: headers = {},
query: query = {},
progress: progress = () => {},
} = {}) {
@kkemple
kkemple / consolefix.js
Created January 8, 2014 15:51
Fix to prevent errors in browsers with no console
// Avoid `console` errors in browsers that lack a console.
(function() {
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
];