Allow Access Origin in PHP – Page Specific

I have come accross it a few times where I need to test a JS call using XHR to a certain backend php page for some JSON data. But you run into this annoying CORS error. Get around it for testing or add this to a specific php page to be able to call it from a local host or outside hosts.


$http_origin = $_SERVER['HTTP_ORIGIN'];

if ($http_origin == "http://localhost:8888")
header("Access-Control-Allow-Origin: $http_origin");

Weekly Snippet: Ionic & Xampp = Build Error & Platform Add

So this took me way to long to figure out, before I finally came across some short comments about it. I added one to the forums for Ionic, but I think if you’re like me, you hop between projects and when you come back, you might forget this one little edit in your .bash_profile and then all your development time turns back into setup time.

So here it is – From Terminal
$ sudo nano ~/.bash_profile

Then from here, you will see several
export MONGO_PATH=/usr/local/mongodb
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"

Comment out the line that is “bold” that represents your xampp or lamp server, and then you will need to quit your terminal and then run sudo ionic build and you shouldn’t have any errors.

Weekly Snippet: May 1, 2015

I have missed placing a few snippets, oops. Been a crazy past few weeks. I wanted to add a pretty basic one, but one I find myself constantly needing for building systems that need a time measurement element.

Javascript Snippet for Months – Short and Long

'use strict';

	var mL = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
	var mS = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
	d.prototype.getLongMonth = d.getLongMonth = function getLongMonth (inMonth) {
		return, inMonth, mL);
	d.prototype.getShortMonth = d.getShortMonth = function getShortMonth (inMonth) {
		return, inMonth, mS);
	function gM(inMonth, arr){
		var m;
		if(this instanceof d){
			m = this.getMonth();
		else if(typeof inMonth !== 'undefined') {
			m = parseInt(inMonth,10) - 1; // Subtract 1 to start January at zero

		return arr[m];

var today = new Date();

Courtesy of Stackoverflow

Weekly Snippet – Fixing your URL Schema after Migrating WordPress

Just run this SQL command once you’re logged into your MySQL database and you will have successfully made all of your old urls into the new one after a migration. This is something that can be forgotten easily, and has you scratching your head why don’t your urls work properly.

UPDATE wp_posts SET guid = REPLACE(guid,'http:://','http:://');

Note: If you have absolute urls in your post_content under wp_posts, the best way is to export the table, open your .sql file in Sublime, and do a find & replace, and then re-upload your table for wp-posts.

Weekly Snippet – Getting URL Parameters with Javascript

Traditionally, you use some backend processing language to grab your URL snippets, or for most front-end, maybe it’s PHP. Here is a nifty function, that I found on Stackoverflow that has helped me incorporate grabbing url parameters easily with my front-end websites/applications.

function getUrlParameter(sParam)
    var sPageURL =;
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) 
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) 
            return sParameterName[1];

An example of this in use would be:

var tech = getUrlParameter('technology');

Command of the Week – Find Folder in Ubuntu Linux

locate foldername | grep /foldername$

Yes, it will be a life saver at some point.

Margin & Padding Sass Mixin Trick

Spacing has always bothered me with all of touchups of padding, margin, etc, I wanted one way to input it. So I came up with this mixin that has saved me loads of time.

$xs : 10px;
$small : 25px;
$medium : 50px;
$large : 75px;
$xlarge : 100px;
$xxlarge: 150px;

@mixin space($type, $direction:all, $amount:$xs){
	@if $type == padding {
		@if $direction == all{
			padding: $amount;
		} @else if $direction == top {
		} @else if $direction == left {
		} @else if $direction == right {
		} @else {
	} @else {
		@if $direction == all{
			margin: $amount;
		} @else if $direction == top {
		} @else if $direction == left {
		} @else if $direction == right {
		} @else {

Using the mixin in your .scss file..

      @include space(margin, top, $medium);

Devops: Helpful Terminal Commands such as top, dig, and tail

Becoming better at Devops is something I seemed to always need through my career. As I continued to dive deeper and deeper on my work projects. I quickly realized how helpful so many little commands were that I never even knew about.

Some of these I learned pretty quickly, such as ssh, scp, and git. Others have taken a little longer and I learned from working closely with a Devops Badass.

Terminal Commands


I think one of the things we tend to forget at times, or not thing about looking at is the Manual that comes with most basic linux commands such as top, dig, etc. You can easily see the manual for commands by typing man (service name). Example: man top.


As simple as you think it is, top is amazingly helpful. This can be used to tell you how the CPU is being used and by what processes. This helps to determine if a process is over bloating your CPU with commands.

Simply ssh into a machine or just in terminal on your mac. Type top.
You will see this.

Using man top you can learn additional ways to use top such as typing “u” when you are in the top view. You can then define processes by users.


Dig gives you helpful information about a server/website. Such as the ip address of the A name in the DNS, or the CNAME if it’s based on a CNAME. It also can be used to keep dive into the Name-servers that you currently have your domain setup at.
Example Output:


One that many people might already know, as I think it’s one of the first commands you learn when you start working with servers. The importance of monitoring logs or changing files. The command tail can be used with -f to continuously monitor for the new logs that are appended.

This comes very helpful when monitoring while a server might be having problems, or a web page error that is thrown, or even an api failure. Typing tail -f xxx.log. You can monitor a log.

Example of access.log

A New Day – Salesforce Development

SOQL. Salesforce Developer Toolkit. So many places to start with development for Salesforce. Much like many of the things I have learned, it has come from a need to learn it.

My chosen poison for my current need will be to work with the PHP Toolkit and run SOQL queries to produce some charting, and reports that we have been unable to on a Salesforce team I work with.

My starting point will be the SalesForce PHP github repository:

In all honesty, I am quite anxious to learn more about Salesforce development and their devious tricks. So many things in Salesforce that are annoying to users are often taken care of from Modules on the AppExchange market. Which if you have ever used, then you know, can cost you a arm & leg in fees, rather it be a simple online license purchase or a more complicated annual contract purchase. Some of these services do several basic things you could actually do just within the Salesforce Developer console with SOQL. But sadly due to the leverage of most Salesforce Administrators not being Developers. They PAY!

It’s time to dive into this mess and aim for the buck to flow the other way.

I will be most likely documenting and pushing a tutorial out for a getting started and use cases on once we have made headway on our use case  and once I get my paws around this fur ball.

Launch Directory in Sublime from Terminal (Command Line)

Making it easier for yourself. Launch Sublime from the command line. Using this easy gist. You can find instructions in the gist.

Here is an example video of it in action. Loving it!