Archive

Archive for September, 2011

GeoLoaction in Javascript

I found this free service for GeoLocation in Javascript…

<script language='JavaScript' src='http://j.maxmind.com/app/geoip.js'></script>
<script language='JavaScript'>document.write(geoip_country_code());</script>
<script language='JavaScript'>
if(geoip_country_code()=="IT")
{
//Redirect ALL users from ITALY on google.com
location.replace("http://www.google.com");
}
</script>

the code is extremely easy to use, anyway I am looking forward for the proper GeoLocation API shipped with HTML5

Categories: DEV Tags: ,

how to script an FTP upload in a BAT file

In several projects you have the need to automate your deployment procedures… unfortunately often your code is hosted by an external provider that for security reasons give you the access only with FTP…

This code is perfect to automate the upload of your deployment package.

1) Create a Bat File with the following code and name it Upload.bat

@echo off
echo user FTPUserName> ftpcmd.dat
echo FTPPWD >> ftpcmd.dat
echo cd FolderName >>ftpcmd.dat
echo bin>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat FTPserverURL
del ftpcmd.dat

as you can understand you have to put into your username and password and eventually the code to switch directory if you are going to upload something on the root…

2) call your bat file with the following syntax: upload.bat testFile.zip

Happy scripting to everybody Smile

Categories: DEV, Infrastructure Tags: ,

Hello World with BackgroundWorker

in .Net 2.0 MS introduced the BackgroundWorker component to simplify the life of WinForm developers… you can check the following article to know more information http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

the simples sample of use of the BackgroundWorker is a WinForm application that count from 1 to 999 billion and every time that add 1 million, update a simple textBox on the form…

As you can see code is extremely simple… just remember to enable the WorkerReportProgress to true and use the UserState to pass values between events…

ps. this sample does not support user cancellation and does not handle more than 1 click…

public Form1()
       {
           InitializeComponent();
           backgroundWorker1.WorkerReportsProgress = true;
       }

       private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
       {
           var bckwork = (BackgroundWorker)sender;
           for (Int64 i = 1; i <= 9999999999; i++)
           {
               if ((i % 1000000) == 0)
               {
                   int  prog =  (int)(i / 1000000) ;               
                   bckwork.ReportProgress( prog, i);
               }
           }
       }

       private void button1_Click(object sender, EventArgs e)
       {
           backgroundWorker1.RunWorkerAsync();
       }

       private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
       {
           textBox1.Text = e.UserState.ToString();
       }
Categories: DEV Tags: , ,

Source Control on Mercurial

There are several tools available for Mercurial…

On my last project we have decided to migrate to Mercurial from TFS and we are enjoying the following technologies stack:

Mercurial – Bitbucket– Jira – TeamCity

How can you do all of this???

Jira with the agile plugin is an excellent tool to run an Agile project, and you can integrate it fairly easily with Mercurial…

TeamCity can be also integrated fairly easily with Mercurial to keep under control build and deployment processes

Bitbucket is the connector to see your Mercurial repository “onLine”

as useful tools, I would also recommend TortoiseHG and VisualHG and Jira Connector for VS

these are few command to remember in the everyday life using mercurial…

How to switch Branch: HG update "default"

TFS CheckIn
hg push 

TFS get latest
hg pull 

after pull sometime hg up o hg update

hg merge to mix changes after a pull

how to download an existing repository from bitbucket
hg clone https://username@bitbucket.org/repCreator/projectName

TO KNOW ALL THE EXISTING BRANCHES
hg branches

Access to an external Sharepoint List with Sharepoint Client API

Do you need to access a Sharepoint List from a NonSharepoint Application???! With Sharepoint 2010 it is extremely easy… you can benefit of the Sharepoint Client API and it would be extremely easy to control resource hosted on SharePoint external list.
Obviously, whenever it is possible, I would suggest to cache the Sharepoint List in your application cache layer to avoid performance issues….

 public static ListItemCollection GetClientList(string listPath)
  {
  string url = ConfigurationManager.AppSettings["sharepointConfigSite"];
  using (Microsoft.SharePoint.Client.ClientContext ctx = new Microsoft.SharePoint.Client.ClientContext(url))
     {
        var list = ctx.Web.Lists.GetByTitle(listPath);
       ctx.Load(list);
       CamlQuery camlQuery = new CamlQuery();
       camlQuery.ViewXml = "<View/>";
       ListItemCollection listItems = list.GetItems(camlQuery);
        ctx.Load(listItems);
        if (ConfigurationManager.AppSettings["sharepointUserConfigSite"] != null)
          {
           string username = ConfigurationManager.AppSettings["sharepointUserConfigSite"];
           string pwd = ConfigurationManager.AppSettings["sharepointPwdConfigSite"];
            string domain = ConfigurationManager.AppSettings["sharepointDomConfigSite"];
            var cred = new System.Net.NetworkCredential(username, pwd, domain);
            ctx.Credentials = cred;
           }   else  {
                    ctx.AuthenticationMode = ClientAuthenticationMode.Anonymous;
                }
            ctx.ExecuteQuery();
            return listItems;
      }
 }
Categories: DEV, Infrastructure Tags: ,

Virtualization Tips

Do you need to run Virtual PC on your Windows 7 home edition??? this guide explain you how to install virtual PC on windows 7 home…

http://blogs.msdn.com/b/virtual_pc_guy/archive/2010/07/07/installing-windows-virtual-pc-on-windows-7-home-editions.aspx

Anyhow if you have windows 7 home I would recommend you VirtualBox Oracle solution for virtualization… http://www.virtualbox.org

Categories: Infrastructure Tags: ,

Easy WireFrames and Interface Mockups

I tried the Balsamiq  tool for making WireFrame and Mockup few interfaces and I found it extremely easy and quick to use…

It is not powerful as VISIO but I found it much easier to use!!!

http://balsamiq.com/

Categories: Infrastructure