Programming

11 Articles

GIST – GREP

 

# Search recursive case insensitive and show line before and after
grep -iR -B 1 -A 1 "searchterm" ./

# Search recursive case insensitive but show file name instead of matching line
grep -liR "searchterm" ./

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.

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!

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