Updates from March, 2009 Toggle Comment Threads | Keyboard Shortcuts

  • Subinkrishna Gopi 11:04 am on March 20, 2009 Permalink |
    Tags: mvc, ruby on rails,   

    Today’s read – Getting started with Ruby on rails 

    railsI was a bit busy – last two weeks – with my personal life. So I could not put more effort in writing the next chapter of my OSGi series and any new stories.

    Today in Smashing Magazine I found an article on “Getting Started With Ruby On Rails” which I think will be very useful for the wanna be Rails geeks or enthusiasts like me. I just started reading it. This is the first one of the two part series on Ruby on rails.

    You can read the article here.

    If you’re a Web developer who’s been curious about Ruby on Rails but has never gotten around to trying it out because you couldn’t find a suitable overview of its advantages, then this article is for you.

    We want to bring Ruby on Rails closer to those who want to take a peek first, without going through an entire tutorial. So, this article is structured a little different from most other introductions out there; hopefully it is more useful because of this.

    Update: Beginner’s Guide To Ruby On Rails: Part 2

    I assume you’re already familiar with some other form of Web development, whether PHP, Python, Perl or Java, and relational databases like MySQL. First, we’ll introduce Rails and Ruby and the basic ideas behind both. I’ll teach you just enough Ruby so that you understand the code samples. I’ll tell you how to get Ruby on Rails running on your computer, and I’ll give you an overview of the basic functionality of Rails and demonstrate how Rails’ main parts work together.

    After reading these parts, you should have an idea of whether Rails is for you. If you get the feeling that it is, I’ll point you to some good tutorials on the Web that you can use to learn Rails. I’ll also provide a lot of further reading recommendations so you can dig as deep into the topic as you like.

    Read the article here: http://www.smashingmagazine.com/2009/03/27/ultimate-beginners-guide-to-ruby-on-rails/

     
  • Subinkrishna Gopi 10:02 am on March 10, 2009 Permalink |
    Tags: bundle, console, , ,   

    Part 3 – OSGi: Writing the first OSGi bundle 

    < Part 2 – OSGi: Creating a workspace | OSGi tutorial home

    Now we can make our hands dirty with a bit of OSGi code. Writing  a bundle is very easy. we need to write a BundleActivator which is the starting point while the bundle get activated or deactivated.

    package subin.osgi.bundle.simple;
    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;
    
    public class SimpleBundleActivator
    implements BundleActivator
    {
        public void start(final BundleContext context) throws Exception
        {
            System.out.println("Hello World !");
        } 
    
        public void stop(final BundleContext context) throws Exception
        {
            System.out.println("Good Bye !");
        }
    }
    

    The start() will get called by the framework when the bundle is activated. Similarly, stop() on deactivation.


    Manifest – OSGi Bundle
    Again a bundle is nothing but the same old JAR with additional set of archive parameters. The following is the manifest file I wrote for the bundle.

    Manifest-Version: 1.0
    Bundle-Name: My Bundle
    Bundle-SymbolicName: subin.osgi.simple
    Bundle-Version: 1.0.0
    Bundle-Description: a Simple bundle
    Bundle-Vendor: subin.co.in
    Bundle-Activator: subin.osgi.bundle.simple.SimpleBundleActivator
    Import-Package: org.osgi.framework

    Bundle-SymbolicName is the unique symbolic name for the bundle which will be used to refer it from other bundles & with in the framework.
    Bundle-Version is the version of the bundle.
    Bundle-Activator is the name of the activator class.
    Import-Package defines the imported packages for the bundle.

    Creating the bundle
    Once the BundleActivator class and the manifest is ready, create a JAR. It’s better we use Bundle-SymbolicName as the JAR name.
    How to create a JAR ?


    How to run my bundle ?
    All the bundles need to be installed with the framework to use it. And an installed bundle need to be activated.

    See the attached screen shot.

    Figure 1: Running the bundle for the very first time

    osgi_console_first_bundle

    Commands – OSGi console
    ss – status of bundles in the framework
    install <bundle URL> – installs a bundle from the specified URL
    start <bundle ID> – starts the bundle with the specified ID. A unique ID will be assigned to each bundle during installation.
    stop <bundle ID> – stops the specified bundle


    Some basic configurations
    Once we install a bundle the framework will load the bundle automatically when the framework starts up next time. But the framework won’t start the bundle automatically.

    Figure 2: Framework restart

    osgi_console_first_bundle_restart


    Enabling bundle auto-start

    We can enable the bundle auto-start  by doing some changes in the configuration/config.ini. Add these configuration properties in the file.

    osgi.bundles=org.eclipse.equinox.common@2:start, org.eclipse.update.configurator@3:start, subin.osgi.simple@4:start
    eclipse.ignoreApp=true
    osgi.noShutdown=true

    Figure 3: Framework restart after configuration changes

    osgi_console_first_bundle_auto_start

     
  • Subinkrishna Gopi 5:25 pm on March 6, 2009 Permalink |
    Tags: c, ,   

    Fun with C 

    This is a very old code written by me back in 2000 to make my sister happy. I found this code in my old hard disk a couple of weeks back. Try this.

    #include <stdio .h>
    int main(int argc, char* argv[])
    {
        char* aString = "I am a monkey. ";
        int index = 0;
        char aChar;
        printf("Type something here. \n\n");
        do
        {
            aChar = getch();
            if (';' != aChar)
            {
                printf("%c", aString[index++]);
                index = (index >= 15) ? 0 : index;
            }
        }
        while (';' != aChar);
        printf("\n\nWow! thats cool. \nPress ENTER to exit.");
        getchar();
        return 0;
    }
    

     
  • Subinkrishna Gopi 9:25 am on March 6, 2009 Permalink |
    Tags: , , ,   

    Part 2 – OSGi: Creating a workspace 

    < Part 1 –  OSGi: What, Why & How | OSGi tutorial home

    To implement my OSGi based applications I am using Equinox (Eclipse Foundation). If you are using Eclipse IDE (which is based on OSGi) you don’ t need to download the OSGi core APIs as you can find it in the Eclipse_Home/plugins directory. If you are using Eclipse Ganymede, you will find a JAR org.eclipse.osgi_3.4.0.v20080605-1900.jar or a higher version. That’s all what we want (for now).

    Equinox download: http://download.eclipse.org/eclipse/equinox/.


    Workspace directory structure

    The directory structure should look like this.

    OSGiWorkspace
    |-- configuration
    |  |-- config.ini               - Framework configuration
    |-- org.eclipse.osgi_3.4.2.jar  - Framework
    |-- subin.orgi.simple.jar       - My bundle
    |
    |-- <other bundles, archives>

    The config.ini is the place where we can configure the framework and bundle behavior. We can talk about it later.


    Running the Equinox core

    Copy org.eclipse.osgi JAR in to your workspace directory. You can start the OSGi framework by running the org.eclipse.osgi JAR file. Use the following command:

    your/workspace/dir> java -jar org.eclipse.osgi_3.4.2.jar -console

    This will start an OSGi console for us using which we can start, install, uninstall OSGi bundles.

    osgi console

    In the above screen shot you can see the OSGi console with the list of installed bundles. (I am using Equinox 3.4.2.)


    Configuring the Equinox workspace
    We can configure Equinox in various ways. I think its very early to mention all those things here. If you are really interested in knowing that, check this link.

    Quick start guide: http://www.eclipse.org/equinox/documents/quickstart.php


    Starting Equinox faceless
    When we start Equinox core using the above command, it will launch an OSGi console. There is a way to start Equinox faceless (with out console). Try this command.

    java -jar org.eclipse.osgi_3.4.2.jar -console 8281 -noExit

    This will make Equinox to launch the OSGi console in port 8281 which we can access using Telnet on port 8281. Try this.

    telnet localhost 8281

    osgi console telnet

    Read more on starting Equinox faceless: http://www.eclipsezone.com/eclipse/forums/t93976.rhtml


    References

    http://www.eclipse.org/equinox/documents/quickstart.php
    http://www.eclipsezone.com/

     
  • Subinkrishna Gopi 2:48 pm on March 5, 2009 Permalink |
    Tags: , ,   

    The most commonly used (favorite) methods 

    Whenever we write code we will have certain set of code blocks – or methods written by us – which we will be using in every other method. isValidString(String aString) is my favorite method.

    public static boolean isValidString(String aString)
    {
        return((null != aString) && (aString.trim().length() > 0));
    }
    

    This one comes second in my list. This method is very useful if we are writing loads of conventional JSPs/Servlets.

    public static String getRequestParameter(HttpServletRequest request,
    		String paramName)
    {
    	return (getRequestParameter(request, paramName, null));
    }
    
    public static String getRequestParameter(HttpServletRequest request,
    		String paramName, String defaultValue)
    {
    	String paramValue = null;
    
    	if ((null != request) && isValidString(paramName))
    	{
    		paramValue = request.getParameter(paramName);
    		paramValue = !Utility.isValidString(paramValue)
    			? defaultValue : paramValue;
    	}
    	else
    		paramValue = defaultValue;
    
    	return (paramValue);
    }
    

    This method comes third. This method tries to implement in_array() of Php. This method checks whether the specified object is available in the given array.

    public static boolean inArray(Object[] array, Object key)
    {
    boolean isKeyInArray = false;
    if (null != array)
    {
    for (int i = 0; i < array.length; i++) { if (array[i].equals(key)) { isKeyInArray = true; break; } } } return (isKeyInArray); } [/sourcecode] But this was like reinventing the wheel. From Java 1.2, they had an API - java.util.Arrays - which does almost everything. I implementing it without knowing that (I am very bad).  But I love my code. So, what's your most commonly used (favorite) method?

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel