Search

just show me the code

Monday, May 11, 2009

Random Objects should be static

thanks to help from dotnetperls.

static Random _r = new Random();
static void F()
{
    // Use class-level Random so that when this
    // method is called many times, it still has
    // good Randoms.
    int n = _r.Next(12);
    // If this declared a local Random, it would
    // repeat itself.
    System.Console.WriteLine(n);
}

using jquery tips

http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx

tip #1

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>



http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js
http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.js

http://code.google.com/apis/ajaxlibs/documentation/index.html#jqueryUI

google.load("jquery", "1.3.2");
google.load("jqueryui", "1.7.1");
google.load("prototype", "1.6.0.3");
google.load("scriptaculous", "1.8.2");
google.load("mootools", "1.2.2");
google.load("dojo", "1.3.1");
google.load("swfobject", "2.1");
google.load("yui", "2.7.0");

Thursday, May 7, 2009

using System.Xml.Linq

using System.Xml.Linq;
protected void Button1_Click(object sender, EventArgs e)
{
  XDocument doc = new XDocument();
  XElement projectElement = new XElement("Project"
     , new XAttribute("ProjectName", "xxx")
     , new XAttribute("ProjectDescription", "xxx")
     , new XAttribute("DateStart", "xxx")
     , new XAttribute("DateEnd", "xxx") );
  doc.Add(projectElement);
  for (int i = 0; i < 5; i++)
  {
    projectElement.Add(new XElement("Property"
      , new XAttribute("PropertyName", "PropertyName" + i)
      , new XAttribute("PropertyValue", "PropertyValue" + i) ));
  }
  this.lbl.Text = Server.HtmlEncode(doc.ToString());
  this.lbl.DataBind();
}



will produce xml that looks like this




<Project ProjectName="xxx" ProjectDescription="xxx" DateStart="xxx" DateEnd="xxx" >
  <Property PropertyName="PropertyName0" PropertyValue="PropertyValue0" />
  <Property PropertyName="PropertyName1" PropertyValue="PropertyValue1" />
  <Property PropertyName="PropertyName2" PropertyValue="PropertyValue2" />
  <Property PropertyName="PropertyName3" PropertyValue="PropertyValue3" />
  <Property PropertyName="PropertyName4" PropertyValue="PropertyValue4" />
</Project>





 

Tuesday, May 5, 2009

popup and print

the javascript 
 
  136 <script language="javascript">
  137     $(document).ready(function() {
  138         $('#<%=Submit.ClientID %>').click( function() {
  139             popitup('../Public/PrintRegister.aspx');
  140             return true;
  141         }); 
  142     }); 
  143     function popitup(url) {
  144         newwindow = window.open(url, 'name', 'height=600,width=750');
  145         if (window.focus) { newwindow.focus() }
  146         return false;
  147     }
  148 </script>

the button


  110 <asp:ImageButton ID="Submit" runat="server" 
  111  ImageUrl="<%$ Resources:Resource,ImageSubmitPrint %>"
  112  AlternateText="<%$ Resources:Resource,ImageSubmitPrintAltText%>" 
  113  OnClick="Submit_Click" />

 


PrintRegister.aspx


    9 <body class="" onLoad="self.print()"> 
   10     <form id="form1" runat="server">
   11     <div>
   12       Print stuff here
   13     </div>
   14     </form>
   15 </body>

Friday, April 24, 2009

My jQuery Date Range

using jQuery UI Datepickers.
Notice when you select a start date it becomes the min end date
and when you select an end date it becomes the max start date.

<!doctype html>

<html lang="en">
<head>
 <title>jQuery UI Datepicker - Restrict date range</title>
 <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
 <script type="text/javascript" src="../../jquery-1.3.2.js"></script>
 <script type="text/javascript" src="../../ui/ui.core.js"></script>
 <script type="text/javascript" src="../../ui/ui.datepicker.js"></script>
 <script type="text/javascript" src="http://www.mattkruse.com/javascript/date/compact/date.js"></script>

 <link type="text/css" href="../demos.css" rel="stylesheet" />
 <script type="text/javascript">
 $(function() {
  $(".startDatepicker").datepicker({
   showOn: 'button',
   buttonImage: 'images/calendar.gif',
   buttonImageOnly: true,
   dateFormat: "mm/dd/y" ,
   onSelect: function(dateText) {
    //alert(dateText);
    var d = parseDate(dateText);
    alert(d);
    $(".endDatepicker").datepicker('option', 'minDate', d);
   }
  });
  $(".endDatepicker").datepicker({
   showOn: 'button',
   buttonImage: 'images/calendar.gif',
   buttonImageOnly: true,
   dateFormat: "mm/dd/y" ,
   onSelect: function(dateText) { 
    //alert(dateText);
    var d = parseDate(dateText);
    alert(d);
    $(".startDatepicker").datepicker('option', 'maxDate', d);
   }
  });
 
 });
 </script>
</head>
<body>
<div class="demo">

<p>Start Date: <input type="text" id="startDatepicker"   class="startDatepicker"   ></p>
<p>End Date: <input type="text" id="endDatepicker" class="endDatepicker"></p>
</div><!-- End demo -->
</body>
</html>

Thursday, April 23, 2009

TFS Fail a build AND create a work item when unit test fails

thanks to http://social.msdn.microsoft.com/forums/en-US/tfsbuild/thread/b6fa6aa8-1861-4cd0-b9bb-4eeb64432651/




  229   <Target Name="AfterTest">
  230     <!-- Refresh the build properties. -->
  231     <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
  232                         BuildUri="$(BuildUri)"
  233                         Condition=" '$(IsDesktopBuild)' != 'true' ">
  234       <Output TaskParameter="TestSuccess"
  235               PropertyName="TestSuccess" />
  236     </GetBuildProperties>

  237 
  238     <!-- Set CompilationStatus to Failed if TestSuccess is false. -->
  239     <SetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
  240                         BuildUri="$(BuildUri)"
  241                         CompilationStatus="Failed"
  242                         Condition=" '$(IsDesktopBuild)' != 'true' and '$(TestSuccess)' != 'true' ">
  243     </SetBuildProperties>
  244     <CreateNewWorkItem
  245       BuildNumber="$(BuildNumber)"
  246       BuildURi="$(BuildURI)"
  247       Description="The CreateNewWorkItem task created this bug."
  248       TeamProject="$(TeamProject)"
  249       TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
  250       Title="Unit Test Failure in $(BuildNumber)"
  251       WorkItemFieldValues="$(WorkItemFieldValues)"
  252       WorkItemType="$(WorkItemType)"
  253       Condition=" '$(IsDesktopBuild)' != 'true' and '$(TestSuccess)' != 'true' ">
  254     </CreateNewWorkItem>
  255   </Target>

Tuesday, April 14, 2009

Let me google that for you

http://lmgtfy.com/?q=dry+code+wiki

This is funny. don't let anyone hassle you

Wednesday, April 1, 2009

sweet regular expression tester site

I finally found a sweet regular expression tester. http://regexpal.com/

here is my test for phone number validation which will allow user to enter (xxx)xxx-xxxx or xxx-xxx-xxxx or xxxxxxxxxx

^((((\(\d{3}\)?)|(\d{3}-))?\d{3}-\d{4})|(\d{10}))

234-432-2342
(324)432-0909
(324)6we-0909
(324)63a-0909
234-432-2342
(234)324-5444
3424324234
234-432-2342
2311212321
asdf323243
1231321
1564344445

thanks regexpal

Tuesday, March 3, 2009

Odds

Bet Actual Odds Odds Paid House Edge
Pass / Come 251:244 1:1 1.41%
Don’t Pass / Don’t Come (Bar 12) 1031:949 1:1 1.36%
Pass Odds / Come Odds Same as paid 2:1 on 4 or 10
3:2 on 5 or 9
6:5 on 6 or 8
0%
Don’t Pass Odds / Don’t Come Odds Same as paid 1:2 against 4 or 10
2:3 against 5 or 9
5:6 against 6 or 8
0%
Yo (11) 17:1 15:1 11.11%
Yo (11) 17:1 16:1 5.55%
Field 5:4 1:1 on 3,4,9,10 or 11
2:1 on 2 and 12
5.56%
Field 5:4 1:1 on 3,4,9,10 or 11
2:1 on 2, 3:1 on 12
2.78%
Hard way 4 / Hard way 10 8:1 7:1 11.11%
Hard way 6 / Hard way 8 10:1 9:1 9.09%
Place 4 / Place 10 2:1 9:5 6.67%
Place 5 / Place 9 3:2 7:5 4%
Place 6 / Place 8 6:5 7:6 1.52%

House edge for the 2 different Yo bets 15:1 and 16:1

-1*34/36 + 15 * 2/36
    -0.11111111111111111111111111111111  = 11.11% House Edge
-1*34/36 + 16 * 2/36
    -0.055555555555555555555555555555556 = 5.55% House Edge

 

-1 * 34/36 + 16 * 2/36   = 5.55% House Edge
34/36 times you will loose $1 
2/36 times you will win $16 


ref http://en.wikipedia.org/wiki/Craps
ref http://en.wikipedia.org/wiki/Roulette

Pass / Come ----- calculation ------------
-1 * 251/(251+244) + 1 * 244/(251+244)
    -0.01414

Monday, March 2, 2009

RadioButtonList jQuery get and set


    8     <script src="http://www.google.com/jsapi"></script>  
    9     <script type="text/javascript">  
   10
   11         // Load jQuery
   12         google.load("jquery", "1.3.2");
   13         google.load("jqueryui", "1.7.1");
   14         google.load("yui", "2.7.0");
   15
   16         google.setOnLoadCallback(function() {  
   17             // Your code goes here.  
   18         });  
   19     </script> 


here is the page aspx

  
    4 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
    5     <script language="javascript">
    6         $(document).ready(function() {
    7             $('#rblDiv input').click(function() {
    8                 var selected = $("#rblDiv input:radio:checked").val();
    9                 $("#output").text(selected);
   10             });
   11             $("#btnChangeValue").click(function() {
   12                 $('#<%=RadioButtonList1.ClientID %>').find("input[value='Three']").attr("checked", "checked");
   13                 $('#rblDiv input:radio:checked').trigger('click');
   14             });
   15
   16         });  
   17     </script> 
   18 </asp:Content>
   19 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
   20     <div id="rblDiv">
   21         <asp:RadioButtonList ID="RadioButtonList1" runat="server">
   22             <asp:ListItem Value="One">1</asp:ListItem>
   23             <asp:ListItem Value="Two">2</asp:ListItem>
   24             <asp:ListItem Value="Three">3</asp:ListItem>
   25         </asp:RadioButtonList>
   26     </div>
   27     <input id="btnChangeValue" type="button" value="Change to Three" />
   28     <div id="output"></div>
   29 </asp:Content>






for the checkboxlist check out this and this post

Contributors