Wednesday, December 30, 2009

Using pyjamas with web2py

Web2Py is a wonderful frameworks Web written in Python.
If you like the power and ease of use web2py is for you
Pyjamas is a port of Google Web Toolkit in Python

http://www.web2py.com/AlterEgo/default/show/203

Friday, December 11, 2009

C# Tutorial - Using The ThreadPool

http://www.switchonthecode.com/tutorials/csharp-tutorial-using-the-threadpool

VSTO Drag & Drop - Application_SheetChange event handler

http://msdn.microsoft.com/en-us/library/bb840032.aspx

SQLCLR : Table Valued Function


using System;
using Microsoft.SqlServer.Server;
using System.Collections;
using System.Data.SqlTypes;
using System.Collections.Generic;

class Product
{
public int Quantity { get; set; }
public string Description { get; set; }
}


public partial class UserDefinedFunctions
{

[SqlFunction(TableDefinition = @"Quantity int,
Description nvarchar(100)",
Name = "Products",
FillRowMethodName = "FillRowProduct")]
public static IEnumerable GetProducts()
{

List lstPerson = new List();
lstPerson.Add(new Product { Quantity = 1, Description = "Ball" });
lstPerson.Add(new Product { Quantity = 10, Description = "Bike" });
lstPerson.Add(new Product { Quantity = 5, Description = "Club" });
lstPerson.Add(new Product { Quantity = 10, Description = "Bat" });
return lstPerson;
}


public static void FillRowProduct(Object obj, out SqlInt32 Quantity, out SqlChars Description)
{
Product p = (Product)obj;
Description = new SqlChars(p.Description);
Quantity = new SqlInt32(p.Quantity);
}
};

<--->
SELECT Prod.*
FROM dbo.Products() AS Prod

Quantity Description
1    Ball
10    Bike
5    Club
10    Bat

Sunday, December 6, 2009

CLR Stored Procedures

http://www.sqldbatips.com/showarticle.asp?ID=22
http://www.aspfree.com/c/a/MS-SQL-Server/NET-CLR-stored-procedures-in-SQL-Server-2005-DB-Good-News-to-Programmers-Shock-to-DBAs/2/

C# Code Snippets

http://en.csharp-online.net/CSharp_Code_Snippets

VSTO Excel From Range to Array Array to Range


using System;
using Excel = Microsoft.Office.Interop.Excel;

namespace ExcelArray
{
public partial class ThisAddIn
{
Excel.Worksheet ws;
Excel.Range c;
Object[,] arValue;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
ws = (Excel.Worksheet)Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet;

for (int j = 1; j < 11; j++)
{
for (int i = 1; i < 11; i++)
{
c = (Excel.Range)ws.Cells[i, j];
c.Value2 = i+j-1;
}
}

// From Range to Array
// We copy the 2nth column
c = (Excel.Range)ws.get_Range(ws.Cells[1, 2], ws.Cells[10, 2]);
c.Interior.ColorIndex = 2;
arValue = (Object[,])c.Value2;

// Array to Range
// We paste on the first column
c = (Excel.Range)ws.get_Range(ws.Cells[12, 1], ws.Cells[21, 1]);
c.Value2 = arValue;
c.Interior.ColorIndex = 6;
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}

#region VSTO generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}

#endregion
}
}

Saturday, December 5, 2009

Apophysis

Nice site for this wonderful program
http://apophysisrevealed.com/

C++/CLI Programming

http://www.functionx.com/cppcli/index.htm

FAQ C++/CLI

http://dotnet.developpez.com/faq/cppcli/?page=sommaire#sommaire

Unsafe Code and Pointers (C# Programming Guide)

http://msdn.microsoft.com/en-us/library/t2yzs44b%28VS.80%29.aspx

Create and access a pointer array

http://en.csharp-online.net/Create_and_access_a_pointer_array

Pointers in C#

I need to parse large amount of data in Excel Sheet.
I trying to use pointers for performance issues
Here is how to define pointers in C#
http://msdn.microsoft.com/en-us/library/f58wzh21%28VS.71%29.aspx

Friday, December 4, 2009

C# - DatagridView

I was in search of editing cell programmatically.
Here is a simple attempt


using System.Collections.Generic;
using System.Windows.Forms;

namespace testGridView
{
public partial class Form1 : Form
{
List cars;

int currentValue;

public Form1()
{
InitializeComponent();
InitializeCarsCollection();
SetLayoutGrid();
this.dataGridView1.DataSource = cars;
}

private void SetLayoutGrid()
{
this.dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
this.dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);
this.dataGridView1.Dock = DockStyle.Fill;
this.dataGridView1.AutoGenerateColumns = true;
this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
}

void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int editedValue = (int)this.dataGridView1[e.ColumnIndex, e.RowIndex].Value;

if (editedValue != this.currentValue)
{
System.Windows.Forms.MessageBox.Show(this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString());
}
}

void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{


if (e.ColumnIndex == 2)
{
this.currentValue = (int)this.dataGridView1[e.ColumnIndex, e.RowIndex].Value;
this.dataGridView1.BeginEdit(true);
}
}

private void InitializeCarsCollection()
{
cars = new List();
cars.Add(new Car { Marque = "Renault", Couleur = "rouge", Cylindree = 6 });
cars.Add(new Car { Marque = "Citroen", Couleur = "bleu", Cylindree = 4 });
cars.Add(new Car { Marque = "Peugeot", Couleur = "vert", Cylindree = 8 });
cars.Add(new Car { Marque = "BMW", Couleur = "jaune", Cylindree = 16 });
}
}
}

Thursday, October 29, 2009

DLR and JavaScript Interoperability with Gestalt

Calling Javascript from Python and vice versa

http://visitmix.com/Opinions/DLR-and-JavaScript-Interoperability-with-Gestalt

Fluid Simulation for Dummies

http://mikeash.com/?page=pyblog/fluid-simulation-for-dummies.html

Advanced Render Techniques with WriteableBitmaps

http://cynergysystems.com/blogs/page/rickbarraza?entry=advanced_render_techniques_with_writeablebitmaps

Rendering Vector Fields in Silverlight

http://www.cynergysystems.com/blogs/page/rickbarraza?entry=rendering_vector_fields_in_silverlight

Hide Your Mac Menu Bar and Dock for a Cleaner Desktop

http://lifehacker.com/5280456/hide-your-mac-menu-bar-and-dock-for-a-cleaner-desktop

Sunday, October 25, 2009

Gestalt - Nishant Kothary and Joshua Allen

Gestalt" is a technology that allows web developers to easily include ruby, python, and even Silverlight code directly within the html of their websites...
http://channel9.msdn.com/shows/The+Knowledge+Chamber/Gestalt-Nishant-Kothary-and-Joshua-Allen/

How to: Access Office Interop Objects by Using Visual C# 2010 Features (C# Programming Guide)

http://msdn.microsoft.com/en-us/library/dd264733(VS.100).aspx

Dynamic C#

Great posts about this new feature
http://blogs.msdn.com/cburrows/archive/tags/dynamic/default.aspx

Walkthrough: Dynamic Programming in Visual Basic 10.0 and C# 4.0 (Lisa Feigenbaum)

http://blogs.msdn.com/vbteam/archive/2008/12/17/walkthrough-dynamic-programming-in-visual-basic-10-0-and-c-4-0-lisa-feigenbaum.aspx

Monday, August 10, 2009

User Defined Functions

'...if you have ever wanted to use the results of a stored procedure as part of a T-SQL command, use parameterized non-updateable views, or encapsulate complex logic into a single database object, the SQL Server 2000 User-Defined function is a new database object that you should examine to see if its right for your particular environment.'

http://www.sqlteam.com/article/user-defined-functions

CLR Stored Procedures

http://msdn.microsoft.com/en-gb/library/ms131094.aspx

http://www.devx.com/dbzone/Article/28412/1954

http://www.amergerzic.com/post/CLRStoredProcedures.aspx

http://aspalliance.com/1338_Working_with_Managed_Stored_Procedure_using_Visual_Studio_2005.5

Thursday, July 30, 2009

Saturday, July 11, 2009

The adventures of a Pythonista in Schemeland

http://www.artima.com/weblogs/viewpost.jsp?thread=238789

Beginning F#: Card Tricks

http://www.devx.com/dotnet/Article/40537/1954

Mastermind F# WPF Game Sample

http://www.trelford.com/blog/post/Mastermind-F-WPF-Game-Sample.aspx

How to Write XNA Game Studio Express Games

http://grammerjack.spaces.live.com/blog/cns!F2629C772A178A7C!156.entry

Learning WPF through F#, and vice versa, by John Liao

http://blogs.msdn.com/dsyme/archive/2008/01/05/learning-wpf-through-f-and-vice-versa-by-john-liao.aspx

Exploring F# with Conway’s Game of Life

http://blogs.vertigo.com/personal/rtaylor/Blog/Lists/Posts/Post.aspx?ID=8

Simple F# Game using WPF

http://blogs.msdn.com/chrsmith/archive/2008/09/04/simple-f-game-using-wpf.aspx

F# FOR GAME DEVELOPMENT

http://sharp-gamedev.blogspot.com/2008/09/hello-world.html

Tuesday, July 7, 2009

How to Design Programs

http://www.htdp.org/2003-09-26/Book/curriculum.html

Factory Pattern in C#

I wanted to access the fields of the created classes.
Here is the code I've implemented, feel free to comment


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FactoryPattern
{

    interface Base
    {      
    }
    
    class Factory
    {
        Base derived;

        public Base GetObject(int selector)
        {
            switch (selector)
            {
                case 1:
                    derived = new Derived1();
                    break;
                case 2:
                    derived = new Derived2();
                    break;
            }
            return derived;
        }
    }


    class Derived1 : Base
    {
        public string origin = "Derived1";      
    }


    public class Derived2 : Base
    {
        public string origin = "Derived2";
        public int value = 145;
    }

    class Program
    {
        public static object GetFieldValue(string nameField, object obj)
        {
            return obj.GetType().GetField(nameField).GetValue(obj);
        }

        static void Main(string[] args)
        {
            Base obj;
            Factory f = new Factory();
            obj = f.GetObject(2);          
            var origin =  GetFieldValue("value", obj);
            System.Console.WriteLine(String.Format("{0}",origin));
            Console.ReadLine();          
        }
    }
}

Tuesday, June 23, 2009

VSTO Excel : GetRange

        /// <summary>
        /// Return a range starting from cell C
        /// The range can contain empty cell
        /// C - - - - - -
        ///  - -   - - - -
        ///  - - - - - - -
        ///  - -   - -          
        ///  </summary>
        /// <param name="ws"></param>
        /// <param name="start"></param>
        /// <returns></returns>
        public Excel.Range GetRightDownRegion(Excel.Worksheet ws, Excel.Range start)
        {
            Excel.Range curCell = start;
            Excel.Range endCell = start;
                  
            int lastCol;
            int offsetCol;
            int j = 0;

            while (curCell.Value2 != null)
            {
                curCell = start.get_Offset(0, j);
                if (curCell.Value2 != null)
                {
                    endCell = curCell;
                }
                j++;
            }
            
            lastCol = endCell.Column;

            int i = 0;
            curCell = start;
            endCell = start;

            while (curCell.Value2 != null)
            {
                curCell = start.get_Offset(i, 0);
                if (curCell.Value2 != null)
                {
                    endCell = curCell;
                }
                i++;
            }
            
            offsetCol = lastCol - endCell.Column;

            endCell = endCell.get_Offset(0, offsetCol);
                                    
            return ws.get_Range(start, endCell);            
        }
    }

Thursday, June 11, 2009

VSTO : ListObjects

VSTO is not obvious, here is to name columns

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;

namespace ExcelWorkbook7
{
public partial class Feuil1
{
NorthwindDataContext ctx = new NorthwindDataContext();

private void Feuil1_Startup(object sender, System.EventArgs e)
{
var cs = from cust in ctx.Customers
select cust;

Microsoft.Office.Tools.Excel.ListObject customerData;
customerData = this.Controls.AddListObject(this.get_Range(this.Cells[1,1],this.Cells[1,2]), "Customers");
DataGridTableStyle s = new DataGridTableStyle();

customerData.TableStyle = "TableStyleLight10";
customerData.ListColumns.get_Item(1).Name = "ID";
customerData.ListColumns.get_Item(2).Name = "Name";
customerData.SetDataBinding(cs,"","CustomerID","CompanyName");

}

private void Feuil1_Shutdown(object sender, System.EventArgs e)
{
}

#region VSTO Designer generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InternalStartup()
{

this.Startup += new System.EventHandler(this.Feuil1_Startup);
this.Shutdown += new System.EventHandler(this.Feuil1_Shutdown);

}

#endregion

}
}

How to programmatically display data into an excel worksheet

http://thedotnet.com/nntp/156520/showpost.aspx

Excel Object Model reference

http://msdn.microsoft.com/en-us/library/bb149081.aspx

VSTO : Add ListObject Controls to Worksheets

http://msdn.microsoft.com/en-us/library/eyfs6478(VS.80).aspx

Trie paramétrable

http://forum.hardware.fr/hfr/Programmation/CNET-managed/parametrable-list-sort-sujet_111411_1.htm

Saturday, May 16, 2009

Excel Addin : calling service

Given a simple asmx service, here is how to call it in an Excel AddIn


(...)
using ExcelAddIn.ServiceReference1;

namespace ExcelAddIn
{
public partial class ThisAddIn
{

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}

public void Hello()
{
using (Service1SoapClient svc = new Service1SoapClient())
{
Excel.Range rgStart;
Excel.Worksheet ws = (Excel.Worksheet)Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet;
rgStart = ws.Application.ActiveCell;
rgStart.Value2 = svc.HelloWorld();
}
}


#region VSTO generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}

#endregion
}
}



In RibbonBar

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;

namespace ExcelAddIn
{
public partial class Ribbon1 : OfficeRibbon
{
public Ribbon1()
{
InitializeComponent();
}

private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{

}

private void button1_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.Hello();
}
}
}

Friday, May 15, 2009

JQuery : Templating using Pure.js

I have tried to use 'chain.js' but it was too slow so I've adopted Pure.js, which is very fast.
I also use the nice tips of John which allows to hide
html parts.
Here is a sample on how I use Pure with JQuery

Here is the link for the lib:
http://beebole.com/pure
Thanks Mic Cvilic



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/pure.js" type="text/javascript"></script>
    <script src="../Scripts/Services.js" type="text/javascript"></script>  

</head>
<body>
    <button onclick="getProducts();">GetProducts</button>        
    <br />
    <div id="productsList"></div>
    <br />
    <button onclick="decS();">prev 10</button><button onclick="incS();">next 10</button>
    

      
   <!-- Scripts -->
  
  
    <script type="text/html" id="productsListTemplate">
            <table id="products" border="1"; width="400">
            <thead>
                <tr>
                    <th style="width:100;">ProductID</th>
                    <th>ProductName</th>
                </tr>
            </thead>
            <tbody id="tableBody">
            </tbody>
        </table>
    </script>
    <script type="text/html" id="tableBodyTemplate">
       <tr class="context">
         <td class="ProductID"></td>
         <td class="ProductName"></td>
       </tr>
    </script>    

    <script type="text/javascript" charset="utf-8">
        var s = 0;
        var t = 10;
        var uriProducts = "ClientBin/DataService.axd/InfoCentreV01-Web-ProductService/GetProducts?";
        var tableBodyTemplate = $("#tableBodyTemplate").html();
        var prdtTemplate = $("#productsListTemplate").html();
        $("#productsList").html(prdtTemplate);


        function incS() {
            s = s + 10;
            getProducts()
        }

        function decS() {
            if (s > 1) {
                s = s - 10;
            }
            getProducts();
            
        } 
        
        function getProducts() {
            var uri = uriProducts + "s=" + s + "&t=" + 10;
            $.getJSON(uri, function(products) {
                var context = products.Results;
                $("#tableBody").html('');
                $("#tableBody").html(tableBodyTemplate);
                $('#products').autoRender(context);
                
            });
        }            
    </script>  

</body>
</html>