Eclipse Indigo hangs on splash screen workspace

Posted in Misc on December 15th, 2011 by taswar

So today I came in to work and saw that my wonderful windows machine was restarted due to Windows Update, and yesterday I was working on some java stuff and did not close out my eclipse, thank god that I do regular code check-in :)

Anyways tried to relaunch eclipse and it kept hanging on workspace.

To fix that I had to go into my workspace folder C:\workspace\.metadata\.plugins

Then I copied the org.eclipse.core.resources to a backup directory and deleted it from the plugins folder.

I restarted Eclipse and then did a File->Import->Existing Project into Workspace and browse my workspace/project directory

And voila I was back in action :)

Share

3 Comments »

Driving Technical Change Book Review

Posted in Books on October 30th, 2011 by taswar

Driving Technical Change Book cover
Have wanted to post the review of this book for a while, which I read somewhere beginning of this year.
This book does a very good job in classification of the “typical” stereotypes of people in IT.
- The Uninformed
- The Herd
- The Cynic
- The Burned
- The Time Crunched
- The Boss
- The Irrational

After the first section we go into what kind of techniques we can use to drive technical changes.
- Gain Expertise
- Deliver Your Message
- Demonstrate Your Technique
- Propose Compromise
- Create Trust
- Get Publicity
- Focus on Synergy
- Build a Bridge
- Create Something Compelling

Lastly the author goes into Strategies one can use to drive technical changes
- Simple, Not Easy
- Ignore the Irrational
- Target the Willing
- Harness the Converted
- Sway Management

The book is a short read with only 125 pages, it is a good read but at the same time one should always remember there are people whom you have to deal with that are emotional, and us human’s are not predictable, the classification helps but if we really want to drive the change we have to be the change agent. I would recommend this book for a beginner who wishes to drive technical changes.

Share

No Comments »

JRuby install and build eventmachine from github

Posted in ruby on October 21st, 2011 by taswar

Have been giving eventmachine a try but I do have issues with it thus wanted to try out the beta version on github.

Here is how you get it to install on your local machine.
- First clone the repo
- Build the gem
- Install the java version

1
2
3
4
5
6
7
8
9
$ git clone git://github.com/eventmachine/eventmachine
$ cd eventmachine
$ jruby -S gem build eventmachine.gemspec
In this step you might be missing some gems, I was missing yard and rake-compiler
$ jruby -S gem install yard
$ jruby -S gem install rake-compiler
$ /c/jruby-1.6.4/bin/rake java gem
 Once the build is done use the pkg version
$ jruby -S gem install pkg/eventmachine-1.0.0.beta-4.java.gem
Share

No Comments »

ERROR: While executing gem … (NameError) uninitialized constant Psych::Syck

Posted in ruby on October 16th, 2011 by taswar

What the ????
I was wanting to try out goliath.io (Goliath: Non-blocking, Ruby 1.9 Web Server) for more info look at http://www.igvita.com/2011/03/08/goliath-non-blocking-ruby-19-web-server/

In any case I was not able to get it to install on JRuby so went and get me 1.9.2 MRI.

Once installed MRI 1.9.2, I went into the gem dir to gem install goliath and guess what this message pops up.

1
2
ERROR: While executing gem ... (NameError)
uninitialized constant Psych::Syck

Really helpful (scarcasim) , then what I had to do to fix this was update my gem

1
gem update --system

After doing so I was able to

1
gem install goliath

Now its time to try out goliath, wish me luck and if anyone knows how to install it with Jruby please let me know cuz jgem install goliath didnt work for me.

Share

2 Comments »

Command Pattern with Notification Event Delegates

Posted in .NET, Design on September 19th, 2011 by taswar

Here is a nice little code I did recently, where the Command Pattern is used with a notification observer like pattern.

First of the Command Pattern, a simple interface for task with an execute method

?View Code CSHARP
1
2
3
4
5
6
7
 public interface ITask
    {
        /// <summary>
        /// Execute the task
        /// </summary>
        void Execute();
    }

Then the notification interface, with 2 methods, one when it started and one when its complete and the event delegate

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/// Notification interface
    /// </summary>
    public interface INotify
    {
        /// <summary>
        /// Process has start
        /// </summary>
        void ProcessStart();
 
        /// <summary>
        /// Process is Complete
        /// </summary>
        void ProcessComplete();
    }
 
    public class NotifyEventArgs : EventArgs
    {
        public enum NotificationStatus
        {
            START,
            COMPLETE,
            ERROR
        } ;
 
        public NotifyEventArgs(string notficationText, NotificationStatus status)
        {
            NotifcationText = notficationText;
            Status = status;
        }
 
        /// <summary>
        /// Status of notification
        /// </summary>
        public NotificationStatus Status { get; private set; }
 
        /// <summary>
        /// Text to notify
        /// </summary>
        public string NotifcationText { get; private set; }
    }

Now the class that implements the interface, I used an abstract class so that I can just use a subclass to implement the simple task I wish to have

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 public abstract class AbstractTask : ITask, INotify
    {
        /// <summary>
        /// Event for notification
        /// </summary>
        public event EventHandler<NotifyEventArgs> NotificationChanged;
 
        /// <summary>
        /// Task to execute
        /// </summary>
        public void Execute()
        {
            try
            {
                ProcessStart();
                ProcessingTask();
                ProcessComplete();
            }
            catch (Exception e)
            {
                 LogException(e);
            }
        }
 
        /// <summary>
        /// When task is started call notification
        /// </summary>
        public void ProcessStart()
        {
            if (NotificationChanged == null)
                return;
 
            NotificationChanged(this, new NotifyEventArgs(NotificationText, NotifyEventArgs.NotificationStatus.START));
        }
 
        /// <summary>
        /// When task is complete call notification
        /// </summary>
        public void ProcessComplete()
        {
            if (NotificationChanged == null)
                return;
 
            NotificationChanged(this, new NotifyEventArgs(NotificationText, NotifyEventArgs.NotificationStatus.COMPLETE));
        }
 
        /// <summary>
        /// Log the exception
        /// </summary>
        /// <param name="e"></param>
        protected void LogException(Exception e)
        {
            if (NotificationChanged != null)
                NotificationChanged(this, new NotifyEventArgs(e.ToString(), NotifyEventArgs.NotificationStatus.ERROR));          
        }
 
        /// <summary>
        /// Text to display for notification
        /// </summary>
        protected string NotificationText { get; set; }
 
 
        /// <summary>
        /// Process task for inheriting class
        /// </summary>
        protected abstract void ProcessingTask();
    }

Now I can write a simple class that inherits from AbstractTask like this

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
public class HelloTask: AbstractTask 
{
        public HelloTask()
        {
            NotificationText = "Hello Task";
        }
 
        protected override void ProcessingTask()
        {  
              Console.WriteLine("Hello World");
         }
}

Now to consume the task

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
 
 
public static void Main(string[] args) 
{
       AbstractTask task = new HelloTask();
       task.NotificationChanged += new EventHandler<NotifyEventArgs>(NotifyAction);
       task.Execute();
}
 
private static void NotifyAction(object source, NotifyEventArgs args)
{
       Console.WriteLine(args.NotificationText);
}

This is more or less the simple form of creating a command pattern to run task that includes a notification to send back. It makes sense to have multiple task like creating users and running database scripts etc etc. This allows one to have flexible design and have an IEnumerable<AbstractTask> and run through each one with an execute method.

Hope this helps :) Happy coding.

Share

No Comments »

Disable browser cache in asp mvc

Posted in ASP .NET, aspmvc on July 29th, 2011 by taswar

Here is a simple trick on how to disable browser cache in your asp .net mvc application with an attribute.
If you have a base controller just add this to your base and all your request would have Pragma No-Cache

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 public class NoCacheAttribute : ActionFilterAttribute
    {        
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (filterContext == null) throw new ArgumentNullException("filterContext");
 
            var cache = GetCache(filterContext);
 
            cache.SetExpires(DateTime.UtcNow.AddDays(-1));
            cache.SetValidUntilExpires(false);
            cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
            cache.SetCacheability(HttpCacheability.NoCache);
            cache.SetNoStore();
 
            base.OnResultExecuting(filterContext);
        }
 
        /// <summary>
        /// Get the reponse cache
        /// </summary>
        /// <param name="filterContext"></param>
        /// <returns></returns>
        protected virtual HttpCachePolicyBase GetCache(ResultExecutingContext filterContext)
        {
            return filterContext.HttpContext.Response.Cache;
        }
     }
}

Simply add this to your base controller, and you are done :)

?View Code CSHARP
1
2
[NoCache]
public BaseController: Controller
Share

1 Comment »

Enable https on ASP.NET MVC 2 & 3, through Filters and web.config

Posted in ASP .NET, aspmvc, unit testing on July 26th, 2011 by taswar

To enable SSL on asp.net mvc, one can use the [RequireHttps] attribute on the base controller if you are using a base controller

?View Code CSHARP
1
2
[RequireHttps]
public class BaseController: Controller

But what if you want to give an option to the installer or the client to enable it in web.config, the easy way to do it for asp mvc2 is to create your own property like code below: (Please note: I am using protected virtual to override stuff for testing, its not one of the best things but it works in breaking dependency and its quick, so that I dont have to mock httpcontext, configuration manager etc etc, I could use an IoC but would make it more complicated for the reader but feel free to use one)

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
namespace MyWebMvc.Attributes
{
    public class MyRequireSslAttribute : RequireHttpsAttribute
    {
        private const string EnableSslKey = "EnableSSL";
 
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if(filterContext == null)
                throw new ArgumentException("filterContext");
 
            if (!IsHttpContextNull(filterContext) && !IsEnableSsl())
            {
                return;
            }
 
            BaseOnAuthorization(filterContext);            
        }
 
        protected virtual void BaseOnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
        }
 
        protected virtual bool IsHttpContextNull(AuthorizationContext filterContext)
        {
            return filterContext.HttpContext == null;
        }
 
        protected virtual bool IsEnableSsl()
        {
            var enableSsl = HttpRuntime.Cache.Get(EnableSslKey);
 
            if(enableSsl == null)
            {
                var configEnableSsl = ConfigurationManager.AppSettings[EnableSslKey] ?? string.Empty;
 
                if(string.IsNullOrEmpty(configEnableSsl))
                {
                    HttpRuntime.Cache.Insert(EnableSslKey, false);
                    return false;
                }
 
                if(configEnableSsl.ToLower() != "true")
                {
                    HttpRuntime.Cache.Insert(EnableSslKey, false);
                    return false;
                }
 
                HttpRuntime.Cache.Insert(EnableSslKey, true);
                return true;
            }
 
            var isEnableSsl = false;
            bool.TryParse(enableSsl.ToString(), out isEnableSsl);            
 
            return isEnableSsl;
        }
    }

Here is the unit test for it, I am using a stub class to override the things I want for testing

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Web.Mvc;
using NUnit.Framework;
using MyWebMvc.Attributes;
 
namespace MyWebMvc.Tests.Attributes
{
    [TestFixture]
    public class MyRequireSslAttributeTests
    {
 
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void OnAuthorization_ThrowException_WhenFilterIsNull()
        {
            var attr = new MyRequireSslAttribute();
 
            attr.OnAuthorization(null);
        }
 
 
        [Test]
        public void OnAuthorization_IsEnableFalse_BaseValidationWasNotCalled()
        {
            var attr = new StubMyRequireSslAttribute {EnableSsl = false, HttpContextBool = false};
 
            var context = new AuthorizationContext();         
 
            attr.OnAuthorization(context);
 
            Assert.That(attr.BaseWasCalled, Is.False);
 
        }
 
        [Test]
        public void OnAuthorization_HttpContextNullTrue_BaseValidationWasCalled()
        {
            var attr = new StubMyRequireSslAttribute { EnableSsl = false, HttpContextBool = true };
 
            var context = new AuthorizationContext();
 
            attr.OnAuthorization(context);
 
            Assert.That(attr.BaseWasCalled, Is.True);
 
        }
 
 
        [Test]
        public void OnAuthorization_HttpContextNullTrueIsEnableTrue_BaseValidationWasCalled()
        {
            var attr = new StubMyRequireSslAttribute { EnableSsl = true, HttpContextBool = true };
 
            var context = new AuthorizationContext();
 
            attr.OnAuthorization(context);
 
            Assert.That(attr.BaseWasCalled, Is.True);
 
        }
 
 
        [Test]
        public void OnAuthorization_IsEnableTrue_BaseValidationIsCalled()
        {
            var attr = new StubMyRequireSslAttribute { EnableSsl = true, HttpContextBool = false };
 
            var context = new AuthorizationContext();
 
            attr.OnAuthorization(context);
 
            Assert.That(attr.BaseWasCalled, Is.True);
        }
 
    }
 
 
    public class StubMyRequireSslAttribute : MyRequireSslAttribute
    {
        public bool EnableSsl { get; set; }
        public bool HttpContextBool { get; set; }
        public bool BaseWasCalled { get; set; }
 
        protected override bool IsHttpContextNull(AuthorizationContext filterContext)
        {
            return HttpContextBool;
        }
 
        protected override bool IsEnableSsl()
        {
            return EnableSsl;
        }
 
        protected override void BaseOnAuthorization(AuthorizationContext filterContext)
        {
            BaseWasCalled = true;
        }
    }
}

Now in your web.config you can add a key value pair like

1
<add key="EnableSSL" value="true" />

And last if you are using Asp.Net Mvc3 life is way easier, one can just use in their Global.ascx file to add the filter

?View Code CSHARP
1
2
3
4
5
6
public static void RegisterGlobalFilters(GlobalFilterCollection filters) {
 
     //get configuration and add the attribute if needed
    filters.Add(new MyRequireHttpsAttribute()); 
 
}

Lastly you would add it to your BaseController

?View Code CSHARP
1
2
[MyRequireSsl]
public class BaseController: Controller
Share

No Comments »

Jquery: dropdown.val(‘selected’, ‘selected’) does not work anymore.

Posted in JQuery on July 25th, 2011 by taswar

Was debugging some code that was broken due to jquery 1.6 update, and found this call.

?View Code JAVASCRIPT
1
$("#dropDownSelect option[text=" + myText +"]").attr("selected","selected") ;

Not working anymore but a simple fix of changing it to

?View Code JAVASCRIPT
1
$("#dropDownSelect option[text=" + myText +"]").prop("selected",true) ;

This does the trick, for more on prop take a look at the api of jquery http://api.jquery.com/prop/

Share

No Comments »

Building an installer and displaying Data Link Properties Dialog Box for connection string

Posted in .NET on July 20th, 2011 by taswar

So was hacking a new installer and wanted to display the data link properties dialog, for building a connection string.
Here is what I have found out by playing with it.
One has to add the reference to ADODB.DLL (from .NET reference) and Microsoft OLE DB Service Component 1.0 Type Library from the COM tab in your visual studio reference tab.

Here is some sample code, assuming that you have a button and a textbox on the screen.

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using ADODB;
using Microsoft.Win32;
public partial class ConnectionStringStep : Form
    {
        private const string MSSQL_PROVIDER = "Provider=SQLOLEDB.1";
 
        private const string ORACLE_PROVIDER = "Provider=MSDAORA.1";
 
        private const string MSSQL = "MSSQL";
 
        public ConnectionStringStep()
        {
            InitializeComponent();
        }
 
 
        private static string DataBaseType()
        {
			//get the data from some previous screen or some kind of storage
            return MyStorage.GetProperty("DATABASE_TYPE") ?? "MSSQL";
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            var dataBaseType = DataBaseType();
 
            var adodbConnection = new Connection
                                      {
                                          ConnectionString = dataBaseType == MSSQL ? MSSQL_PROVIDER : ORACLE_PROVIDER
                                      };
 
            object connection = (object) adodbConnection;
 
            var dialog = new MSDASC.DataLinks();
 
            dialog.PromptEdit(ref connection);
 
            connectionTextBox.Text = adodbConnection.ConnectionString;
        }
    }

And here is how it looks like

Once a user clicks on build, the Data Link Properties Shows up.

Data Link Properties Dialog

Also note: that I am providing some default into the connection, since if you do not provide “Provider=SQLOLEDB.1″ then the default is just OLE database not the MSSQL database option.

Share

1 Comment »

RubyMine 3.1.1 running in 64bit JVM on Windows 7

Posted in ruby on April 20th, 2011 by taswar

In order to run Rubymine under a 64bit jvm one needs to run the IDE from the bat file.

In the bat file which is located at C:\Program Files (x86)\JetBrains\RubyMine 3.1.1\bin add this line

SET RUBYMINE_JDK=%ProgramFiles%/Java/jdk1.6.0_25

and remove the IF statements
::IF “%RUBYMINE_JDK%” == “” SET RUBYMINE_JDK=%JDK_HOME%
::IF “%RUBYMINE_JDK%” == “” goto error

Run the rubymine.bat file voila 64bit jvm.

Share

No Comments »

« Previous Entries