Thursday, May 28, 2015

Tuesday, May 5, 2015

Pebble Time Development: Code Examples

Here are some places where you can find official and unofficial code examples and libraries for development of apps and watchfaces for the Pebble Time, along with links to the SDK/CloudPebble to get started:

(Note: this was written 5/5/2015. Things may have changed since then.)

Wednesday, April 29, 2015

Finding Files by Name That Contain/Don't Contain a String in a Bash Script

When trying to find things, sometimes I use the IDE, but most of the time I drop down to terminal.

Today I needed to find persistence.xml files that weren't in Maven target directories that required a classname.

Easy right? Without a script it's not bad.

To find files named persistence.xml containing ".MyClassName" and where target is not in the path:

find . -name 'persistence.xml' -exec grep -H -il '.MyClassName' {} \; | grep -v target

and to find files named persistence.xml not containing ".MyClassName" and where target is not in the path:

find . -name 'persistence.xml' -exec grep -H -iL '.MyClassName' {} \; | grep -v target

However, I thought I'd create a script to make this easier in the future.

It gets a little tricky to use arguments passed into a bash script along with find -exec grep, especially if you need to escape anything like a dot/period in the grep.

The idea is that you need to use "sh -c" since find exec uses exec and not a shell, and you want variable expansion to use the variable you passed in (e.g. $1), but then you have to pass in the variable and the argument passed from find to exec, which is the pathname of the found file.

Here's an example solution:

#!/bin/bash
while test $# -ne 1; do
  echo "Usage: findinpersistencexml MyClassName"
  echo
  echo "Finds the persistence.xml files that do and do not contain the specified unqualified classname."
  test "$1" = "-h" || test "$1" = "--help" && exit 0 || exit 1
done

echo "persistence.xml with ${1}:"
find . -name 'persistence.xml' \
  -exec sh -c \
  "grep -H -il \\\\.$1 {}" "{}" "$1" \; \
  | grep -v target
echo
echo "persistence.xml without ${1}:"
find . -name 'persistence.xml' \
  -exec sh -c \
  "grep -H -iL \\\\.$1 {}" "{}" "$1" \; \
  | grep -v target
If you wanted to also look for </class at the end and use single quotes around that:

#!/bin/bash
while test $# -ne 1; do
  echo "Usage: findinpersistencexml MyClassName"
  echo
  echo "Finds the persistence.xml files that do and do not contain the specified unqualified classname."
  test "$1" = "-h" || test "$1" = "--help" && exit 0 || exit 1
done

echo "persistence.xml with ${1}:"
find . -name 'persistence.xml' \
  -exec sh -c \
  "grep -H -il '.$1</class' {}" "{}" "$1" \; \
  | grep -v target
echo
echo "persistence.xml without ${1}:"
find . -name 'persistence.xml' \
  -exec sh -c \
  "grep -H -iL '.$1</class' {}" "{}" "$1" \; \
  | grep -v target

Thursday, April 9, 2015

Uninstall git-scm.com's Git and Use Homebrew's Instead

It looks like git_osx_installer provided by git-scm.com is no longer being maintained and the Homebrew version is. Here's how to fix that:

  1. Uninstall the git installed by this installer (command from here):

    sudo rm -rf /usr/local/git/ /usr/bin/git /etc/paths.d/git /etc/manpaths.d/git
    

  2. Install homebrew, if you haven't, and:

    brew update
    brew install git
    
  3. Fix any paths/etc. that you might have that dependent on the other git, if any.
  4. Restart Terminal.app.

When you want to upgrade, whenever homebrew updates git (and it seems to stay up-to-date recently), you can do:

brew upgrade git

To update the Git and Git Flow completion and your Git prompt as I described previously to work with Homebrew Git, assuming you have installed git flow and git flow completion, you can put this in your ~/.bashrc or ~/.bash_profile:

# git provided by homebrew
source /usr/local/etc/bash_completion.d/git-completion.bash
# if fails, do find /usr/local/Cellar -name git-flow-completion.bash to find path and set it here
source /usr/local/Cellar/git-flow-avh/1.8.0/etc/bash_completion.d/git-flow-completion.bash
source /usr/local/etc/bash_completion.d/git-prompt.sh
PS1='\h:\W$(__git_ps1 " (%s)") \u\$ ';

YouTube's Server Error

Got the interesting YouTube error page this morning:



Here are a few examples:

AB38WEPc79JrLN6fF1ntQSQr28W2w_keNTQrM3cpqqFsTgvDiR1Kxd3andpd
kjtWdJPpB9YRcZjNi7ngIEYPX5iHiuhpa7AsDK_tbT_pxooM-sADx6jeQ_Q8
h9nuUo-q0xr7n0cEWm58qvzsrLvf0oQ24_eV0ugTcxksqA-YNwk90E5Oz9je
a8DRk16M7wvCZK6IYCp2u05cGuqPzDJYOStNlcoJaLSEEjWRAvc6zkIkF1_V
1OBopyEWmmBveg8BXVWBf03CtJGl-4kGfvLbpGjXxsNGKztbY0tlbukbtBXW
s0JVmkRzcMDRwMwiyaWjFy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bLhzgzd_2ohvj9xUWR4RBFYMQih0A8mBXVBbHBSN_Fan7bZzUWpF6Qx
LbM-wR5ttvtoJre7gN1vKi6L3v0oxQFkGgJBB9hgD-dET7h9nJRQTBN9hmAB
-uQ8Yzd9yTIDkYNZ4As7flq5auXuK2J-VWnhBaEg_O98phEI6g_7teV0iJ5-
HyFtgwnOyK18lZUNZq0QXQBST7yo7PjlByR3BIiKgppgqrBFJTr0xnlLQ4uk
ggutkRZnVFwFkO-HXvT1gm5MxZlgHb46TJSt42Q_0-SJZf_8PXdfQUy5M7_9
hsAzAU_dAYhmBLet1TIL-M4MLAHEZK_2mLNr6IdhLKaQWBHAiPFS_G2SoIS0
_kD6hlSEaivJ9wgb80QzqpigpKxzD7d9Zd7YfjxCE5NfU-xCC-Oxrj-uOtN3
SEZpgKX3u-CPfAHYT0Kmkw7mMO5BAbPZgz_4647b8M-8k6M1nOeE6vneW3bP
rYL9LorE0lOZVJOxl6oR3rBDnewsOp55pqxhnk44vqKBg89MED83yeuGoO0J
dGkBCiq5do8N1hieja0fCyxwOaIstPN2G7BVX2BcOCvVa5yUaMDDE6hxnong
VhNC9qs9H5dYLmATKyCjHS62A8mroZxXC2lf6L0I7-Dv9dHF0TcynBgHXtcq
RDp6e_1ORrFKoakE5ppXAIvQd0vUIvK203fFF2fzcqFub58Us1LzAVqf2wYH
ho8wHm8vwg1MaNlHeaQwkBk5miaRd3_RIsMhF1-iYw
(2116 characters)

It's an interesting way to provide an error.

Monday, April 6, 2015

Finding Git Hotspots or Author Code Experience with a One-liner

On StackOverflow, sometime ago I shared the following command that can help identify the files in a git repo that a certain author has worked with more than others, as part of an attempt what that author had experience working in:

git log --name-only --author="David Heinemeier Hansson" --pretty=format: | sort | uniq -c | sort -nr

And, today, I saw that bugspots was a trending Ruby gem in GitHub, which was based on info from Bug Prediction at Google which in turn was based on work by Foyzur Rahman, Daryl Posnett, Abram Hindle, Earl Barr, and Premkumar Devanbu of UC Davis. I looked and what bugspots currently does is to find messages containing the regexp "/\b(fix(es|ed)?|close(s|d)?)\b/i" to determine what are "hotspots" in the code that were changed more often when fixing bugs.

I quickly modified my one-liner and now have something that can find the files that have been checked in most with the commit message containing "fix". This can help identify "hotspots" for bugs/support-related changes:

git log --name-only --grep="fix" --pretty=format: | sort | uniq -c | sort -nr