2RSS Reader
Your RSS list: Login Top RSS feeds: --- Select RSS feed --- Yahoo! News - World BBC News | News Front Page | World Edition Reuters: Top News WashingtonPost.com - World Christian Science Monitor | World Yahoo! News - Top Stories Moreover: Top Stories Wired News: Top Stories Reuters: World CNET News.com Internet News - Top News Yahoo! News - Technology MSDN Just Published InfoWorld: Top News PCWorld.com - Latest News Stories Variety.com Yahoo! News - Entertainment Christian Science Monitor | Arts/Entertainment Dilbert Reuters: Entertainment Moreover: Entertainment ABC Entertainment BBC News | Entertainment | World Edition ESPN.com Yahoo! News - Sports Moreover: Sports top stories WashingtonPost.com - Sports BBC Sport | BBC Sport Plus | World Edition WashingtonPost.com - Nation Yahoo! News - U.S. National Christian Science Monitor | USA MrSwing's Free Trading Education Yahoo! Health Reuters: Business Wired News: Business or Your RSS feed:
DECLARE @string2check varchar(50) DECLARE @character2find char SET @string2check = 'this is a very long string' SET @character2find = 'i' PRINT LEN(@string2check) - LEN(REPLACE(@string2check, @character2find, ''))
CREATE FUNCTION udf_CountCharOccurence ( @string2check varchar(500) , @character2find char )RETURNS INT BEGIN RETURN (LEN(@string2check) - LEN(REPLACE( @string2check, @character2find) ) ) END GO
CREATE FUNCTION udf_CountCharOccurenceCaseSensitive ( @string2check varchar(500) , @character2find char )RETURNS INT BEGIN RETURN (LEN(@string2check) - LEN(REPLACE( @string2check COLLATE SQL_Latin1_General_Cp1_CS_AS, @character2find COLLATE SQL_Latin1_General_Cp1_CS_AS, '') ) ) END GO
PRINT dbo.udf_CountCharOccurenceCaseSensitive('This is a long text','i')
SELECT * FROM Users WHERE dbo.udf_CountCharOccurenceCaseSensitive(EmailAddress,'.') > 2
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { //iterate through all the rows in our table called yourtable //excluding the first row because those are column titles $("#yourtablename tr:not(:first)").each(function() { //get the value of the table cell located //in the third column of the current row var priceYesterday = $(this).find("td:nth-child(2)").html(); var priceToday = $(this).find("td:nth-child(3)").html(); //check if its greater than zero if (priceToday > priceYesterday){ //change the color of the text to green if its a positive number $(this).find("td:nth-child(3)").css("color", "#00FF00"); } else if(priceToday < priceYesterday){ //change the color of the text to red if its a negatice number $(this).find("td:nth-child(3)").css("color", "#FF0000"); } }); //iterate through all the rows in our table called yourtable //excluding the first row because those are column titles $(".yourtableclassname tr:not(:first)").each(function() { //get the value of the table cell located //in the third column of the current row var priceYesterday = $(this).find("td:nth-child(2)").html(); var priceToday = $(this).find("td:nth-child(3)").html(); //check if its greater than zero if (priceToday > priceYesterday){ //change the color of the text to green if its a positive number $(this).find("td:nth-child(3)").css("color", "#00FF00"); } else if(priceToday < priceYesterday){ //change the color of the text to red if its a negatice number $(this).find("td:nth-child(3)").css("color", "#FF0000"); } }); }); </script>
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { //iterate through all the rows in our table called yourtable //excluding the first row because those are column titles $("#yourtablename tr:not(:first)").each(function() { //get the value of the table cell located //in the third column of the current row var priceYesterday = $(this).find("td:nth-child(2)").html(); var priceToday = $(this).find("td:nth-child(3)").html(); //check if its greater than zero if (priceToday > priceYesterday){ //change the color of the text to green if its a positive number $(this).find("td:nth-child(3)").css("color", "#00FF00"); } else if(priceToday < priceYesterday){ //change the color of the text to red if its a negatice number $(this).find("td:nth-child(3)").css("color", "#FF0000"); } }); //iterate through all the rows in our table called yourtable //excluding the first row because those are column titles $(".yourtableclassname tr:not(:first)").each(function() { //get the value of the table cell located //in the third column of the current row var priceYesterday = $(this).find("td:nth-child(2)").html(); var priceToday = $(this).find("td:nth-child(3)").html(); //check if its greater than zero if (priceToday > priceYesterday){ //change the color of the text to green if its a positive number $(this).find("td:nth-child(3)").css("color", "#00FF00"); } else if(priceToday < priceYesterday){ //change the color of the text to red if its a negatice number $(this).find("td:nth-child(3)").css("color", "#FF0000"); } }); }); </script> </head> <body> <h3>Iterating to the table via table id</h3> <table id="yourtablename"> <thead> <tr> <td>Product Name</td> <td>Yesterday</td> <td>Today</td> </tr> </thead> <tbody> <tr> <td>Egg</td> <td>1.95</td> <td>2.10</td> </tr> <tr> <td>Sugar</td> <td>1.92</td> <td>1.88</td> </tr> <tr> <td>Milk</td> <td>1.95</td> <td>1.97</td> </tr> <tr> <td>beans</td> <td>3.15</td> <td>3.06</td> </tr> </tbody> </table> <h3>Iterating to the table via class name</h3> <table class="yourtableclassname"> <thead> <tr> <td>Product Name</td> <td>Yesterday</td> <td>Today</td> </tr> </thead> <tbody> <tr> <td>Egg</td> <td>1.95</td> <td>2.10</td> </tr> <tr> <td>Sugar</td> <td>1.92</td> <td>1.88</td> </tr> <tr> <td>Milk</td> <td>1.95</td> <td>1.97</td> </tr> <tr> <td>beans</td> <td>3.15</td> <td>3.06</td> </tr> </tbody> </table> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; namespace KeithRull.SimpleExpressionCalculator { class Program { static void Main(string[] args) { string expressionToEvaluate = "4 + 5 + 10 - 4 / 5 * 2"; var result = new DataTable().Compute(expressionToEvaluate, null); Console.Write(result); Console.Read(); } } }
namespace KeithRull.SimpleExpressionCalculator { class Program { static void Main(string[] args) { string expressionToEvaluate = "Tan(20) * 2"; var p = new IronPython.Hosting.PythonEngine(); var result = p.EvaluateAs<double>(expressionToEvaluate); Console.Write(result); Console.Read(); //will output: 4.47432188844948 } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using NCalc; namespace KeithRull.SimpleExpressionCalculator { class Program { static void Main(string[] args) { string expressionToEvaluate = "Tan(20) * 2"; Expression e = new Expression(expressionToEvaluate); var result = e.Evaluate(); Console.Write(result); Console.Read(); //will output: 4.47432188844948 } } }
<script> $(document).ready(function() { //set the color of the row based on rowindex $(".report-table-horizontal tr:even").css("background-color", "#FFF8DC"); $(".report-table-horizontal tr:odd").css("background-color", "#FFFBD0"); //highlight the table titles by selecting the first row $(".report-table-horizontal tr:first").css("background-color", "#FFCC33"); }); </script>
<script> $(document).ready(function() { //set the color of the row based on rowindex $(".report-table-vertical tr:even").css("background-color", "#FFF8DC"); $(".report-table-vertical tr:odd").css("background-color", "#FFFBD0"); //set the color of the first column $(".report-table-vertical td:first-child").css("background-color", "#FFCC33"); }); </script>
$(".report-table-vertical td:nth-child(1)").css("background-color", "#FFCC33");
<html> <head> <title>Working with tables in jQuery</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script> $(document).ready(function() { //set the color of the row based on rowindex $(".report-table-horizontal tr:even").css("background-color", "#FFF8DC"); $(".report-table-horizontal tr:odd").css("background-color", "#FFFBD0"); //highlight the table titles by selecting the first row $(".report-table-horizontal tr:first").css("background-color", "#FFCC33"); //set the color of the row based on rowindex $(".report-table-vertical tr:even").css("background-color", "#FFF8DC"); $(".report-table-vertical tr:odd").css("background-color", "#FFFBD0"); //set the color of the first column $(".report-table-vertical td:nth-child(1)").css("background-color", "#FFCC33"); }); </script> <style type="text/css"> body { font-family: Arial; } </style> </head> <body> <h2>Alternating row colors in a table with jquery</h2> <table class="report-table-horizontal"> <tr> <td width="100px">Firstname</td> <td width="100px">Lastname</td> <td>Email</td> </tr> <tr> <td>Keith</td> <td>Rull</td> <td>keith@example.com</td> </tr> <tr> <td>Charissa</td> <td>Rull</td> <td>charissa@example.com</td> </tr> <tr> <td>Zoe Adrielle</td> <td>Rull</td> <td>zoe@example.com</td> </tr> <tr> <td>John</td> <td>Doe</td> <td>jdoe@example.com</td> </tr> <tr> <td>Jane</td> <td>Doe</td> <td>janedoe@example.com</td> </tr> <tr> <td>Tony</td> <td>Brown</td> <td>brown@example.com</td> </tr> <tr> <td>Lisa</td> <td>Sally</td> <td>sally@example.com</td> </tr> </table> <br /> <h2>Change the color of the the first column with jquery</h2> <table class="report-table-vertical"> <tr> <td width="100px">Product</td> <td>Price</td> </tr> <tr> <td>Eggs</td> <td>$1.10</td> </tr> <tr> <td>Flour</td> <td>$1.20</td> </tr> <tr> <td>Carrots</td> <td>$0.35</td> </tr> <tr> <td>Cucumber</td> <td>$0.50</td> </tr> <tr> <td>Melon</td> <td>$0.99</td> </tr> </table> </body> <html>
Sometimes its the basic things that we tend to forget. It's true. One example is encrypting the ViewState. Someone asked me this question today and I had to admit that I wasn't able to answer on top of my head. Whats funny is that I've been doing it all along but never told myself to remember how.
Anyhow, lets go back to the topic on how to encrypt the ViewState in ASP.NET.
Prior to .NET 2.0 the way you would do this is via the machineKey element validation attribute. In .NET 2.0 onwards Microsoft provided us with an option to specify ViewState encryption in the page level or web.config level via the ViewStateEncryptionMode attribute.
ViewStateEncryptionMode has three enumeration values that you could use defending on what you need. They are Auto, Never and Always. ViewStateEncryptionMode.Auto means that the page will be encrypted if a control request for encryption. By default the value for ViewStateEncryptionMode is set to Auto. ViewStateEncryptionMode.Never means that ASP.NET will not encrypt the ViewState on your page even if a control request for it. This is a good bypassing mechanism if and only if you know that the page does not need to have ViewState encryption on it. ViewStateEncryptionMode.Always on the otherhand will encrypt your page all the time. A good practice for pages with sensitive information is to always set this ViewStateEncryptionMode to Always as you don't want anybody compromising your ViewState.
To enable ViewState encryption in the page all you need to do is specify the value for ViewStateEncryptionMode at the Page directive
<%@Page ViewStateEncryptionMode="Always" %>
To enable ViewState encryption via web.config to apply to the whole application
<configuration> <system.web> <pages ViewStateEncryptionMode="Always" /> </system.web> </configuration>
One thing to remember though is that you can't set ViewStateEncryptionMode via code
To request for ViewState encryption inside a control all you need to do is call RegisterViewStateEcryption() method from the Page class
protected override void OnInit(EventArgs e) { base.OnInit(e); if(Page != null) { Page.RegisterRequiresViewStateEncryption(); } }
Ahhh, such reverie. Now I need to remember this for future use (or questions). Cheers!
In case you missed the announcement, ASP.NET MVC 2 is out and ready for the picking. Go get it here.
Enums are special value types that lets you specify a group of numeric constants. For example:
enum Languages { English, Spanish, Chinese, Japanese, French, Filipino }
We can use an anum as follows:
Languages ls = Languages.Filipino bool canSpeakFilipino (ls == Languages.Filipino) //return true
By default enums have an underlying ingtegral value which is of type int and the constant values start from 0 to infinity based on how they enum members are declared. You can also specify an alternate integral type as follows
enum Languages: byte { English, Spanish, Chinese, Japanese, French, Filipino }
Or do an explicit value for each enum member
enum Languages: byte { English = 1, Spanish = 2, Chinese = 4, Japanese = 8, French = 16, Filipino = 32 }
You can also assign some values of the enum and let the compiler decide on the value of the other unassigned enum members which is an increment of 1 by the previous value of the previous member.
enum Languages { English = 1, Spanish, Chinese, Japanese = 8, French, Filipino }
The code above will result to English = 1, Spanish = 2, Chinese = 3, Japanese = 8, French = 9, Filipino = 10
It is a good practice to define a value for 0 in enums to signify "no value" as 0 in enums mean the absence of all properties possible. Defining a value for 0 with make it a valid state for your enum.
enum Languages: byte { None = 0, English = 1, Spanish = 2, Chinese = 4, Japanese = 8, French = 16, Filipino = 32 }
This is specifically useful when you are using flags attribute on your enum as this will catch values presented as 0
[Flags] enum Languages: byte { None = 0, English = 1, Spanish = 2, Chinese = 4, Japanese = 8, French = 16, Filipino = 32 }
Language ls; //will default to 0 Console.WriteLine(ls); //will print None on the console
Adding the [Flags] attribute to your enums will help you "combine values" of enums into one.
Language ls = Language.English | Language.Filipino | Language.French; Console.WriteLine("I can speak {0}", ls); //The code above will print: I can speak English, Filipino, French
Add to favorites · FAQ