2RSS.com :: RSS feeds, RSS directory, RSS articles, RSS syndication, XML, RDF, news ... Directory My RSS 2RSS Reader Software Articles Contact Blog Forum
2RSS.com :: RSS feeds, RSS directory, RSS software, RSS scripts, RSS articles, RSS syndication, XML, RDF, news and more.


2RSS Reader

One stop for your RSS daily news. No software to install. Online news from most read RSS sources: Yahoo, BBC, Wired, Reuters, Moreover, ESPN, Variety and more.

Your RSS list:    Login
Top RSS feeds: or
Your RSS feed:

 

Keith Rull

Expression Studio 4 is out and my 60-day tool
Wed, 09 Jun 2010 22:06:43 GMT
I was really excited last Monday after seeing Expression Studio 4 has been released (I have to admit that I'm one of those developers who logged in at MSDN at 12 midnight to check if the RTM bits are already out. hehe). I think this is great news for all XAMLers all over the world. On thing that I'm really sad about though is that our corporate MSDN license only has Expression Studio 4 Professional and not the Ultimate version. Bummed. So I ended up downloading the 60 day trial up until I can figure out how I can get a copy of the full version (OK, here's the part that I ask donations to get a full copy but I'll leave that out. LOL).

Sad, but still happy. At least I have 60 days to enjoy this new tool. ;)

How To: Count the occurrence of a character in a string in SQL
Wed, 09 Jun 2010 21:35:38 GMT
Last night I was trying to cleanup the spammers from the database of devpinoy.org and while I was evaluating the result sets i was able to conclude that aside from using common spam text like 'cheap', 'buy', 'free', 'deal', 'viagra', 'prozac' that 30% of the false emails that spam accounts are using multiple dots on their email address. A good example is a subset below from the list of offenders that I found in the devpinoy db.


Having found that fact I immediately created a sql script that will delete users from the database if they have more than 2 dots in their email address.

Enough with the side note and here is some code.

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, ''))

What the code above is doing is that it is removing the characters that matched our search key and then subracts the length of that string to the original string to find the total occurrence of the character we are looking for.

Now, if you want to use this as a function you can use this:

CREATE FUNCTION udf_CountCharOccurence
(    @string2check varchar(500)
,    @character2find char )RETURNS INT BEGIN RETURN (LEN(@string2check)
- LEN(REPLACE(
                                @string2check,
@character2find)                                         )
                                ) END GO
The code above works great but there's a catch. If you are concerned with case sensitivity then the code above wont work. The way around it is to use COLLATION which is supported by the SQL function below:

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
In order to use this in your query all you need to do is
PRINT dbo.udf_CountCharOccurenceCaseSensitive('This
is a long text','i')
Or if you want to put it to use to meet the criteria that I mentioned about dots on emails you can do it this way:
SELECT * FROM Users WHERE dbo.udf_CountCharOccurenceCaseSensitive(EmailAddress,'.')
> 2

HTH


How To: Change table cell color depending on its value using jQuery
Wed, 09 Jun 2010 18:32:49 GMT
Here's a nifty trick using jQuery on how to iterate on all rows of a table except the first row, how to get the value of a column in the current row being iterated and how to change the table cell color depending on the value it contains.

In this case we wanted to change the color of the 3rd column depending on whether it is higher or lower than the second column. There are two examples in here. The first one is select the table via its ID and the second version is selecting the table based on its class name.

 <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>

Below is the full source for this sample:

Iterating to the table via table id

Product Name Yesterday Today
Egg 1.95 2.10
Sugar 1.92 1.88
Milk 1.95 1.97
beans 3.15 3.06

Iterating to the table via class name

Product Name Yesterday Today
Egg 1.95 2.10
Sugar 1.92 1.88
Milk 1.95 1.97
beans 3.15 3.06

<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>

You can copy and paste the code above and put it on a new file to see it running or you can view this sample running here: jquery_change_table_cell_color_depending_on_value.html (3.05 KB)

HTH

How To: Calculate Mathematical Expressions in .NET
Tue, 18 May 2010 23:41:31 GMT
Everyday you learn something new. You do. That is if you let yourself to be taught everyday.

I didn't know that you could solve this expression string in .NET in one line of code: "4 + 5 + 10 - 4 / 5 * 2"
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(); } } } 
The result is 17.4. Nifty huh? You can also group the expressions to display a clearer evaluation instruction and it still will work.

string expressionToEvaluate = "(((4 + 5) + (10 - 4)) / 5) * 2"; //will result to 6

This is all cool but there's a gotcha. DataTable.Compute() method can only evaluate simple expressions so your

string expressionToEvaluate = "Tan(10) * 2"; //error

Would throw an exception of type EvaluateException because it could not recognize the function Tan().

One solution you could take to solve this problem is to use a dynamic language in the DLR like IronRuby or IronPython.
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 } } } 
You can check out Kirill Osenkov's post for more info regarding this approach.

Another way which i think is the better way is using a third-party library that already support this like NCalc.

NCalc is an open source Mathematical Expression Evaluator for .NET that can parse any expression and evaluate the result, including static or dynamic parameters and custom functions.

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 } } }
Pretty cool huh?!

Just Released: Silverlight 4 Tools for VS 2010, new SL themes and WCF RIA Services
Tue, 18 May 2010 07:07:19 GMT

Just in case you missed it, Tim Heuer has announced that Silverlight 4 Tools for Visual Studio 2010, WCF RIA Services and 3 new SL themes have been released today. This is an exciting news for Silverlight aficionados who have been waiting for the RTM version of SL4 Tools since the last RC who are itching to put their hands on this new set of goodies.

If you want to learn more about SL, the best place to start is to go to Silverlight.net and checkout the Getting Started section. I would also suggest you follow Tim's blog and subscribe to his updates and also as follow Silverlight Cream for the latest stream of info from SL developers.

If you are looking for Silverlight books for beginners my suggestion would be to get Laurent's book (a SL4 edition will come out in September) and start from there. You should also checkout Jeff Pairies mind boggling book about Silverlight animation and also John Papa's classic SL book that talks about data-driven services with Silverlight. Although some of these books are 1-2 versions behind I still believe that there are a lot of value in them that you can still apply with your Silverlight 4 projects.



I've just downloaded the package via the WPI and I can't tell you how much excited I am to see SL4T-4-VS2010 RTMed. This will surely be a fun week.




Nice, time to rock this ship!
How To: Change the row and column colors of a table using jQuery
Thu, 06 May 2010 00:23:11 GMT

Here's a quick and easy way to alternate the row colors of a table using jQuery

<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>
The resulting code will apply the to the table and would look like this:



Basically what the code is doing is that it is selecting a css class called "report-table-horizontal" and applies the style to the tr attribute of the table based on their row index whether they are even or odd.

Now if you want to change the color of a  table column you can do so using this 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>



The difference on this code is the third line wherein we specified that the style will be applied on the first td element of the table. Alternately you can use the nth-child(n) selector instead to do the same task:

$(".report-table-vertical
td:nth-child(1)").css("background-color", "#FFCC33");

Hope this helps. You can view the live sample here:
alternating table colors with jquery.html (2.42 KB)

or just copy and paste the HTML code below to a new file:
<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>

How To: Encrypt the ViewState in ASP.NET
Tue, 04 May 2010 21:40:43 GMT

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!

VS2010 Keyboard shortcuts released
Mon, 12 Apr 2010 22:03:17 GMT



Just in case you need to freshen up on the keyboard shortcuts for VS 2010 you can get them here.
ASP.NET MVC 2 is out!!
Fri, 12 Mar 2010 02:51:04 GMT

In case you missed the announcement, ASP.NET MVC 2 is out and ready for the picking. Go get it here.

How To: Working with Enums in C#
Sat, 09 Jan 2010 02:40:44 GMT

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

Free Laptop Bag? LOL
Thu, 03 Dec 2009 23:51:10 GMT
I just saw this posting from sandiego.craigslist.com and it really made me laugh. LOL.

http://sandiego.craigslist.org/csd/sys/1493519713.html



Heheh. Funny.
By keith.rull@gmail.com
Keith Rull

Add to favorites · FAQ

 

© 2003-2006 2RSS.com · A BloggyNetwork site · Terms of use