How to show the Git branch in the Linux prompt

In pictures

How to go from this…

… to this?

Short answer

We will be changing your .bashrc file. It is located in your home.

  1. Make a save of your .bashrc file (one is never too careful; cp -p .bashrc .bashrc.sav).
  2. Optional step: make your prompt colored by uncommenting the highlighted line:

  1. Now locate the last line of the following excerpt and edit the previous lines accordingly to the following line:

  1. Restart your prompt, you’re done.

Something more detailed

Continue reading How to show the Git branch in the Linux prompt

How to make a regex pattern that matches except if…

Short answer

We will take an example: match all /* ... */-type comments except when in string (in our example: JavaScript, so both single and double quotes will have to be excluded).

  1. Write the regex for what you want to match (later called m; our example: /\*.*?\*/1).
  2. Write the regular expressions for matching your exclusions (later called e1, e2, e3; our example: '[^']+' and "[^"]+").

Regex #1

  1. Write your final regex: e1|e2|(m) (our example: '[^']+'|"[^"]+"|(/\*.*?\*/)).
  2. Match group 1 instead of matching group 0.

Note: This requires code to parse the result. If you need something simple (sed? Which you would replace with a Perl command? Or just something you can use with match), see below.

Regex #2: alternative for Perl and PCRE (PHP)

  1. Write your final regex: (?:e1|e2)(*SKIP)(?!)|m (our example: (?:'[^']+'|"[^"]+")(*SKIP)(?!)|/\*.*?\*/).
  2. Match group 0 as usual.

Note: You can execute this expression as a Perl command: perl -pe '(?:\'[^\']+\'|"[^"]+")(*SKIP)(?!)|/\*.*?\*/'

You can test the regex and have it explained at this link.

Something more detailed

Continue reading How to make a regex pattern that matches except if…

How to prevent IE from messing with console.log

Short answer

  1. Add the following before any use of console.log:

    Or (which is OK with JSHint’s undef rule):

    Or make a log function that will not add a potentially useless object and that you will use instead of console.log:

    (or just make sure you do not use console.log)

Something more detailed

Continue reading How to prevent IE from messing with console.log

How to download a plugin-free Eclipse platform

Short answer

  1. Go to the dedicated download page.
  2. Select the version you want and click it (column: Build Name).
  3. Go to the Platform Runtime Binary section (available in the table of contents or by adding #PlatformRuntime at the end of your URL).
  4. Click the runtime corresponding to your OS.

Something more detailed

Continue reading How to download a plugin-free Eclipse platform

How to determine the best implementation of a Java method

Short answer

  1. Write alternative versions of the method you want to test. They should be named as the original, and suffixed with an index. The rest of the signature must not change.
  2. Download the java-implementation-comparer project from Github.
  3. Build it to add it to your local Maven repository: mvn install
  4. Create a test project importing both:
    • the project you want to test;
    • thejava-implementation-comparer:
  5. Create a test class and write the little code you need:
  6. Just enjoy your comparison:

Something more detailed

Continue reading How to determine the best implementation of a Java method