Tuesday, July 10, 2012

Installing setuptools for Python2.7 on Windows

Assuming you have python 2.7 installed in C:\Python27
  1. Make sure your path includes C:\Python27\; and C:\Python27\Scripts\;
  2. Download setuptools-0.6c11.tar.gz and setuptools-0.6c11-py2.7.egg from here
  3. Extract the tar using 7zip into a folder outside C:\Python27 and copy the setuptools-0.6c11-py2.7.egg file into the extracted folder
  4. Open command prompt, get into the extracted folder and run the command: python ez_setup.py setuptool-0.6c11-py2.7.egg
You can now install modules like suds using the command
python setup.py install


Thanks to the guys at 

http://www.jansipke.nl/python-soap-client-with-suds/

Thursday, September 1, 2011

Passing arrays from jQuery to C# Webservice

Step 1:
Download json2.js from https://github.com/douglascrockford/JSON-js
Include in your <head>
<script type="text/javascript" src="scripts/json2.js"></script>


Step 2:
Assuming you are populating an array from a select list, create and populate an array

var Voltages = new Array();
// AddedVoltage is my select list
$("#AddedVoltage option").each(function () {
        Voltages.push($(this).val());
});

Step 3:
Convert your array to a json string using json2.js
var jsonString = JSON.stringify(Voltages)


Step 4:
You can now pass the jsonString in your ajax request and recieve it as a string in your webservice.

Step 5:
Download jayrock json from http://code.google.com/p/jayrock/downloads/detail?name=jayrock-0.9.12915.zip&can=2&q= and add reference to your .net project.
More info here (http://msdn.microsoft.com/en-us/library/bb299886.aspx)

Step 6:
You can now convert the received json string in your web service to a list using

public List<String> ConvertToList(string jsonString)
    {
        List<string> SelectedVoltages = new List<string>();
        using (JsonTextReader reader = new JsonTextReader(new StringReader(jsonString)))
        {
            while (reader.Read())
            {
                if (reader.TokenClass == JsonTokenClass.String)
                {
                    SelectedVoltages.Add(reader.Token.Text);
                }
            }
        }
        return SelectedVoltages;
    }



Wednesday, August 24, 2011

jQuery access textbox within GridView

If you want to access the textbox in the gridview example below, use
$("table[id*=ResultGridView] input[type=text][id*=date]")

<asp:GridView ID="ResultGridView" runat="server" OnRowDataBound="ResultGridView_RowDataBound">
       
<Columns>

           
<asp:TemplateField>

               
<ItemTemplate>

                   
<asp:TextBox ID="date" runat="server"></asp:TextBox>
dd/MM/yyyy                  </ItemTemplate>
           
</asp:TemplateField>

       
</Columns>

   
</asp:GridView>
 

Auto-resize textbox

Facebook like textboxes

Download this jquery plugin
http://james.padolsey.com/demos/plugins/jQuery/autoresize.jquery.js

Then apply this for your textbox

$('textarea#comment').autoResize({
    // On resize:
    onResize : function() {
        $(this).css({opacity:0.8});
    },
    // After resize:
    animateCallback : function() {
        $(this).css({opacity:1});
    },
    // Quite slow animation:
    animateDuration : 300,
    // More extra space:
    extraSpace : 40
});

Tuesday, August 9, 2011

ASP.net Submit does not work on enter press

Submit button wont get fired on press of Enter button on IE

<!-- Fix for IE bug submit on pressing "Enter") --> 
<div style="display:none">
           
<input type="text" name="hiddenText"/>
 
</div> 

SQL truncate decimal points, Get only Date


SQL get only date and not time

For Ex: 12/07/2009 and not 12/07/2009 10:09:20...

convert(varchar(10),@YOUR_DATE,101)

SQL Remove decimal points

For Ex: 203.98 and not 203.98079
select cast((123.456-(123.456%.001)) as decimal (18,2))

Monday, August 1, 2011

Disabling ipv6 in Ubuntu

Installed netbeans on my Ubuntu 11.04 and it was failing to connect and install updates. Disabling ipv6 solved the issue.

Check status of ipv6
Terminal:
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
0 means it's enabled and 1 - disabled

echo "#disable ipv6" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf

Done. Restart and check status of ipv6 again.

Cheers
Bhushan