Installing Chrome Extensions Without Signing in With a Google Account

Google requires that you login with a Google account before you can install any Chrome extensions.

The following is how to install an extension without logging in (under Windows.  The same should work under Linux and Mac):

  1. Find the ID for the extension.  When you browse the extension in the store you will see a URL similar to the following:  https://chrome.google.com/webstore/detail/cookies/iphcomljdfghbkdcfndaijbokpgddeno?hl=en.   The hash string after the ‘cookies’ string (the name of the extension) up to the ? is the id.
  2. Download the .crx extension file.  Use the following URL and replace the <ID> string with the ID for your extension:  https://clients2.google.com/service/update2/crx?response=redirect&x=id%3D<ID>%26uc.  Chrome will complain that the extension cannot be added from this site.  Just ignore/OK it and you will be able to download it.
  3. Download and install (if you don’t already have it) 7zip.
  4. Create a directory and move the .crx file into it.  Go into that dir, rename the .crx file to .zip and use 7zip to extract the file.
  5. Then back in chrome enter the following URL:  chrome://extensions/
  6. Towards the top-right of the page, check the “Developer Mode” checkbox.
  7. Then click on the “Load unpacked extension…” button and navigate to the directory that contains the unpacked .crx file and select it and it should install the extension for you.

Removing The Last N Character From a String in Bash Script with sed

Here is a quick one-liner for trimming a specific number of characters from the end of a string under bash:

# Remove the last 5 characters
$ echo "somestringwith12345" | sed "s/.....$//g"
$ somestringwith

# Remove the last 3 characters
$ echo "somestringwith12345" | sed "s/...$//g"
$ somestringwith12

Splitting a String in Bash on the FIRST Occurrence of a Character

About a year ago I posted an article about how to split into an array of values based on a given delimiter in bash.

The following is how to take that same string and split it on the first occurrence of the same user defined delimiter.

Both use the ‘read’ command, but in a slightly different way.

Instead of passing read the -a [aname] parameter which tells it that “The words are assigned to sequential indices of the array variable aname, starting at 0.”, we pass is -r which indicates that “Backslash does not act as an escape character.  The backslash is considered to be part of the line.”.  This will make sure to include any backslash that is in the string in your output.

Then, we provide two variables into which we will store the split string.

#!/bin/bash

SOURCE_STRING='foo|blah|moo'

# Save the initial Interal Field Separator
OIFS="$IFS"

# Set the IFS to a custom delimiter
IFS='|'

read -r KEY VALUE <<< "${SOURCE_STRING}"
echo "KEY = $KEY, VALUE = $VALUE"

# Reset original IFS
IFS="$OIFS"

BASH Script With Default Arguments Defined in The Script

Often times you will want to write a BASH script where you don’t want to have to keep track of all of the positional command line arguments and/or you might want to configure it with a set of environmental variables while having a default value for each in the script.

Following is the syntax for declaring them in the shell script, and then an example on how to invoke it.

#!/bin/bash

: ${ARG1:="somedefault_arg1"}
: ${ARG2:="10"}

echo "ARG1 = $ARG1"
echo "ARG2 = $ARG2"

$ ./default-bash-vars.sh
ARG1 = somedefault_arg1
ARG2 = 10
$ ARG1="someOtherArg1" ARG2="20" ./default-bash-vars.sh
ARG1 = someOtherArg1
ARG2 = 20

In the example script, we have two variables, ARG1 and ARG2.  When running the script without providing any additional configuration the default values will be used.  When invoking it and defining the variables on the command line prior to executing the script those values will be used instead.

This prevents the situation where you potentially have many command-line arguments and then have to jugle the positional $1, $2, …. vars in the script.

Unable to Set the Path To java.exe When Running Oracle SQL Developer Under Windows 7

I was trying to run Oracle SQL Developer for the first time on a new machine.  When firing it up, it presented me with a dialog box asking me to “Enter the full pathname for the java.exe file”.

OK, no problem.  So I find the path to the java.exe binary that was just installed with the SDK.  Hit submit . . . and nothing happens.  It blanks out the text field and the dialog box stares back at me.

I tried pointing it to the java.exe that was in the jre dir.  No joy.

After a lot of futzing around and doing some searches it turns out that there are a few things that you have to do to get it to run for the first time.

First, right-click on the Oracle SQL Developer short-cut and select “Run as Administrator”.

Then, in the dialog box, click Browse and navigate to the JDK that comes with the Oracle install.  For me it was in C:\Oracle11G\11.2.0.3\jdk\bin\java.exe

Once I did that it fired right up.  I then quit, and ran it as my user and it seemed to start up just fine.

Pin a “Show Desktop” Link to the Task Bar in Windows 7

To create a short cut and pin it to the task bar in Windows 7 do the following:

  1. Right-click on the Desktop and select New -> Shortcut.
  2. Enter the following in the field labeled “Type the location of the item:”  %windir%\explorer.exe shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257}
  3. Click “Next” and name the shortcut and then click “Finish”.
  4. Update the icon so that you will recognize it when you pin it to the task bar.  To do so, right-click on the shortcut and select “Change Icon”
  5. Paste the following in the “Look for icons in this file”  %SystemRoot%\system32\imageres.dll
  6. Select an appropriate icon and click “Apply” and then “OK”.
  7. Right-click on the icon and select “Pin to Taskbar”.

Running Dynamically Generated Hive Queries From a Shell Script

If you want to write a HQL hive query and run it mulitple times from a shell script, each time passing it different data for the query, here is a quick example that should get you started.

The first thing to know is that by specifying n number of -hivevar key value pairs when invoking hive on the command line will allow you to pass that data into the hive process.

For example, if you do the following

$ hive -e 'SELECT * FROM some_table' -hivevar FOO=blah

You will have passed in a key of FOO with the value of ‘blah’ to the hive process.

A more practical example would be wanting to run the same hive query over multiple data partitions.

In this example, I’ve got a hive database that has a ‘packets’ table partitioned by hours which looks like 2014032601.

The hive query file (dest_ip_hive.sql) would look like:

SELECT packets.sourceip FROM packets
WHERE packets.destip = "${hivevar:DEST_IP}"
AND packets.hour = ${hivevar:HOUR}
GROUP BY packets.sourceip

And a shell script that would dynamically set those values for each invocation of hive would look like:

#!/bin/bash

#
# Destination IP that we are using to determine which
# packets we will examine.
#
DEST_IP="10.0.1.10"

for HOUR in 2014032209 2014032210 2014032211 2014032212
do

   echo "Running hive query for HOUR $HOUR"

   # Run a hive query from the command line setting variables that will be
   # expaned in the .sql file.
   hive -hivevar HOUR=$HOUR -hivevar DEST_IP=$DEST_IP \
   -f dest_ip_hive.sql > ${DEST_IP}-{$HOUR}.out

done

For each hour defined in the for loop, we will execute a hive command telling it to run the query contained in the file dest_ip_hive.sql.  The DEST_IP and HOUR variables that will be expanded in the query are passed to hive via the

-hivevar HOUR=$HOUR -hivevar DEST_IP=$DEST_IP

part of the hive command.  And the output for each query will be written to a different file for each query.

Eclipse Android Development Error executing aapt: Cannot run program “/path/to/aapt”: error=2, No such file or directory: error=2, No such file or directory

Even though the ADT bundle provides a 64 bit version, the system requirements indicate that “64-bit distributions must be capable of running 32-bit applications.”  I failed to see that when installing it under Fedora Core 20 and was getting the following error from Eclipse:

Error executing aapt: Cannot run program "/home/rchapin/sdks/adt-bundle-linux-x86_64-20131030/sdk/build-tools/android-4.4/aapt": error=2, No such file or directory: error=2, No such file or directory  android_sdk    line 1   Android ADT Problem

I checked to see if the file was there.  Yep.  I checked to see if was executable.  Yep.

It was only after finding a blog post about it and doing a file command on it that I noticed that it was a 32 bit executable:

file adt-bundle-linux-x86_64-20131030/sdk/build-tools/android-4.4/aapt 
adt-bundle-linux-x86_64-20131030/sdk/build-tools/android-4.4/aapt: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, not stripped

All I had to do was install the 32 bit libraries that the binaries are linked against:

yum install glibc.i686 zlib.i686 libstdc++.i686 ncurses-libs.i686 libgcc.i686

Once installed, the error should disappear from Eclipse as it tries to invoke the binaries and do a regular build and/or restarting or cleaning the project should clear the errors.