Friday, March 22, 2013

Eclipse: Create project from existing source - How to import existing Java/Android Project into Eclipse

It seem that a lot of material on the internet, and even some Android books, refer to a mystical "Create project from existing source" option of the new project wizard in Eclipse.
I didn't know how Eclipse looked in the past, but now, in Eclipse Juno, there is no such option.
But you can still "Create project from existing source", and I'll show you how to do it :-)

I created a simple step-by-step visual guide about how to create a new project from existing source.
In this guide I've used Eclipse Juno (from the Android SDK)


1) Start Eclipse and open a new/empty workspace 



2) Click the Import command, in the File menu



3) Choose "Android\Existing Android Code Into Workspace" and click "Next"



4) The following screen will appear, we need to insert the folder path of the source files we want to use as base for our new project: we can use the "Browse" button or...



5) We can simply Copy/Paste the path of our source files :-)


6) Paste the path of our source project folder



7) Click the "Refresh" button: this will update the list of source project(s)



8) Eureka! Now we have the list of our much wanted source project(s)



9) Now, don't be hungry, click the "Deselect All" button, to uncheck all the projects



10) and now select the project you really want. I'll go for the AccelerometerPlay, I always liked the interesting things you can do with modern smartphone sensors... :-)



11) Check the option "Copy projects into workspace" so you'll work on a copy of the original project. It's best to not mess up with the original SDK samples, you never know when you'll need them again :-)



12) Click "Finish" aaaaand....



13) You are done! Welcome your new project freshly copied from the SDK source :-)


P.S.: Can you guess that the first programming language I learned was Borland Turbo Pascal 5?
The blue background IDE of those good old days left a sign in my infancy... and even 22 years after, I still feel at home with a dark blue background, yellow keywords, and white identifiers! :-)


In case you like it, here is a link to my Eclipse color theme (MaxDarkBlue Eclipse theme), It's a work in progress... but for my eyes it seem better that other themes I've checked :-)

Thursday, March 14, 2013

WHAT? NO MORE GOOGLE READER? Google: ARE YOU CRAZY?

I just acknowledged that from 1 July 2013 Google is dismissing Google Reader.

http://googlesystem.blogspot.it/2013/03/no-more-google-reader.html

WHAT? NO MORE GOOGLE READER?
Google: ARE YOU CRAZY?
How I'm supposed to keep up with the news?

Google reader changed the way I search for news!
Google reader changed the way I surf the web.
With Google reader I can look efficiently at an enormous amount of news, all in one place.

Hey Google, do you really mean that I need to back to the old habit of opening a website, looks for news, open another website, looks for news.... but, hey, I have more than 500 RSS feed in my Google reader, How Can I open 500 website? I can't...

So, not having Google Reader will slow down by a a factor of no less than 10 my ability to surf the news, to surf the net, to keep up with interesting things...

Google reader is 100% news, 100% interesting things, 100% efficiency!
And Google is trowing that out of the window... :-(

This is so sad.

Once upon a time I was using an offline feed reader, it was not bad... but then I discovered Google reader, so much faster, so much better!

Do I really need to find another offline RSS feed reader? does they still exist?

Why are you doing that Google? WHY?!?

Please, please, please, keep Google Reader running!


Thursday, March 7, 2013

How to split a comma separated string and loop it's values in SQL Server

Here is a simple T-SQL script for SQL Server that will split a comma separated string and loop on the values.
It's a simple way to create a array/list of things in SQL Server, and then do something on the values of the list.
These values can be anything: table names, stored procedures, query...

Application note:  the value list string must end with a comma ","
I've update the code to work even with a value list that doesn't have a trailing comma

DECLARE @valueList varchar(8000)
DECLARE @pos INT
DECLARE @len INT
DECLARE @value varchar(8000)

SET @valueList = 'aa,bb,cc,f,sduygfdctys,w,e,r,t,sd sdf sdf,yyy yyy yy,'

--the value list string must end with a comma ','
--so, if the last comma it's not there, the following IF will add a trailing comma to the value list
IF @valueList NOT LIKE '%,'
BEGIN
    set @valueList = @valueList + ','
END


set @pos = 0
set @len = 0

WHILE CHARINDEX(',', @valueList, @pos+1)>0
BEGIN
    set @len = CHARINDEX(',', @valueList, @pos+1) - @pos
    set @value = SUBSTRING(@valueList, @pos, @len)
    --SELECT @pos, @len, @value /*this is here for debugging*/
        
    PRINT @value
    --Here is you value
    --DO YOUR STUFF HERE
    --DO YOUR STUFF HERE
    --DO YOUR STUFF HERE
    --DO YOUR STUFF HERE
    --DO YOUR STUFF HERE

    set @pos = CHARINDEX(',', @valueList, @pos+@len) +1
END


The output of this script is:

    aa
    bb
    cc
    f
    sduygfdctys
    w
    e
    r
    t
    sd sdf sdf
    yyy yyy yy


SQL Code colored with this syntax highlighter

How to rebuild all index on all tables in a SQL Server database

This code will rebuild all indexes on all tables of the current SQL Server DB (without changing the fill factor)
 
Here is the T-SQL code:
DECLARE @tbName varchar(255)

DECLARE tbCursor CURSOR FOR
    SELECT table_name FROM information_schema.tables
    WHERE table_type = 'base table'

OPEN tbCursor

FETCH NEXT FROM tbCursor INTO @tbName
    WHILE @@FETCH_STATUS = 0
    BEGIN
        PRINT 'rebuilding all indexes on ' + @tbName
        DBCC DBREINDEX (@tbName,' ',0) WITH NO_INFOMSGS 
        FETCH NEXT FROM tbCursor INTO @tbName
    END
CLOSE tbCursor

DEALLOCATE tbCursor

The source for this code is in the comments of this blog post
I just changed the code a bit, and color-coded it for easier reading  (using this highlighter)