Fixing the Dreaded “SyntaxError: Unexpected Token in JSON”

If you’re seeing a SyntaxError: Unexpected token < in JSON at position 0 error in your browser console at angular.js:13920, or Line 13920 or angular.min.js, then it’s likely that you’re working with HTTP API’s, possibly using $resource or $http, and…

Auto Indent HTML in Sublime Text on Save

If you’re tired of manually re-formatting, indenting, structuring or beautifying HTML code in Sublime Text then you can use the following approach to automatically indent HTML files when you Save. Manual Auto-indent for HTML Based on common questions the following…

Markdown Filter for Timber/Twig

Markdown is a wonderful way to write content on the web, it’s what I use to write every blog article you see here on kevinleary.net. While working with Upstatement’s Timber plugin I came across a situation where I wanted to…

Change a WordPress Plugin’s Menu Name

If you want to change the wording of an admin menu inside of WordPress without editing the plugin directly you can make use of the $menu global variable that exists within the WordPress admin. Manipulating this data structure will allow…

Building an Angular.js App in a WordPress Plugin

The tutorial will show you how to setup and work with Angular.js inside of a WordPress plugin to create a stand-alone, API powered, Angular.js single page app or microsite that is available at a defined path of a WordPress website.…

Git Remotes for an Existing Heroku App

I find myself doing this all the time, so I wanted to make note of the snippet here for anyone else commonly looking to add a Git remote for an existing Heroku app using the Heroku CLI. Open up your…

Seonix.org WordPress Redirect Hack

I picked up a strange issue on my WordPress site today while reviewing stats in Google Search Console. I noticed a malicious 301 redirect happening for an old post, one that had no redirect rules set. Specifically the post had…

Regex Routes in Express.js

If you want to use regex for an Express.js route rule then you must use a JS regular expression object instead if string by wrapping your regular expression in slashes (/) instead of quotes (“). To look at a common…

Angular $http Cache Examples

Angular’s built-in $http service and it’s $http.get() method do NOT cache responses by default. There are a few different ways you can enable $http caching, below are some helpful examples of each. These examples are ordered in terms of difficult,…

Angular.js Custom Tag Delimiter’s

Angular’s templating system is wonderful, and it build’s on some common practices established years ago by the Handlebars templating engine. Sometimes I encounter projects where an existing templating system conflicts with Angular, such as a server-side templating language like Mozilla’s…

Restrict an Angular.js Directive to a Specific HTML Tag

This is the best way I’ve found to create an Angular.js directive that’s restricted to a specific HTML element or tag. There’s no directive configuration option in Angular.js to do this, but I recommend adding the `restrict: ‘A’` to your directives config so that it only matches an attribute name. Once we have that in place the key aspect that makes this happen is this line: if ( element[ 0 ].tagName !== “A” ) { … }

How to Fix Slow Gulp Uglify Builds

I use gulp-uglify to minify my JavaScript for a large Angular.js project. Recently the compile process became incredibly slow, taking upwards of 15 seconds to compile JavaScript each. I’m convinced there is an underlying issue here, but for now I was able to solve the issue using a filesystem cache. This reduced a the JS build task with Uglify from 15-20 secs down to 500ms-1.5secs.

Preventing Possible Attempt to Enumerate Users [SOLVED]

What is User Enumeration? WordPress websites may reveal whether a username exists on system through the author query variable. When a web app leaks information about whether a username exists or doesn’t exist, this is called user enumeration. A common…

WordPress Database Migration & Transfer Tools

As of 2017 here are the two best ways I’ve found to handle the transfer of a WordPress database from development to production. WP Migrate DB Pro The WP Migrate DB Pro WordPress plugin will let you push, pull, and…