Insidethe.com It is my space, but better than myspace

8Mar/210

RegEx To Find Lines Containing Text and Exclude Matches Containing Text

 

This is an example of how to do a find in files with PhpStorm or WebStorm but exclude lines matching a specific string.

For example, give this code below, we want to find all lines that contain the http://example.com/api but do not also contain the string 'some_variable'

$my_url = variable_get("some_variable", "http://example.com/api");
...
$my_url = 'http://example.com/api';

The RegEx pattern will find all lines that contain the URL but exclude the lines with the specified text:

^(?!.*some_variable.*$).*(http:\/\/example.com\/api)

This should work in any JetBrains editor which supports Java regular expressions.

Filed under: Programming No Comments
26Jun/140

NetBeans 8 Navigator Empty or Blank When viewing Drupal PHP Files

It was exciting to see NetBeans 8 released as I use it as my primary editor for PHP projects (along with Xdebug of course) but the excitement was short lived when the navigator window frame was empty for all of my Drupal project files. After a bit of googling and checking the NetBeans bug tracker I wasn't getting anywhere until I tried one last ditch generic search on Google which held the answer.

According to this blog posting it was discovered that the .install and .module files lose their content type and aren't parsed as PHP files. A simple configuration change to set the correct content type fixes the issue. Wonderful!

Filed under: Programming, Tech No Comments
19May/140

Create a Bookmark that Always Points to Today’s Freshbooks Timesheet

Do you want to access your freshbooks timesheet with as few clicks as possible? The directions below walk you through creating a dynamic JavaScript based bookmark that will always point to todays Freshbooks timesheet by calculating the correct URL to go to.

Creating such a link on your browser's bookmark bar or favorites list can be a time saving step for quickly logging in and recording your time.  To create the link follow these steps:

  1. Locate your Freshbooks domain by logging into Freshbooks account and looking at the address bar. The highlighted text in the image below indicates where your freshbooks domain is located in the URL.finding your freshbooks domain
  2. Copy the text below. This is the dynamic JavaScript URL which will always point to your Freshbooks timesheet:
    javascript: var dt = new Date();var d=dt.getDate();var m=dt.getMonth()+1;var y=dt.getFullYear();window.location='https://YOURFRESHBOOKSDOMAIN.freshbooks.com/timesheet#date/'+y+ "-" + (m<=9 ? '0' + m : m) + "-" + (d <= 9 ? '0' + d : d);
  3. Right click on the bookmark bar and create a new bookmark.
  4. Paste the text into the bookmark URL field:creating freshbooks timesheet bookmark
  5. Before saving the bookmark you must change the URL text "YOURFRESHBOOKSDOMAIN" with the Freshbooks domain found in step one. For example, if your domain was "mycoolcorpinc" the URL should read:
    javascript: var dt = new Date();var d=dt.getDate();var m=dt.getMonth()+1;var y=dt.getFullYear();window.location='https://mycoolcorpinc.freshbooks.com/timesheet#date/'+y+ "-" + (m<=9 ? '0' + m : m) + "-" + (d <= 9 ? '0' + d : d);
  6. Save the bookmark. You should now have a bookmark link or favorite that points you to the current day timesheet.

Click on the new bookmark and the browser will direct you to your freshbooks account and compute the current date of the timesheet to display. Your address should resemble the image below except 'yourfreshbooksdomain' will be replaced with your domain i.e. mycoolcorpinc and the date on the end of the URL will be today's date.

freshbooks timesheet url example

 

 

Filed under: Programming, Tech No Comments
15Apr/140

Coding Tips from Writing Code that isn’t Needed YouTube Video

The above video,Three Flaws in Software Design - Part 1: Writing Code that isn't Needed, was a bit long considering the content presented but there were two ideas worth sharing:

  1. Let the version control system worry about tracking dead code. I've worked in plenty of programs with code that I've been tempted to bypass because it was suspected dead code. Removing the suspected dead code might not cause the customers testing to fail but customers don't always test their own requirements properly. Without the old code it becomes difficult to track how the program once functions unless you use a version control system. Whats worse than trying to avoid making dead code? Working around mysterious code from a long departed coder, unsure if it's still relevant, while trying to make my own logic clear among rotting bits.
  2. Establish when functions can assume variables are well formatted and note them in the function documentation. It's so easy to start coding away, checking for possible conditions that might have been checked closer to the user input. It's painfully agonizing trying to return a high level validation failure from a very low level function.

If the addition videos in the series contain any pearls of wisdom they'll get posted here.

Filed under: Programming No Comments
18Apr/100

International Spectrum Article

The company I work with contributes to International Spectrum. The publication serves the multi-value database community with news and new technologies. It was my pleasure to contribute an article. The second part of the two-part article was recently featured in the publication.

The article demonstrates how BASIC-like languages can be extended using the object oriented programming (OOP) concept of encapsulation to protect private variables. The article covers benefits and provides examples of how these modern concepts can further benefit non-OOP languages.

First part
http://www.intl-spectrum.com/mag/MARAPR.2010/default.aspx

Second part
http://www.intl-spectrum.com/mag/JANFEB.2010/default.aspx

The entire magazine is available for PDF download. No registration required.

Filed under: Programming No Comments