Skip to content

Instantly share code, notes, and snippets.

@infn8
infn8 / README.md
Last active August 29, 2015 14:13
WP Livereload trigger

Add these files to your theme and ensure that your grunt or gulp or whatever is watching the php files in your theme folder for changes and triggering live reload.

Ensure that yoursite.dev has the live reload script at http://yoursite.dev:35729/livereload.js which it likely will if you're using grunt watch right. If Not edit the livereload-loader.js file to point to the right place where the file is.

@infn8
infn8 / force-login.php
Created December 9, 2014 21:26
Wordpress Force Login
<?php
if (!is_user_logged_in()) {
wp_login_form();
wp_die('you need to login' );
}
?>
@infn8
infn8 / cc_spaces.fn.js
Created December 9, 2014 19:03
Credit Card Spaces
function cc_spaces(txt){
// rip all non digits from string
txt = txt.toString().replace(/[^\d]/g, '');
format = /(\d{1,4})/g;
// test for amex.
if (null !== txt.match(/^3[47]/)) {
format = /(\d{1,4})(\d{1,6})?(\d{1,5})?/;
@infn8
infn8 / swapDev.bookmark
Created November 11, 2014 16:22
Bookmarklet to swap between whatever.com and whatever.dev
javascript:(function(){parts = location.host.split('.'); last = parts.pop(); replace = last == 'dev' ? 'com' : 'dev'; parts.push(replace); location.host= parts.join('.'); })();
*~
/rsync*
.DS_Store
.svn
.cvs
*.bak
*.swp
Thumbs.db
.sass-cache/
*.log
@infn8
infn8 / cascade_values.fn.php
Last active August 29, 2015 14:08
Pass an array of items and the first one that is not empty will be returned to you
<?php
function cascade_values(){
for ($i = 0; $i < func_num_args(); $i++) {
$val = func_get_arg($i);
if(!empty($val)){
return $val;
}
}
return false;
}
@infn8
infn8 / Default (OSX).sublime-keymap
Created October 5, 2014 04:08
Sublime Text Bootstrap Shortcuts and Snippets
[
{ "keys": ["super+shift+alt+b", "super+shift+alt+o", "super+shift+alt+x"], "command": "insert_snippet", "args": {"name": "Packages/User/bcxo.sublime-snippet"}},
{ "keys": ["super+shift+alt+b", "super+shift+alt+x"], "command": "insert_snippet", "args": {"name": "Packages/User/bcx.sublime-snippet"}},
{ "keys": ["super+shift+alt+b", "super+shift+alt+o", "super+shift+alt+s"], "command": "insert_snippet", "args": {"name": "Packages/User/bcso.sublime-snippet"}},
{ "keys": ["super+shift+alt+b", "super+shift+alt+s"], "command": "insert_snippet", "args": {"name": "Packages/User/bcs.sublime-snippet"}},
{ "keys": ["super+shift+alt+b", "super+shift+alt+o", "super+shift+alt+m"], "command": "insert_snippet", "args": {"name": "Packages/User/bcmo.sublime-snippet"}},
{ "keys": ["super+shift+alt+b", "super+shift+alt+m"], "command": "insert_snippet", "args": {"name": "Packages/User/bcm.sublime-snippet"}},
{ "keys": ["super+shift+alt+b", "super+shift+alt+o", "super+shift+alt+l"], "command": "insert_snippet", "args": {"n
@infn8
infn8 / clearAllTimers.js
Created September 10, 2014 19:48
Clear All JS Timers
tempID = window.setTimeout(function() {}, 0);
while (tempID--) {
window.clearTimeout(tempID); // will do nothing if no timeout with tempID is present
}
tempID = window.setInterval(function() {}, 0);
while (tempID--) {
window.clearInterval(tempID); // will do nothing if no interval with tempID is present
}
@infn8
infn8 / Modernizr.canvasblending.js
Last active August 29, 2015 14:06
Modernizer Canvas Blend Modes
Modernizr.addTest('canvasblending', function() {
if (Modernizr.canvas === false) return false;
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
ctx.globalCompositeOperation = 'screen';
return ctx.globalCompositeOperation === 'screen';
});
@infn8
infn8 / wordpress_import_set_authors.js
Last active November 25, 2016 21:09
Ever import a Wordpress eXtended RSS file and get sick of setting all the authors in the import file to all the SAME authors in your site? if so open your console and run this code.
jQuery('ol#authors li').each(function(index, el) {
var $, theName, parts, theOption, theID;
$ = jQuery;
theName = $(this).find('strong').text();
parts = theName.split('(');
theName = parts[0];
theID = parts[1].replace(')', '').trim();
theOption = $(this).find('select option:contains(' + theName.trim() + ')');
if(theOption.length){
$(this).find('select').val(theOption.val());