Blog

Remove ‘type’ attribute in Drupal 7 – Say goodbye style, script & link!

Here’s a quick tip to remove the type attribute in Drupal 7 to make your site more HTML5 code compliant. This along with other HTML5 features allows for less code on the front-end… and who doesn’t like less code?!

No longer do you need to include this attribute in your script, style and link tags. As an added bonus, this Drupal hook will also remove CDATA comments. They only existed to satisfy the XHTML validator and it too has gone away with the release of HTML5.

Continue reading “Remove ‘type’ attribute in Drupal 7 – Say goodbye style, script & link!”

PHP Stock Market API

Here’s a quick API script I put together to help monitor my stocks. It’s a PHP Stock Market API that uses the Yahoo! Finance API and allows you to retrieve up to 20 current data points for a particular symbol. It’s simple to use and doesn’t require any knowledge on how to implement or use the Yahoo! Finance API.

Looking to grab the latest stock market data? There’s a surprising lack of stock market APIs out there and even fewer that work consistently or affordable. Never fear, the PHP Stock Market API is here!

The PHP Stock Market API is a simple PHP class that uses the Yahoo! Finance API allowing you to retrieve up to 20 current data points for a particular symbol. It’s simple to implement and doesn’t require you to learn how to use the Yahoo! API.

UPDATE (Nov. 28, 2014, v1.3): getData now allows an array to pull multiple stocks at once (thanks @d3vit).
UPDATE (Jan. 27, 2014, v1.2): You can now also retrieve historical data (open, high, low, close, volume & adjusted close).

Download Now (Version 1.3) Fork on GitHub


PHP Stock Market API Usage

With just a few lines of code, you can easily retrieve 20 current data points. Here’s how it works:

<?php
require_once('class.stockMarketAPI.php');
?>

<h1>Current Stock Information for AAPL</h1>

<?php
$StockMarketAPI = new StockMarketAPI;
$StockMarketAPI->symbol = 'AAPL';
?>
<pre><?php print_r($StockMarketAPI->getData());?></pre>

<?php
$start = '01-01-2013';
$end = '01-07-2013';
?>
<h1>Historical Stock Information for AAPL (<?php echo $start ?> - <?php echo $end ?>)</h1>
<?php
$StockMarketAPI = new StockMarketAPI;
$StockMarketAPI->symbol = 'AAPL';
$StockMarketAPI->history = array(
  'start'    => $start,
  'end'    => $end,
  'interval' => 'd' // Daily
);
?>
<pre><?php print_r($StockMarketAPI->getData());?></pre>

<hr>

<h1>Stock Information for AAPL, MSFT, GOOGL</h1>
<?php
$StockMarketAPI = new StockMarketAPI;
$StockMarketAPI->symbol = array('AAPL', 'MSFT', 'GOOGL');
?>
<pre><?php print_r($StockMarketAPI->getData());?></pre>

Drupal Behaviors: A Quick Introduction & How-to

I’m fairly new to Drupal myself and came across something called Drupal Behaviors when I was working over at BioWare Austin. A fellow Drupal developer whom was part of the team, Ivan Fuyivara, gave a presentation on what they were and how to use them. Being a complete greenhorn at Drupal then, I was a little foggy on the concept and didn’t really understand. Now with a year of Drupal dev under my belt, a better understanding on how to do things the ‘Drupal way’, and an opportunity to work on a re-theme project at Stratfor Global Intelligence, I had the opportunity to put this feature into practice.

Here’s a quick introduction on what Drupal Behaviors are and how to use them. Feel free to critique or tell me I’m completely wrong here… in no way am I claiming to be a Drupal expert. You can also read more (though not too much info) on Drupal.org.

Continue reading “Drupal Behaviors: A Quick Introduction & How-to”

Useful Git Delete Branch Commands

Want to delete a branch in GitHub? It’s a simple operation.

Need to delete a branch in GitHub? It’s a simple operation and keeping your repo clean & tidy is incredibly important in any project. In this post, I’ll show you how to:


Delete a Local GitHub Branch

$ git branch -d yourbranch
Deleted branch yourbranch (was 2a4ef7)

Depending if you already have unmerged commits in the branch you’re trying to delete, you may see this error:

error: The branch 'my-branch' is not fully merged.
If you are sure you want to delete it, run 'git branch -D my-branch'.

This protects you from losing your reference to those commits, which means you would effectively lose access to that entire line of development. If you really want to delete the branch (e.g., it’s a failed experiment), you can use the capital -D flag:

$ git branch -D yourbranch
Deleted branch yourbranch (was 2a4ef7)

This is the command to use if you want to permanently throw away all of the commits associated with a particular line of development.


Delete a Remote GitHub Branch

As of Git v1.7.0, you can delete a remote branch using:

$ git push origin --delete yourbranch

Previous to Git v1.7.0, you can use:

$ git push origin :yourbranch

Delete Merged Branches

Through time as you create and merge branches, you’ll want to delete the one’s no longer needed. In order to delete local branches which have already been merged, run:

$ git branch --merged master | grep -v "\*master" | xargs -n 1 git branch -d

You can omit the master branch argument to remove local branches which have already been merged into the current HEAD:

$ git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

For more information, see Git Clean: Delete Already-Merged Branches.


Delete All Branches Except Master

If you’re like me, you leave branches laying around, even after they’ve been merged into master. The sad part is GitHub even provides a button to do the cleanup, but I can’t be bothered. So when you’re ready to do some real cleanup on a repository, run this command to delete every branch in your local except for the master branch.

git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/^/git branch -d /' | bash

Recover a Deleted GitHub Branch

What if you accidentally deleted a branch or just need to recover one that’s been deleted? Not a problem. Use the following to find the HEAD commit of the deleted branch to get it back:

$ git fsck --full --no-reflogs | grep commit
dangling commit 609bb956bc9ef1b43c0w6af60fa009e37be0566d
dangling commit 608bb956bc9ef1b43c0g4af60fa0e9e34be0566d
dangling commit 708bb956bc9ef1b43c0wdaf60fa000e99be0566d
dangling commit 402bb956bc9ef1b43c0d4af60fa001e87be0566d

Then do a git show to find the commit you want to recover:

git show 609bb956bc9ef1b43c0w6af60fa009e37be0566d

Once you found the commit you want, do a git branch to recover the branch:

git branch 609bb956bc9ef1b43c0w6af60fa009e37be0566d

Simple stuff!

Mozscape API PHP Class

Mozscape’s API is a little daunting to use with the amount of valuable information it can offer. Here’s a simple PHP class that allows you to easily access your site’s SEO metrics using the Mozscape API. A major benefit to the Mozscape API PHP Class is the ability to return detailed information on the response fields Mozscape provides.

Features


Implementation

It’s pretty simple to use this class. Currently it’s pretty limited to the data it can provide in relation to what’s available through Mozscape’s API, but I do have plans on adding the rest of the available APIs later on.

That’s it, pretty simple huh?

Documentation

Here’s more detailed information on how to use the class. If you have any questions or suggestions, I’d love to hear them.

Mozscape URL Metrics API

urlMetrics($site_url, $sum_of_bit_flags)

To access the Mozscape URL Metrics API, you just need to provide the URL you want to retrieve data for and the type of data you want (the total sum of Bit Flags).

Mozscape Response Fields

responseFields($field, $return_value = '')

This is a great helper to get information on the various response fields that the Mozscape API provides, including the bit flag values, user-friendly names, slugs, and descriptions! See more information on Mozscape’s Response Fields here: https://moz.com/help/guides/moz-api/mozscape/api-reference/response-fields.

Mozscape Top Pages API

topPages($url, $offset = 0, $limit = 1000, $bits = 4)

This paid call returns the metrics about many URLs on a given subdomain. The top pages call can be accessed by the API call top-pages. A set of metrics can be requested by indicating them as bit flags in the $bits parameter. A page of urls with associated metrics is returned. The start record of the page can be specified using the $offset parameter. The size of the page can by specified using the $limit parameter. URLs are currently sorted by number of linking root domains.

A maximum of 1000 records can be retrieved per call. Limits over this value will result in a 400 Bad Request or 500 Internal Error response.

Currently only 10,000 pages may be retrieved using top-pages calls, in at least 10 calls.

See more on Mozscape’s Top Pages API here: http://apiwiki.seomoz.org/top-pages-api

Mozscape Required Attribution Link

attributionLink($type, $size, $img_dir = 'img/mozscape/')

This is good to use to stay compliant with the required Mozscape API’s attribution links. Provides easy output using their approved logo or icon with the required link.


Change Log

Version 1.1

  • Created a changelog file
  • Added an error message if the Curl request to the Mozscape API failed
  • Added the Mozscape Metadata API Calls
  • Added the Mozscape Top Pages API