Monday, October 4, 2010

Unable to connect Samsung Vibrant to App Inventor on Ubuntu9.04

The good news is that almost 2.5 months after I applied for access to Google Android App Inventor, I got the access on 1st October.

Now the bad news is that I am unable to connect my Samsung Galaxy S Vibrant to App Inventor on my machine running Ubuntu 9.04. Here is what I have tried till now after installing App Inventor Extras software for Linux:

I ensured the below settings were done before connecting the phone:
  1. Settings > Applications > Unknown sources is checked
  2. Settings > Applications > Development > USB debugging is checked
  3. Settings > Applications > Development > Stay awake is checked
  4. Settings > Sound and display > Orientation is un-checked

On connecting the phone, I see the USB Icon which mentions that USB is connected and also a Red exclamation alert icon mentioning that USB debugging is connected. I also ensured that OpenJDK is also not installed on my machine as that is known to cause clashes with Android SDK.

Then I opened a shell, logged in as root (using sudo -s) and then did the following:

# lsusb | grep 'Sam'
Bus 001 Device 003: ID 04e8:681c Samsung Electronics Co., Ltd 
# vi /etc/udev/rules.d/51-android.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="681c", MODE="0666"

Now rebooted the machine and again with sudo -s, ran the following commands:

# /etc/init.d/udev restart
 * Stopping kernel event manager...                                      [ OK ]
 * Starting kernel event manager...                                      [ OK ]
# cd /usr/google/appinventor-extras/commands-for-Appinventor
# ./adb kill-server
# ./adb devices
* daemon not running. starting it now *
* daemon started successfully *
List of devices attached

# ./adb usb
error: device not found


I tried the above sequence of steps with these versions of UDEV rules as well, but to no avail:
# vi /etc/udev/rules.d/51-android.rules
SUBSYSTEMS=="usb", SYSFS{idVendor}=="04e8", MODE="0666"

and

# vi /etc/udev/rules.d/51-android.rules
SUBSYSTEMS=="usb_device", SYSFS{idVendor}=="04e8", MODE="0666"


Here is the log from the Java console:

Creating the REPL controller
Changing the REPL communication button text to Communicating...
Disabling REPL communication button.
********* Actually invoking CreateAndSend
Restarting repl controller (true)
ReplController sending (begin (require com.google.youngandroid.runtime)  (setup-repl-environment "<<" ":" "@@" "Success" "Failure" "=="">>" '((">>""&2")("<<""&1")("&""&0"))))
**** devicesPluggedIn: 0 isPluggedIn: false connectionHappy: false
************************** commIndicator was unexpectedly
connected!!!! COMMUNICATING
Changing REPL communication button to Connect.
Re-enabling REPL communication button.
Communication with REPL failed: java.io.IOException: App Inventor
cannot find any phones.
Please plug in a phone and try again.

I am at a loss as to what else to check as all these steps are a compilation of the knowledge in the google groups as well as other blogs on the topic. If anyone has any ideas/pointers/suggestions, please let me know - Thanks.

Wednesday, September 22, 2010

How to use Syntax Highlighter 3 in Blogger

Syntax Highlighter version 3.0.83 has been released and there are quite a few changes in the way things work now. I realized this when the rendering on this site broke after I modified it to use the latest release. So, here is the steps required to setup the "hosted" version of the latest Syntax Highlighter (version 3.0.83) and integrate with your Blogger/Blogspot blog.

Installation

  1. Navigate to Dashboard > Design > Edit HTML
  2. Backup the current template by clicking on the link Download Full Template
  3. In the textarea, press CTRL+F to find the code </head>
  4. Copy the below code and paste it just above
    <!-- Syntax Highlighter Additions START -->
    <link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
    <link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
    
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
    
    <script language='javascript' type='text/javascript'>
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
    </script>
    <!-- Syntax Highlighter Additions END -->
    
  5. Preview your changes and make modifications as required
  6. Save the template

In the above code, I have put in brushes for the languages that I use frequently. Modify the brushes according to your needs - check the full list of supported brushes here and use whichever you need.

Configuration

Apart from choosing the brushes that you need, there are other configuration parameters that you can setup as well. Check out the details here. More useful ones are the ones that allow you to change the starting line number, highlight specific lines, disable auto-linking of URLs and html-script option to highlight mixture of HTML/XML code.

Apart from these configuration changes, you can change the theme as well. SyntaxHighlighter comes bundled with 7 themes and I personally like the default one. However, you can choose the theme that you fancy the most by simply replacing the name of the theme in this line:
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>

So you can replace shThemeDefault in the above line with any one of the following themes:
  1. Django - shThemeDjango
  2. Eclipse - shThemeEclipse
  3. Emacs - shThemeEmacs
  4. Fade to Grey - shThemeFadeToGrey
  5. Midnight - shThemeMidnight
  6. RDark - shThemeRDark

Usage

To use it in your blog post, there are a couple of things that need to be done.
  1. Escape all code by replacing any occurrences of:
    1. < with &lt;
    2. > with &gt;
  2. Enclose the escaped code between <pre class="brush:[brush_name];[optional_params]"> and </pre>
  3. Setup the proper brush name (based on the code being highlighted) in the opening pre tag. Using the correct brush will ensure proper highlighting of the code

New Features in 3.0.83

The new version brings with it quite a few new features - here's an overview:
  • Auto-Loading of Brushes

    Now all the brushes need not be pre-loaded on every page. You can load only the required brushes on the pages that need those brushes. Use the shAutoloader.js and then load the brushes as required
    For more details on using this feature, check out the instructions here. Note that this might not be so useful for a blogger account as we do not modify the javascript for each page/post.
  • No usage of Flash

    Earlier, Flash was being used to copy the code to clipboard. This has now been removed and a simpler & better way to do this has been implemented. Also, the user can now simply double-click anywhere in the code to select it and then use the standard CTRL+C to copy it.
  • Code copy without line numbers

    Now the copied code excludes line numbers and the extra leading tabs/spaces to make it usable directly - very convenient!
  • Add Title

    Now you can add a title to the code block by title="[title_name]"
parameter to the pre tag.

  • More under the hood

    More improvements and changes under the hood like better CSS support, easier integration with CommonJS & node.js, etc.
  • Monday, September 20, 2010

    Search & replace text in multiple files in Unix

    To search a particular string in multiple files and replace all occurrences with a new string, you can use the following handy Perl one-liner:

    perl -pi -e 's#search_string#replace_string#g' *.php
    

    Here, the -p switch wraps the script inside a loop, executing once for each input file which is denoted by the last arguement *.php.

    The -i switch allows inline modification of the file; you can optionally save a backup of the original file by providing the backup file name template after this switch as -i *.bak.

    The -e switch executes the following piece of code.

    The string of code 's#search_string#replace_string#g' searches for search_string and replaces it with replace_string globally. You can use any other character like "/" to delimit the search & replace strings. Remember to replace the place-holder text with the actual text and also escape it properly.

    Friday, September 17, 2010

    Extend battery life on Samsung Vibrant

    Here are a few tips / tricks to extend the battery life on Samsung Vibrant and any Android based phones. Of course, cutting down on many of these aspects may reduce the quality of experience that you have with the phone, so there's always a give-and-take involved. However you can definitely turn-off those features that you don't use so that you can have the full-fledged experience of the phone as well as a better battery life!

    1. Switch off GPS
    If you are not using any location aware services, maps or navigation, then turn off the GPS radio. GPS radios generally use a lot of juice and if you are not using the feature, no point in letting it consume battery.

    2. Switch off Wi-Fi
    If you are on the move and not using Wi-Fi, then turn it off as Wi-Fi radios can eat up a lot of power as well.

    3. Switch off Bluetooth
    If you are not using Bluetooth, then turn it off. Switched on Bluetooth transciever that is not being used is another major culprit for draining the battery in all phones that have bluetooth, not just the Samsung Vibrant.

    4. Adjust & Optimize Display Setting
    Reduce the brightness of the screen and decrease the screen time-out (the amount of time the phone waits to turn the display off if there is no activity). Display is the major consumer of battery resources hence using it in a controlled manner will provide astonishing results.

    5. Increase Synchronization intervals
    Increase the gap between synchronization intervals or set them to synchronize on demand instead of a time interval. Apps for social networks, emails that use "polling" instead of "push", weather, news, etc. are major culprits for such unwarranted usage of battery.

    6. Install Apps to Kill unwanted tasks
    Note: this may be risky / complicated depending on which app(s) are installed and how they are used.
    For Android 2.1, you can install JuiceDefender to intelligently manage & control how apps use battery.
    You can also install & use Advanced Task Killer to kill apps that don't close after you have exited from them. Apps that keep running in the background even after you have exited from them can also drain the battery.

    7. Remove Dynamic Wall Papers
    Dynamic / Live Wall Papers and similar apps can also eat into the battery very fast - disable such apps to increase available battery.

    8. Turn off Vibrate / Haptic Feedback
    A small motor spins at a high speed to create the Vibration / Haptic Feedback buzz. This obviously takes a lot of power, so switching it off can save quite a bit.

    9. Switch to Flight mode in areas of no cell coverage
    Switch to Flight mode in areas where there is no cell coverage to conserve battery. When there is no cell coverage, generally the signal strength is boosted to see if any towers can be reached and the polling interval also increases. Switching to Flight mode switches off the radios saving the battery from drain out.


    Note: These are also generally applicable for all other (smart) phones too based on whether they have the below mentioned features.

    Friday, July 16, 2010

    Interview Tips

    Came across a few good articles on how to prepare for interviews especially aimed at Google. These make very good reads even if you are not planning on attending any interviews any time soon!

    Upgrade Drupal

    Drupal core could get updates due to security / bug fixes / patches and it is very important that your installation of Drupal be kept updated in this regard. Here are the steps needed to updgrade a Drupal installation:
    1. Backup current data
    2. Download & unzip update file
    3. Disable all contributed modules
    4. Revert theme to a core theme
    5. Delete all old files
    6. Upload new files
    7. Copy over the backed up folders
    8. Re-enable contributed modules
    9. Run update.php script
    10. Re-apply custom theme

    Now lets discuss each of the above steps in a bit of detail:

    1. Backup current data
    Backup your installation database using phpMyAdmin or any other suitable tool.
    Backup the files and sites folders

    2. Download & unzip update file
    Download files for the upgrade and extract the contents to a temporary folder. On Ubuntu, I just double-click on the file to do this. On WinX platforms, this cannot be done directly - you will need to download & install the free & open source tool 7-Zip to do this. Now you should have the full install files extracted into your chosen temporary folder.

    3. Disable all contributed modules
    Log in to the Drupal admin and go to Administer > Site building > Modules or the Drupal path admin/build/modules. Disable all the contributed modules.

    4. Revert custom theme to a core theme
    If you have a custom theme, revert it back to one of the core themes. Log in to the Drupal admin and go to Administer > Site building > Themes or the Drupal path admin/build/themes to do this.

    5. Delete all old files
    Delete all the files in your installation main directory - this ensures that there are no clashes between existing files and new files.

    6. Upload new files
    Now upload the files extracted in step 2 above folder to the main installation folder on the server.

    7. Copy over the backed up folders
    Copy back the files and sites folders backed up in step 1 above back to their respective folders.

    8. Re-enable contributed modules
    Log in to the Drupal admin and go to Administer > Site building > Modules or the Drupal path admin/build/modules. Enable all the contributed modules that you disabled in step 3 above.

    9. Run update.php script
    Drupal provides a special update script located in the root folder of the install for maintaining the database after upgrades. Log in to the admin section with your admin id(usually having id of 1 and is the first account to be creaed). Then point your browser to http:///update.php and click on the Update button. The modules requiring database updates will have their appropriate DB update number selected in their drop-downs. For most cases, the defaults should be fine. The database update may take some time depending on the number of updates to apply.

    10. Re-apply custom theme
    If you had a custom theme, re-apply it now. Log in to the Drupal admin and go to Administer > Site building > Themes or the Drupal path admin/build/themes to do this.

    Updating Drupal Module

    With changes to the core modules or due to security / bug fixes / patches, installed modules may require to be updated. Updating (contributed) modules is very simple as the process has been kept very rudimentary. Here are the steps needed to update a module:
    1. Find modules requiring updates
    2. Disable the module
    3. Delete all files of the module
    4. Reinstall the updated module
    5. Run update.php script

    Now lets delve into each of the above steps in a bit of detail:

    1. Find modules requiring updates
    If you do not already have the Update Status module installed & enabled, get it from the drupal site http://drupal.org/project/update_status & install it. This module tracks which of the installed modules have updates available and provides handy links to download the updates directly. Once this is installed & enabled, go to Administer > Reports > Available updates or the Drupal path admin/reports/updates. This page shows which modules require updates to be installed.

    2. Dsiable the module
    Once the list of modules to be updated is known, go to Administer > Site building > Modules or the Drupal path admin/build/modules and disable those modules.

    3. Delete all files of the module
    Now delete all the files for these modules by deleting their corresponding folder in sites/all/modules folder in your Drupal install.

    4. Reinstall the updated module
    Now upload & install the files for the updated module just as if it were a new module. For details on how to install a new module, check out my blog post on Installing Drupal Module.

    5. Run update.php script
    Drupal provides a special update script located in the root folder of the install for maintaining the database after upgrades. Log in to the admin section with your admin id(usually having id of 1 and is the first account to be creaed). Then point your browser to http:///update.php and click on the Update button. The modules requiring database updates will have their appropriate DB update number selected in their drop-downs. For most cases, the defaults should be fine. The database update may take some time depending on the number of updates to apply - once this is done, the modules are all updated!

    Installing a Drupal Module

    Drupal is a very powerful CMS platform and has many modules to enhance it's functionality. Installing (contributed) modules is very simple as the process has been kept very rudimentary. Here are the steps needed to install a module:
    1. Find & download compatible module
    2. Unzip it locally
    3. Upload files to your server
    4. Read & follow special instructions (if any)
    5. Enable the new module
    6. Setup permissions (if required)
    7. Adjust Settings (if required)

    Now lets delve into each of the above steps in a bit of detail:

    1. Find & Download compatible Module
    Search for the module on the drupal site http://drupal.org/project/modules/. This page has a big list of available modules and you can search for required modules as well. Once you find the module that is compatible with the version of the installed Drupal core, download the compressed "tar.gz" file locally.

    2. Unzip it locally
    Once the file is available locally, extract the contents to a temporary folder. On Ubuntu, I just double-click on the file to do this. On WinX platforms, this cannot be done directly - you will need to download & install the free & open source tool 7-Zip to do this. Now you should have a folder by the name of the module in your chosen temporary folder.

    3. Upload files to your server
    Now upload this extracted folder to sites/all/modules folder in your Drupal install. This is the folder that holds all the contributed modules.

    4. Read & follow special instructions (if any)
    Check the module folder for "README.txt" or "INSTALL.txt" or similarly named files to see if this module requires any special steps for installation. If so, follow those steps to a "T".

    5. Enable the new module
    Log in to the Drupal admin and go to Administer > Site building > Modules or the Drupal path admin/build/modules. Look for the new module and enable it.

    For most cases, you should be good by now. If not, then follow the below steps.

    6. Setup permissions (if required)
    Some modules need extra permissions to be setup for them to work properly. Grant the permissions as appropriate & required for the module to function properly.

    7. Adjust Settings (if required)
    Tweak the settings provided by the module (if any) to make it function as per your requirements. Mostly the provided defaults work good, but there could be cases where you need to change the settings to suit your needs.

    Monday, July 12, 2010

    Google launches Android App Inventor Beta

    Ever wanted to create an app for your (or for that matter, someone else's) Android phone? But were lost in the sea of code & APIs that is required to be mastered?

    Worry no more - for Google Labs has launched (but of course) a Beta version of the App Inventor for Android.

    This looks like a glorified equivalent of the Visual Basic interface that was used to make many a (good & bad) programs. However the good part here is that you can make an entire program without even a single line of coding! To quote from the App Inventor site:

    To use App Inventor, you do not need to be a developer. App Inventor requires NO programming knowledge. This is because instead of writing code, you visually design the way the app looks and use blocks to specify the app's behavior.

    The App Inventor team has created blocks for just about everything you can do with an Android phone, as well as blocks for doing "programming-like" stuff-- blocks to store information, blocks for repeating actions, and blocks to perform actions under certain conditions. There are even blocks to talk to services like Twitter.

    Here's to Google to open up it's platform for the young and the old alike for whoever may have the appetite and energy to create their own Android apps. Only time will tell whether this approach will yield better apps or not!

    Fee jQuery eBook - 7/12 Only

    Sitepoint is offering free download of the eBook jQuery: Novice to Ninja by Earle Castledine and Craig Sharkie here.

    Amazon reviews are pretty good and the paper edition is priced at $35.60.

    LinkWithin

    Related Posts Plugin for WordPress, Blogger...