tag:blogger.com,1999:blog-37295691857169977472024-03-13T07:55:46.521+07:00X189 blog.NET & ProductivityAnonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.comBlogger34125tag:blogger.com,1999:blog-3729569185716997747.post-51145470036237122122015-04-05T18:35:00.000+07:002015-04-18T20:44:49.672+07:00Adding Dynamic Data to an ASP.NET MVC5 websiteASP.NET Dynamic Data lets us mange data right on the website instead of having to access the database. You can add it as an admin interface to your MVC website, but it seems there has never been an easy way to do so. In this article I'll try to make the task easier for you if you have never done it.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLzGUy4xi4kIDrlvn_YivEGS_NKciTvj19mSAO0Z49eGnnNKYAsmZcpToj-qJekOx4D1JmVqgnLFgUHhe5yoI-Aga3PbmSKyvfU_6tPB7HDx01lLI6WmqlOZDqL-3xIO6OBgTK7VcslrQ/s1600/dynamic-data-ui.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Dynamic Data UI" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLzGUy4xi4kIDrlvn_YivEGS_NKciTvj19mSAO0Z49eGnnNKYAsmZcpToj-qJekOx4D1JmVqgnLFgUHhe5yoI-Aga3PbmSKyvfU_6tPB7HDx01lLI6WmqlOZDqL-3xIO6OBgTK7VcslrQ/s1600/dynamic-data-ui.jpg" height="270" title="" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Dynamic Data UI</td></tr>
</tbody></table>
<br />
First you would need to install the NuGet package <a href="https://www.nuget.org/packages/Microsoft.AspNet.DynamicData.EFProvider/6.0.0" target="_blank">Microsoft ASP.NET DynamicData EFProvider</a>. The package will add some templates for generating the views based on your data context. But we will need more than that to make it work.<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl-QURgA9nRsUH4buN3Qd3DH4NUiejjZhINCCZpEmv_r82AHzLI6_hylj8BDS4q5bgmw58Pn3PbdVOKt-kkbM_ssWoKzCCBfEurK2OjEna9UfM2ODPrpmJU5NT2wcKLaC-ZfWkfIbdwpo/s1600/dynamic-data_templates.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img alt="Dynamic Data - templates" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl-QURgA9nRsUH4buN3Qd3DH4NUiejjZhINCCZpEmv_r82AHzLI6_hylj8BDS4q5bgmw58Pn3PbdVOKt-kkbM_ssWoKzCCBfEurK2OjEna9UfM2ODPrpmJU5NT2wcKLaC-ZfWkfIbdwpo/s1600/dynamic-data_templates.jpg" height="320" title="" width="137" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The templates</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjscpqIxZf_Cb8K79pS0jllEixkO6PO6NU2YcvX-BmDtLAEskSzdLtCH0iW1AXmd1eUwBNzw72jCAkJWFeQFcH_wSwdmAWOAuU9t94SwDLTriKFaBLwsGoEceHlDVkhuNqHBNZbecD197Q/s1600/DynamicData+EFProvider.jpg" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-left: auto; margin-right: auto; text-align: center;"><img alt="DynamicData EFProvider package" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjscpqIxZf_Cb8K79pS0jllEixkO6PO6NU2YcvX-BmDtLAEskSzdLtCH0iW1AXmd1eUwBNzw72jCAkJWFeQFcH_wSwdmAWOAuU9t94SwDLTriKFaBLwsGoEceHlDVkhuNqHBNZbecD197Q/s1600/DynamicData+EFProvider.jpg" height="228" title="" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">DynamicData EFProvider package</td></tr>
</tbody></table>
<br />
<br />
Having the DynamicData folder from the package, now we need to create a new <i>ASP.NET Dynamic Data Entities Web Application</i> to get some files from it.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSBustdI2O7I7Q5LIcqhW2mlkFBJQs0SpPR_vizSEKkSELOCh6f4byw_ii12L8BhJuR16JF7bz8UAAg47kLtAI8eu_WEWCFJ8g-2BhNiAVli5IncNocXkIAgyduzE7OIdfGRgaTLJO7DQ/s1600/new-dynamic-data-project.jpg" imageanchor="1"><img alt="Creating new Dynamic Data web app" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSBustdI2O7I7Q5LIcqhW2mlkFBJQs0SpPR_vizSEKkSELOCh6f4byw_ii12L8BhJuR16JF7bz8UAAg47kLtAI8eu_WEWCFJ8g-2BhNiAVli5IncNocXkIAgyduzE7OIdfGRgaTLJO7DQ/s1600/new-dynamic-data-project.jpg" height="185" title="" width="640" /></a></div>
<br />
After creating the project, let's copy these files and folders to the DynamicData folder in our website:<br />
Default.aspx, Default.aspx.cs, Site.master, Site.master.cs, Site.css, and Web.config; Content and Filters folders.<br />
<ul>
<li>In <i>Site.master</i></li>
<ul>
<li>Change "~/Site.css" to "Site.css" (because the files are now in a same folder).</li>
<li>The href for "Back to home page" is for the homepage of our administration UI, let's change it to "~/dbadmin/home" (I use <i>dbadmin/{pagename}</i> for routeUrl, because using <i>dbadmin</i> only will mess up with the default route).</li>
<li>Add <i>~/</i> before <i>DynamicData/Content/Images/back.gif</i>.</li>
</ul>
<li>Change "~/Site.master" to "Site.master" for <i>Default.aspx</i>.</li>
<li>Change "~/Site.master" to "..\Site.master" for all the views in PageTemplates.</li>
<li>Because ASP.NET Dynamic Data is WebForms, we need to install the package <a href="https://www.nuget.org/packages/AspNet.ScriptManager.jQuery/2.1.3" target="_blank">AspNet.ScriptManager.jQuery</a> in order for the <i>asp:ScriptManager</i> controls to work.</li>
</ul>
<br />
Create a new class called <i>Registration</i> in your DynamicData folder. Change <i>ApplicationDbContext</i> to the data context you want to use for generating tables and fields for data management.<br />
<div>
<pre class="brush:csharp">using System.Web.DynamicData;
using System.Web.Routing;
using DynamicDataSample.Models;
using Microsoft.AspNet.DynamicData.ModelProviders;
namespace DynamicDataSample.DynamicData
{
public class Registration
{
public static readonly MetaModel DefaultModel = new MetaModel();
public static void Register(RouteCollection routes)
{
DefaultModel.RegisterContext(
new EFDataModelProvider(() => new ApplicationDbContext()),
new ContextConfiguration { ScaffoldAllTables = true });
// This route must come first to prevent some other route from the site to take over
routes.Insert(
0,
new DynamicDataRoute("dbadmin/{table}/{action}")
{
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = DefaultModel
});
routes.MapPageRoute(
"dd_default",
"dbadmin/{pagename}",
"~/DynamicData/Default.aspx");
}
}
}
</pre>
</div>
<div>
<br /></div>
<div>
Here is how your DynamicData folder should be at this point:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz5bM7c4YoSLFGTN9tR5ewY0va1jZclq8OqCgj9o4kivwzmHQvxVPNQk_3iX7vXD7wv6Z2iGf_REjb9B-dGhlKFXQCaqf_9R75IX80UWyKaV9UGUHu1ESso-dG5WKWCB3FcvZPWKt5ln8/s1600/dynamic-data-folder.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Dynamic Data folder" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz5bM7c4YoSLFGTN9tR5ewY0va1jZclq8OqCgj9o4kivwzmHQvxVPNQk_3iX7vXD7wv6Z2iGf_REjb9B-dGhlKFXQCaqf_9R75IX80UWyKaV9UGUHu1ESso-dG5WKWCB3FcvZPWKt5ln8/s1600/dynamic-data-folder.jpg" title="" /></a></div>
<br />
Build the project, you will notice there's an error in <i>Default.aspx.cs</i>, we need to change the <i>Global</i> class to our new <i>Registration</i> class to fix:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfrn5KgkCT2COI2h6FHc_UvXUimCRU6AEsu6rQ8iVDaKVaqnKn6qyj0wDuhltDzQ2FJ_XmsIDrp6qHUi3_WlyvZ6aV-iNCm_VA99pBhTNUpkrI9gYm4ZQ56nBqZN4_V2Kf_OF_uUv9lVI/s1600/dynamic-data_default.aspx.cs.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Default.aspx.cs class" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfrn5KgkCT2COI2h6FHc_UvXUimCRU6AEsu6rQ8iVDaKVaqnKn6qyj0wDuhltDzQ2FJ_XmsIDrp6qHUi3_WlyvZ6aV-iNCm_VA99pBhTNUpkrI9gYm4ZQ56nBqZN4_V2Kf_OF_uUv9lVI/s1600/dynamic-data_default.aspx.cs.jpg" height="120" title="" width="640" /></a></div>
<div>
<br /></div>
<div>
One more step: call the <i>Register</i> method for Dynamic Data in your <i>Global.asax.cs</i>, notice that it must be before the <i>RegisterRoutes</i>:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnHmtZSle-3mdAkDuvLlPsN3j_0jvugISlU1DVB3g86Y5mB5o-nxgLDKDGs7zhfqbtUNyX4miNi9O1itqnd_usIzieh7BYW24G3zetQoR5N2s4aUnjwxu3fLRyP2geTTIK67F6hkzZUt4/s1600/register-dynamic-data.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnHmtZSle-3mdAkDuvLlPsN3j_0jvugISlU1DVB3g86Y5mB5o-nxgLDKDGs7zhfqbtUNyX4miNi9O1itqnd_usIzieh7BYW24G3zetQoR5N2s4aUnjwxu3fLRyP2geTTIK67F6hkzZUt4/s1600/register-dynamic-data.jpg" height="155" width="640" /></a></div>
<br /></div>
<div>
If everything is correct, you will see the Dynamic Data interface when you run the website and go to <i>/dbadmin/home</i>:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdpUl9Ffb860cSNbwsUKPwIrg_8nzUsDOXxxZJr7oNHCZlg02_QnxdowWryYG6ErN596haaDHigvzIDf1N_7rxRPnn34aW9Jvb8fEQcNaLMyaG4B8H7PNgAoVM3ntrnsoyGJnmeN5vwU8/s1600/dynamic-data-homepage.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Dynamic Data homepage" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdpUl9Ffb860cSNbwsUKPwIrg_8nzUsDOXxxZJr7oNHCZlg02_QnxdowWryYG6ErN596haaDHigvzIDf1N_7rxRPnn34aW9Jvb8fEQcNaLMyaG4B8H7PNgAoVM3ntrnsoyGJnmeN5vwU8/s1600/dynamic-data-homepage.jpg" height="298" title="" width="320" /></a></div>
<br />
For authorization, add something like this to the <i>Site.master.cs</i>:<br />
<pre class="brush:csharp">protected override void OnInit(EventArgs e)
{
if (!Page.User.Identity.IsAuthenticated)
{
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
Response.End();
}
if (!Page.User.IsInRole("Admin"))
{
Response.StatusCode = (int)HttpStatusCode.Forbidden;
Response.End();
}
base.OnInit(e);
}
</pre>
<br />
<b><br /></b>
<b>Reference</b>: <i>Professional ASP.NET MVC 4</i> is a great book, but it's not so great on Dynamic Data. I needed quite a few modifications, googling around, and head-scratching... Hopefully they will have some complete NuGet package for this in the future.</div>
<a href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=5567030" rel="tag" style="display: none;">CodeProject</a>
<script type="text/javascript">
$(function() {
SyntaxHighlighter.highlight();
});
</script>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-55364627045342636002014-05-10T18:06:00.001+07:002014-05-11T11:58:52.655+07:0030 major causes of failure - Think & Grow RichMajor causes of failure, from the book Think and Grow Rich by Napoleon Hill:<br />
<ol>
<li>Unfavorable hereditary background</li>
<li>Lack of a well-defined purpose in life</li>
<li>Lack of ambition to aim above mediocrity</li>
<li>Insufficient education - best-educated are often self-educated</li>
<li>Lack of self-discipline</li>
<li><span style="font-family: Georgia, Times New Roman, serif;">I</span>ll health - including causes by overeating unhealthy foods, lack of exercise...</li>
<li>Unfavorable environmental influences during childhood</li>
<li>Procrastination</li>
<li>Lack of persistence</li>
<li>Negative personality</li>
<li>Lack of controlled sexual urge</li>
<li>Uncontrolled desire for "something for nothing" - gambling</li>
<li>Lack of a well defined power of decision</li>
<li>One or more of the six basic fears</li>
<ul>
<li>Fear of poverty/criticism/ill health/loss of love of someone/old age/death</li>
</ul>
<li>Wrong selection of a mate in marriage</li>
<li>Over-caution</li>
<li>Wrong selection of associates in business</li>
<li>Superstition and prejudice</li>
<li>Wrong selection of a vocation</li>
<li>Lack of concentration of effort</li>
<li>The habit of indiscriminate spending</li>
<li>Lack of enthusiasm</li>
<li>Intolerance</li>
<li>Intemperance</li>
<li>Inability to cooperate with others</li>
<li>Possession of power that was not acquired through self effort</li>
<li>Intentional dishonesty</li>
<li>Egotism and vanity</li>
<li>Guessing instead of thinking</li>
<li>Lack of capital</li>
</ol>
Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-13895228493010654542014-04-20T17:59:00.000+07:002015-04-12T17:39:55.279+07:00async & await - A simple sampleIn this article I'll create a very simple WPF app, then use Async & Await - the new asynchronous programming approach to improve its responsiveness. Hopefully will help you have a quick overview and understanding if you're new to it.<br />
<br />
Suppose we have an empty TextBlock and a Run button, when Run is clicked we want to show a fake percentage status which is increased by 10% every 1 second. It seems very simple, just add a new line to the TextBlock each second with the increased percentage.<br />
<br />
<pre class="brush:csharp">private void Button_Click(object sender, RoutedEventArgs e)
{
for (int i = 1; i <= 10; i++)
{
this.NotificationTextBox.Text += this.GetStatus(i);
}
}
private string GetStatus(int step)
{
Thread.Sleep(1000);
return step * 10 + "%\n";
}
</pre>
<br />
Only it wouldn't work, you will see that instead of adding the percentages one by one, the window is hung for 10 seconds and then all the percentages are shown up at once. The use of <i>async </i>and <i>await </i>will solve this.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<img alt="async await sample" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSdbAUfJ847deFmWw5VIxh-nRlwSnAkJvAxd0GzbZFb5CaGcTNVoPi1cDJeTOM5AYDSQT3cuy38VL5Vnny2crgWLzG-9O4iqWkRCfPmPxa0em-11rXtqIixmxrmpPYHO9AvKmKt7M0BgA/s1600/async-await_sample.png" /></div>
<br />
<br />
First we need to turn <i>GetStatus </i>into an async method, you need to add the <i>async </i>keywork, and create a <i>Task<string></i> so we can use <i>await </i>for it instead of just return <i>string</i>, it's also common to named your async method with "Async" at the end (<i>GetStatusAsync</i>)
<br />
<br />
<pre class="brush:csharp">private async Task<string> GetStatusAsync(int step)
{
Task<string> getStatusTask = Task<string>.Factory.StartNew(() =>
{
Thread.Sleep(1000);
return step * 10 + "%\n";
});
return await getStatusTask;
}
</pre>
<br />
Now it's kind of intuitive to just use the <i>await </i>keyword when calling <i>GetStatusAsync</i>, but don't forget to also make the <i>Button_Click </i>event async, or else you will get the error "The 'await' operator can only be used within an async method" (which did make we get stuck for awhile and wonder "why the hell it doesn't work??")<br />
<br />
<pre class="brush:csharp">private async void Button_Click(object sender, RoutedEventArgs e)
{
for (int i = 1; i <= 10; i++)
{
this.NotificationTextBox.Text += await this.GetStatusAsync(i);
}
}
</pre>
<br />
Run the program a gain and click the button, you will see that the percentages are updated nicely every one second.
<script type="text/javascript">
SyntaxHighlighter.highlight();
</script>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-2638897572311975972013-11-30T18:03:00.000+07:002013-11-30T19:21:40.904+07:00Phone Dev Reference - My WP AppAfter some time working on the project, my first Windows Phone 8 app is finally published on November 27, the app name is <a href="http://www.windowsphone.com/s?appid=c780ee9d-be8a-492e-8488-f0e8dbdefb38" target="_blank">Phone Dev Reference</a>, and here is the description:<br />
<img alt="Phone Dev Reference icon" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKbDMbdntus407623I0DIvz0w2MNghtu3d1jAjOSQ_o6DEeK46I6i9CMPheeVflovTJ6tuY96aP_YmvKQujhUSIaVMsG6RGCtVKFRZID38aOwxDsN_7ckIR1YnoDtJT-NWMzmhUQT-2Es/s1600/PhoneDevRef_Icon.png" height="150" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" title="Phone Dev Reference icon" width="150" />
<br />
<blockquote>
<i>"A quick reference for developers to see the phone controls in live action and how to create them.
The app is not intended to be a step-by-step guide so you should be familiar with Windows Phone or XAML development."</i></blockquote>
The idea is a kind of reference/cheatsheet app that developers can try the phone controls and capacities right on their development phones and also see how we commonly code that. It's a good way to learn Windows Phone programming and can also serve as a quick reference if you already have experience, for sometimes there are things we have to look up again every time we need.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<img alt="Phone Dev Reference screenshots" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-vUK5H15f_9a8yQ0z0l-M3vQou_SulkuJ3koXDTtTc9dnCJD1BdMppig1W5oZx1U4pZnqfae-u2HtssaJy8bHpX3wLy1_sZuN78Tr8t0Drs012O1gbCKZbAtccMIPvAJ-yZwcu-WvaB8/s1600/PhoneDevRef_screenshots.png" height="508" title="Phone Dev Reference screenshots" width="640" /></div>
<br />
The app certification process was pretty smooth thanks to the Store Test Kit built into Visual Studio helped me caught some errors before submitting, it took about more than 3 days until I got the passed certification email from Microsoft.<br />
<br />
The app price is $0.99 and there's a Trial mode with the restriction that you can't see CustomMessageBox, alphabet LongListSelector, and RichTextBox. I tried using ad instead of function restriction for Trial, but when I registered for real ad I realized that PubCenter hasn't supported my country yet, I also intended to try Smaato or AdMob but then I came up with this (hopefully) better idea.<br />
<br />
You can get it here: <a href="http://www.windowsphone.com/s?appid=c780ee9d-be8a-492e-8488-f0e8dbdefb38" target="_blank">http://www.windowsphone.com/s?appid=c780ee9d-be8a-492e-8488-f0e8dbdefb38</a> or search for it on your phone, "dev ref" is a good keyword. (works with Windows Phone 8, it seems I added some new things only for WP8 so you can't get it on WP7)<br />
<br />Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-35366661140236215822013-01-26T16:44:00.000+07:002013-08-17T17:37:48.186+07:00Quiet highlightsSome of my highlights from the book <a href="http://www.amazon.com/dp/B004J4WNL2/" target="_blank">Quiet: The Power of Introverts in a World That Can't Stop Talking</a><br />
<blockquote class="tr_bq">
<i>We’re told that to be great is to be bold, to be happy is to be sociable. We see ourselves as a nation of extroverts—which means that we’ve lost sight of who we really are.<br />
<br />
so many people pretend to be extroverts.<br />
<br />
We like to think that we value individuality, but all too often we admire one type of individual—the kind who’s comfortable “putting himself out there.” Sure, we allow technologically gifted loners who launch companies in garages to have any personality they please, but they are the exceptions, not the rule, and our tolerance extends mainly to those who get fabulously wealthy or hold the promise of doing so.<br />
<br />
Introversion—along with its cousins sensitivity, seriousness, and shyness—is now a second-class personality trait, somewhere between a disappointment and a pathology.<br />
<br />
Some of our greatest ideas, art, and inventions—from the theory of evolution to van Gogh’s sunflowers to the personal computer—came from quiet and cerebral people who knew how to tune in to their inner worlds and the treasures to be found there.<br />
<br />
Introverts recharge their batteries by being alone; extroverts need to recharge when they don’t socialize enough.<br />
<br />
Carnegie’s metamorphosis from farmboy to salesman to public-speaking icon is also the story of the rise of the Extrovert Ideal.<br />
<br />
by 1920, popular self-help guides had changed their focus from inner virtue to outer charm<br />
<br />
the new personality-driven ads cast consumers as performers with stage fright from which only the advertiser’s product might rescue them.<br />
<br />
His hypothesis was that extroverted leaders enhance group performance when employees are passive, but that introverted leaders are more effective with proactive employees.<br />
<br />
“The evangelical culture ties together faithfulness with extroversion,” McHugh explained. “The emphasis is on community, on participating in more and more programs and events, on meeting more and more people. It’s a constant tension for many introverts that they’re not living that out.<br />
<br />
if you’re in the backyard sitting under a tree while everyone else is clinking glasses on the patio, you’re more likely to have an apple fall on your head.<br />
<br />
“A mind forever Voyaging through strange seas of Thought alone.”<br />
<br />
Deliberate Practice is best conducted alone for several reasons. It takes intense concentration, and other people can be distracting. It requires deep motivation, often self-generated. But most important, it involves working on the task that’s most challenging to you personally.<br />
<br />
it takes approximately ten thousand hours of Deliberate Practice to gain true expertise, so it helps to start young.<br />
<br />
Open-plan offices have been found to reduce productivity and impair memory. They’re associated with high staff turnover. They make people sick, hostile, unmotivated, and insecure.<br />
<br />
programmers from the same companies performed at more or less the same level, even though they hadn’t worked together. That’s because top performers overwhelmingly worked for companies that gave their workers the most privacy, personal space, control over their physical environments, and freedom from interruption.<br />
<br />
What looks like multitasking is really switching back and forth between multiple tasks, which reduces productivity and increases mistakes by up to 50 percent.<br />
<br />
Psychologists usually offer three explanations for the failure of group brainstorming. The first is social loafing: in a group, some individuals tend to sit back and let others do the work. The second is production blocking: only one person can talk or produce an idea at once, while the other group members are forced to sit passively. And the third is evaluation apprehension, meaning the fear of looking stupid in front of one’s peers.<br />
<br />
felt too cut off from the world to type a single keystroke... the café worked as my office because it had specific attributes that are absent from many modern schools and workplaces. It was social, yet its casual, come-and-go-as-you-please nature<br />
<br />
The most effective teams are composed of a healthy mix of introverts and extroverts
<br /><br />
who was unusually shy as a child, is good at school, watchful and quiet, devoted to his girlfriend and parents, prone to worry, and loves learning on his own and thinking about intellectual problems
<br /><br />
If you spend a lot of time charging around, then you have less time for reading and learning.
<br /><br />
Enjoyment appears at the boundary between boredom and anxiety, when the challenges are just balanced with the person’s capacity to act. —MIHALY CSIKSZENTMIHALYI
<br /><br />
introverts, who have trouble projecting artificial enthusiasm.
<br /><br />
A shy man no doubt dreads the notice of strangers, but can hardly be said to be afraid of them. He may be as bold as a hero in battle, and yet have no self-confidence about trifles in the presence of strangers. —CHARLES DARWIN
<br /><br />
highly sensitive people tend to be keen observers who look before they leap. They arrange their lives in ways that limit surprises. They’re often sensitive to sights, sounds, smells, pain, coffee. They have difficulty when being observed (at work, say, or performing at a music recital) or judged for general worthiness (dating, job interviews). But there were also new insights. The highly sensitive tend to be philosophical or spiritual in their orientation, rather than materialistic or hedonistic. They dislike small talk. They often describe themselves as creative or intuitive. They dream vividly, and can often recall their dreams the next day. They love music, nature, art, physical beauty. They feel exceptionally strong emotions—sometimes acute bouts of joy, but also sorrow, melancholy, and fear. Highly sensitive people also process information about their environments—both physical and emotional—unusually deeply. They tend to notice subtleties that others miss—another person’s shift in mood, say, or a lightbulb burning a touch too brightly.
<br /><br />
high-reactive temperaments come with risk factors. These kids are especially vulnerable to challenges like marital tension, a parent’s death, or abuse.
<br /><br />
someone offers you a beer, says the personality psychologist Brian Little, “they’re really saying hi, have a glass of extroversion.”
<br /><br />
human extroverts have more sex partners than introverts do—a boon to any species wanting to reproduce itself—but they commit more adultery and divorce more frequently, which is not a good thing for the children of all those couplings.
<br /><br />
Sensitive people seem to do the reverse. They “enjoy small talk only after they’ve gone deep,” says Strickland. “When sensitive people are in environments that nurture their authenticity, they laugh and chitchat just as much as anyone else.”
<br /><br />
introverts are “geared to inspect” and extroverts “geared to respond.”
<br /><br />
if you leave them to their own devices, the introverts tend to sit around wondering about things, imagining things, recalling events from their past, and making plans for the future. The extroverts are more likely to focus on what’s happening around them. It’s as if extroverts are seeing “what is” while their introverted peers are asking “what if.”
<br /><br />
“It’s not that I’m so smart,” said Einstein, who was a consummate introvert. “It’s that I stay with problems longer.”
<br /><br />
people who focus on their own instincts and those who follow the herd.
<br /><br />
The wind howls, but the mountain remains still.
<br /><br />
we can feel sociable at 6:00 p.m. and solitary at 10:00 p.m
<br /><br />
Yes, we are only pretending to be extroverts, and yes, such inauthenticity can be morally ambiguous (not to mention exhausting), but if it’s in the service of love or a professional calling, then we’re doing just as Shakespeare advised.
<br /><br />
Jealousy is an ugly emotion, but it tells the truth.
<br /><br />
Introverts should ask themselves: Will this job allow me to spend time on in-character activities like, for example, reading, strategizing, writing, and researching? Will I have a private workspace or be subject to the constant demands of an open office plan? If the job doesn’t give me enough restorative niches, will I have enough free time on evenings and weekends to grant them to myself?
<br /><br />
single. You dislike the bar scene, but you crave intimacy, and you want to be in a long-term relationship in which you can share cozy evenings and long conversations with your partner and a small circle of friends. In order to achieve this goal, you make an agreement with yourself that you will push yourself to go to social events, because only in this way can you hope to meet a mate and reduce the number of gatherings you attend over the long term.
<br /><br />
“I am social,” she says. “I love you, I love my family, I love my close friends. I just don’t love dinner parties. People don’t really relate at those parties—they just socialize. You’re lucky because I devote all my energy to you. You spread yours around to everyone.”
<br /><br />
Your degree of extroversion seems to influence how many friends you have, in other words, but not how good a friend you are.
<br /><br />
Big Five traits: Introversion-Extroversion; Agreeableness; Openness to Experience; Conscientiousness; and Emotional Stability.
<br /><br />
The purpose of school should be to prepare kids for the rest of their lives, but too often what kids need to be prepared for is surviving the school day itself.
<br /><br />
kids stop learning when they feel emotionally threatened
<br /><br />
my passion overcomes my shyness once I get started on a speech. If you find something that arouses your passion or provides a welcome challenge, you forget yourself for a while. It’s like an emotional vacation.”
<br /><br />
contributing earlier in a discussion is a lot easier than waiting until everyone else has talked and letting the tension build as he waits to take his turn.
<br /><br />
While extroverts are more likely to skate from one hobby or activity to another, introverts often stick with their enthusiasms.
<br /><br />
intense engagement in and commitment to an activity is a proven route to happiness and well-being
<br /><br />
Well-developed talents and interests can be a great source of confidence
<br /><br />
Figure out what you are meant to contribute to the world and make sure you contribute it.
<br /><br />
Quit your job as a TV anchor and get a degree in library science. But if TV anchoring is what you love, then create an extroverted persona to get yourself through the day.
<br /><br />
<b>Respect your loved ones’ need for socializing and your own for solitude (and vice versa if you’re an extrovert).</b>
<br /><br />
</i>
</blockquote>
Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-14520815609231358622012-12-23T14:35:00.002+07:002015-04-12T17:41:42.291+07:00Normalize string and remove special charactersLong, long ago I wrote an article about creating a <a href="http://x189.blogspot.com/2009/12/simple-search-engine-languages-accents.html" target="_blank">simple search engine</a> which is able to work with characters containing accents, imagine we want to reuse it for URL rewriting (e.g. we don't want our URL to be 'núi-biển-đà-nẵng-^^', it should be 'nui-bien-da-nang').<br />
<br />
This is the old normalization code:<br />
<pre class="brush:csharp">private static string NormalizeString(string inputWord)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (char c in inputWord.Trim().ToLower().ToCharArray())
{
string normalizedChar = c.ToString()
.Normalize(NormalizationForm.FormD).Substring(0, 1);
stringBuilder.Append(normalizedChar);
}
return stringBuilder.ToString();
} </pre>
<br />
We need to remove special characters in the text if it has any, usually we just use numbers 0-9 and characters A-Z for URL. We can do that easily by converting the normalized character to ASCII and compare it. Take a look at this ASCII table: http://www.asciitable.com/, you can see that 0-9 in ASCII is from 48 to 57, and A-Z is from 97 to 122. So here is the code:<br />
<pre class="brush:csharp">// Not to add special characters
int ascii = (int)char.Parse(normalizedChar);
if ((ascii >= 48 && ascii <= 57) || (ascii >= 97 && ascii <= 122))
{
stringBuilder.Append(normalizedChar);
}
</pre>
<br />
You will notice that the code correctly converts 'ú' to 'u', 'ể' to 'e', 'à' and 'ẵ' to 'a', but 'đ' is gone. Supposedly you added some code for converting the whole sentence yourself, you will get 'nui-bien-a-nang' instead of 'nui-bien-da-nang'.<br />
<br />
How is that possible? It seems somehow 'đ' is completely different from 'd', it's not 'd' with accent but another character itself, and its ASCII is 273 (neither from 48-57 nor from 97-122, and gone). I can't find any solution for that but this:<br />
<pre class="brush:csharp">if (normalizedChar == "đ")
{
normalizedChar = "d";
}
</pre>
<br />
Yes, that's it. Please let me know if you have a better solution. 'đ' is the only issue I found so far, I hope it's the only one, otherwise we will have to add more conditions.<br />
That's it for our URL generator, I'm sure you can write your own code for adding '-' between the words right?
<script type="text/javascript">
SyntaxHighlighter.highlight();
</script>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-37059292296066727782011-12-25T00:04:00.000+07:002015-01-14T23:35:55.562+07:00Device and Service - Kindle experience series<br />
I'm enjoying my Kindle Basic now, but my confession is that when I was thinking about buying one, I didn't intended to use it the way I'm using it now.<br />
<br />
<i style="font-family: 'Helvetica Neue Light', HelveticaNeue-Light, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; text-align: justify;">This is the last post in my Kindle experience series:</i><br />
<ul style="font-family: 'Helvetica Neue Light', HelveticaNeue-Light, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; list-style-image: initial; list-style-position: initial; margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 2em; padding-right: 0px; padding-top: 0px; text-align: justify;">
<li style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><i><a href="http://x189.blogspot.com/2011/12/fire-touch-or-basic-kindle-experience.html" target="_blank">One - Fire, Touch, or Basic?</a></i></li>
<li style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><i><b>Two - The device and the service</b>.</i></li>
</ul>
<br />
<a href="http://3.bp.blogspot.com/-1V9s6dvsQdA/TvWFdpN5_gI/AAAAAAAABMg/PM5M2cojWfU/s1600/Kindle-Basic_Collections.JPG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img alt="Kindle Basic - Collections" border="0" src="http://3.bp.blogspot.com/-1V9s6dvsQdA/TvWFdpN5_gI/AAAAAAAABMg/PM5M2cojWfU/s320/Kindle-Basic_Collections.JPG" height="240" style="cursor: move;" width="320" /></a>
Scott Hanselman was right, I'm <a href="http://www.hanselman.com/blog/ReadingMoreThanEverAnAnalysisOfFourLazyYearsWithAnAmazonKindleAndNoDeadTrees.aspx" target="_blank">reading more than ever</a>, there's something special about it, something makes you just want to pick up the Kindle and read, maybe the small and skinny design, maybe the collection of many books (even though I've just bought 2 by far, the rest are just samples :P), maybe the E Ink screen... Whatever the reason, I'm glad I'm spending more time on books and less time hanging around the web pointlessly.<br />
<br />
Reading PDF files, that was the most important reason for me to own a Kindle, but it turned out Kindle is not a good PDF reading device (maybe Kindle DX is, if you don't mind its overwhelming size). With a Kindle format file (AZW), you can change the font size of the book, but of course you can't do that with PDF, and Kindle's zooming function works well for images but not PDFs i think. The best option is using Landscape mode, but it still depends on the design of the PDF file, some files look great in Landscape and easy to read, but some are still a little hard to read because of small text. You might also want to try converting to AZW by sending the file to "name"@free.kindle.com or using an app but most of the time you'll get some pages with broken layout (I also tried sending a DOC file to Amazon service for converting, unlike PDFs, the outcome file looked great).<br />
<br />
Luckily the easiness to get books and samples made me forget the pain, we know that with Kindle, it's easier to get and read books, but it's even double in value when you're a foreigner, I've never thought it would be that easy to get English books, with the so-called Amazon Whispernet, suddenly everyone on the world has the same opportunity. Kindle books' prices are kind of affordable, many are even free, including some classic novels. But I still think it should have been cheaper, I ran into many programming and software development books with very high prices, and some books have their Kindle version more expensive than physical version, strange, isn't it?<br />
<br />
Speaking of English and foreigners, a dictionary is a must, and Kindle does this rather too well than I expect. You just need to move the cursor next to a word and its meaning will be automatically display at the bottom or on the top of the screen. The default dictionary is Oxford, which is English - English, if you want another you'll need to buy or find a free one.<br />
<br />
When reading Kindle books, you have the option to go to the table of contents, beginning, end, location... And I love how we can highlight, bookmark, and create notes, but when having so many highlights (e.g. 20 pages of highlights) I didn't find any easy way to navigate but having to move from page to page. If you take notes often when reading, then go for Kindle Touch, or something non-Kindle, because taking notes with Kindle Basic's 5-way controller is not easy at all. Your annotations can be synced with other Kindles, Kindle for PC, and Kindle Cloud Reader; you can also share them at <a href="https://kindle.amazon.com/">https://kindle.amazon.com/</a>. Also note that you can add annotations to PDFs but neither the files nor the annotations can be synced.<br />
<br />
Overall, though there're still many rooms for improvement, I would love to see a hybrid between Kindle Basic and Kindle Touch, a device with better PDF experience (and not too big like DX)... but if you love reading, don't wait. Even if you're not a bookworm, you should consider owning one, for it can make you become one.Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com1tag:blogger.com,1999:blog-3729569185716997747.post-86211498207380978542011-12-11T18:40:00.000+07:002012-01-10T08:58:30.517+07:00Fire, Touch, or Basic? - Kindle experience seriesA weird thought came into my mind recently: maybe I'll need 4 years, not for university or anything but read.<br />
<br />
<i>This is the first post in my Kindle experience series:</i><br />
<ul>
<li><b><i>One - Fire, Touch, or Basic?</i></b></li>
<li><i><a href="http://x189.blogspot.com/2011/12/device-and-service-kindle-experience.html" target="_blank">Two - The device and the service</a>.</i></li>
</ul>
<br />
<i>I intended to write it all in one post but it's kind of long and time-consuming so I have to break down like this. There might be some changes in the number of posts or post titles but what I'm going to share is still the same.</i><br />
<br />
When everyone started talking about the Kindle Fire, I paid some attention to it and thought about owning one (actually I almost bought one :P). Why? Because I thought it's a cheap eBook readers which can do more things than other Kindles and does things other Kindles can better.<br />
But after doing some research, I realized that we shouldn't call Kindle Fire an eBook reader (I think the term "comic reader" is more correct). Take a look at this table:<br />
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td valign="top"><span style="font-size: large;"><i>Compare Kindles</i></span></td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 119.7pt;" valign="top" width="160"><div style="text-align: center;">
<b>Kindle
Basic<img alt="Kindle Basic" height="160" src="http://g-ecx.images-amazon.com/images/G/01/kindle/common-assets/comp-KT._V166985501_.gif" v:shapes="Picture_x0020_3" width="124" /></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 119.7pt;" valign="top" width="160"><div style="text-align: center;">
<b>Kindle
Touch<img alt="Kindle Touch" border="0" src="http://g-ecx.images-amazon.com/images/G/01/kindle/common-assets/comp-KW._V166985500_.gif" />
</b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 119.7pt;" valign="top" width="160"><div style="text-align: center;">
<b>Kindle
Fire</b><br />
<img alt="Kindle Fire" border="0" src="http://g-ecx.images-amazon.com/images/G/01/kindle/common-assets/comp-KO._V166782091_.gif" />
</div>
</td>
</tr>
<tr>
<td><b> Display</b>
</td>
<td><div style="text-align: center;">
6" E Ink Pearl</div>
</td>
<td><div style="text-align: center;">
6" E Ink Pearl
</div>
</td>
<td><div style="text-align: center;">
7" Vibrant Color IPS</div>
</td>
</tr>
<tr>
<td><b> Battery Life</b><br />
<b> (Wireless off)</b>
</td>
<td><div style="text-align: center;">
1 month</div>
</td>
<td><div style="text-align: center;">
2 months</div>
</td>
<td><div style="text-align: center;">
8 hours</div>
</td>
</tr>
<tr>
<td><b> Storage</b>
</td>
<td><div style="text-align: center;">
2GB<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
4GB<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
8GB</div>
</td></tr>
<tr><td valign="top"><b> Dimensions</b>
</td>
<td><div style="text-align: center;">
6.5" x 4.5"<o:p></o:p></div>
<div style="text-align: center;">
x 0.34"<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
6.8" x 4.7"<o:p></o:p></div>
<div style="text-align: center;">
x 0.40"<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
7.5" x 4.7"<o:p></o:p></div>
<div style="text-align: center;">
x 0.45"<o:p></o:p></div>
</td>
</tr>
<tr>
<td><b> Weight</b>
</td>
<td><div style="text-align: center;">
5.98 ounces<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
7.5 ounces<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
14.6 ounces<o:p></o:p></div>
</td>
</tr>
<tr>
<td><b> Supports Audio</b>
</td>
<td><div style="text-align: center;">
No<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
Yes<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
Yes<o:p></o:p></div>
</td>
</tr>
<tr>
<td><b> Touch Screen</b>
</td>
<td><div style="text-align: center;">
No<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
Yes<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
Yes<o:p></o:p></div>
</td>
</tr>
<tr>
<td width="180"><b> “X-ray” Content</b>
</td>
<td><div style="text-align: center;">
No</div>
</td>
<td><div style="text-align: center;">
Yes</div>
</td>
<td><div style="text-align: center;">
Yes</div>
</td>
</tr>
<tr>
<td><b><span style="font-size: large;"> Landscape</span></b><br />
<b><span style="font-size: large;"> mode</span></b>
</td>
<td><div style="text-align: center;">
Yes</div>
</td>
<td><div style="text-align: center;">
No</div>
</td>
<td><div style="text-align: center;">
Yes</div>
</td>
</tr>
<tr>
<td valign="top"><b> Content Formats</b>
</td>
<td valign="top"><div style="text-align: center;">
Natively: Kindle (AZW), TXT, PDF,
unprotected MOBI, PRC.<o:p></o:p></div>
<div style="text-align: center;">
Through conversion: DOC, DOCX, JPEG,
GIF, PNG, BMP<o:p></o:p></div>
</td>
<td valign="top"><div style="text-align: center;">
Natively: Kindle (AZW), TXT, PDF,
Audible (Audible Enhanced(AA,AAX)), MP3, unprotected MOBI, PRC.<o:p></o:p></div>
<div style="text-align: center;">
Through conversion: DOC, DOCX, JPEG,
GIF, PNG, BMP.<o:p></o:p></div>
</td>
<td valign="top"><div style="text-align: center;">
Natively: Kindle (AZW), TXT, PDF,
Audible (Audible Enhanced(AA,AAX)), MP3, unprotected MOBI, PRC.<o:p></o:p></div>
<div style="text-align: center;">
Through conversion: DOC, DOCX, JPEG,
GIF, PNG, BMP.<o:p></o:p></div>
</td>
</tr>
<tr>
<td valign="top"><b> Price</b>
</td>
<td><div style="text-align: center;">
$79<o:p></o:p></div>
<div style="text-align: center;">
(with special offer)<o:p></o:p></div>
</td>
<td><div style="text-align: center;">
$99<o:p></o:p></div>
<div style="text-align: center;">
(with special offer)<o:p></o:p></div>
</td>
<td valign="top"><div style="text-align: center;">
$199<o:p></o:p></div>
</td>
</tr>
</tbody></table>
<span style="font-size: xx-small;">Reference:</span><br />
<span style="font-size: xx-small;"><a href="http://www.amazon.com/Kindle-eReader-eBook-Reader-e-Reader-Special-Offers/dp/B0051QVESA">http://www.amazon.com/Kindle-eReader-eBook-Reader-e-Reader-Special-Offers/dp/B0051QVESA</a>
</span><br />
<a href="http://reviews.cnet.com/8301-33198_7-20112764-286/amazon-kindle-touch-3g-vs-kindle-touch-vs-kindle-2011/"><span style="font-size: xx-small;">http://reviews.cnet.com/8301-33198_7-20112764-286/amazon-kindle-touch-3g-vs-kindle-touch-vs-kindle-2011/</span></a>
<br />
<br />
"Kindle's E Ink screen reads like real paper, with no glare".<br />
See the "vibrant color screen" there? I was a fool thinking Kindle Fire screen were something like "E-Ink-with-Colors screen". Besides, I don't want to charge my reading device every 8 hours.<br />
So it looks like Kindle Touch is the best option here: more storage, more battery life, supports audio... Oh wait... what's wrong with the so-big "Landscape mode"? It's a very big issue in my opinion, but Amazon, CNET, and many other big sites don't even mention anything about it. That's like a conspiracy to me so I want to make it big here.<br />
If you haven't known, Landscape mode is essential to read PDF files (otherwise the text will be too small), actually I encountered some PDF files which even when you switch to Landscape mode, the text is still a little small, but at least it's readable. You might think if you only use AZW files, then that's not a big deal, but some books also contain images, and many of them are also easier to see in Landscape mode. All in all, I think most of us will need Landscape mode sooner or later.<br />
<br />
And this is my conclution:<br />
<i><b>Kindle Fire is not good for reading.</b></i><br />
<i><b>Screen rotation is not available on Kindle Touch.</b></i><br />
<i><b>So I go for Kindle Basic</b></i>, the biggest drawback here is that it does not support audio, but the thought of something that is good for nothing but reading is kind of sexy, isn't it?Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-1285744257975595212011-11-27T23:04:00.001+07:002015-01-18T13:59:39.750+07:00C# Accessibility Levels<a href="http://msdn.microsoft.com/en-us/library/ba0a1yw2.aspx" target="_blank">Accessibility Levels</a>... should have paid more attention to this, haha
<br />
"If you love the stars, look up to the sky... but watch your ground first". My master kept telling us something like that so many times, yet...<br />
<br />
<table style="border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; color: black; font-family: 'Segoe UI', Verdana, Arial; font-size: 13px; text-align: left;"><tbody>
<tr style="vertical-align: top;"><th style="background-color: #e5e5e5; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; font-size: 1.077em; height: 21px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;">Declared accessibility</th><th style="background-color: #e5e5e5; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; font-size: 1.077em; height: 21px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;">Meaning</th></tr>
<tr style="vertical-align: top;"><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">public</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
Access is not restricted.</div>
</td></tr>
<tr style="vertical-align: top;"><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">protected</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
Access is limited to the containing class or types derived from the containing class.</div>
</td></tr>
<tr style="vertical-align: top;"><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">internal</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
Access is limited to the current assembly.</div>
</td></tr>
<tr style="vertical-align: top;"><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">protected</span> <span class="input">internal</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
Access is limited to the current assembly or types derived from the containing class.</div>
</td></tr>
<tr style="vertical-align: top;"><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">private</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
Access is limited to the containing type.</div>
</td></tr>
</tbody></table>
<br />
<table style="border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; color: black; font-family: 'Segoe UI', Verdana, Arial; font-size: 13px; text-align: left;"><tbody>
<tr style="vertical-align: top;"><th style="background-color: #e5e5e5; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; font-size: 1.077em; height: 21px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;">Members of</th><th style="background-color: #e5e5e5; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; font-size: 1.077em; height: 21px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;">Default member accessibility</th><th style="background-color: #e5e5e5; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; font-size: 1.077em; height: 21px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;">Allowed declared accessibility of the member</th></tr>
<tr style="vertical-align: top;"><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">enum</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">public</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
None</div>
</td></tr>
<tr style="vertical-align: top;"><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">class</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">private</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">public</span></div>
<div style="margin-top: 13px; position: relative;">
<span class="input">protected</span></div>
<div style="margin-top: 13px; position: relative;">
<span class="input">internal</span></div>
<div style="margin-top: 13px; position: relative;">
<span class="input">private</span></div>
<div style="margin-top: 13px; position: relative;">
<span class="input">protected</span> <span class="input">internal</span></div>
</td></tr>
<tr style="vertical-align: top;"><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">interface</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">public</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
None</div>
</td></tr>
<tr style="vertical-align: top;"><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">struct</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">private</span></div>
</td><td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 9px; padding-left: 4px; padding-right: 4px; padding-top: 9px;"><div style="position: relative;">
<span class="input">public</span></div>
<div style="margin-top: 13px; position: relative;">
<span class="input">internal</span></div>
<div style="margin-top: 13px; position: relative;">
<span class="input">private</span></div>
</td></tr>
</tbody></table>
Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-33773510296797994162011-10-16T18:37:00.001+07:002015-04-12T17:47:28.595+07:00Create an RSS feed for your ASP.NET websiteRecently I've been looking into <a href="http://msdn.microsoft.com/en-us/library/aa478968.aspx">Creating an Online RSS News Aggregator with ASP.NET</a>, but that article is applied for ASP.NET Web Forms so I came up with this simple solution for Web Pages and maybe we can use something similar for MVC:
<br />
<pre class="brush:html">@{
var db = Database.Open("DatabaseName");
var articles = db.Query(
"SELECT TOP 5 ArticleID, Title, Author, Description, DatePublished, Url " +
"FROM Articles " +
"ORDER BY DatePublished DESC");
}
<rss version="2.0">
<channel>
<title>X189 blog</title>
<link>http://x189.blogspot.com/</link>
<description>.NET & Productivity</description>
@foreach (var article in articles)
{
<item>
<title>@article.Title</title>
<description>@article.Description</description>
<link>@Href("~/", article.Url)</link>
<author>@article.Author</author>
<pubDate>article.DatePublished</pubDate>
</item>
}
</channel>
</rss>
</pre>
Create some fake data and you should have something like this running the page:
<br />
<div class="separator" style="clear: both; text-align: center;">
<img alt="Sample RSS feed" border="0" height="199" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFs9rERZONwwF5jHet0aq_LNws43ZEN8k1inv84vFBEk9KKpLkhliT24erCT4DS8kw_LgD9GHBBEnOOOiVxiwish5LNTqizDbvwj6IfQCbb4ViAr7R6CoesVai_Dnym7phmZhnUyUcdL0/s320/sameple-rss-feed.png" width="320" /></div>
<b>Update</b>: you might also want to check out this useful article: <a href="http://www.petefreitag.com/item/384.cfm">How to add RSS Autodiscovery to your site</a>
<script type="text/javascript">
SyntaxHighlighter.highlight();
</script>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-19331013871603777982011-07-09T19:45:00.004+07:002015-04-12T17:50:16.846+07:00Autocomplete textbox with jQuery & RazorWith <a href="http://jqueryui.com/demos/autocomplete/">jQuery Autocomplete</a>, we can easily create an autocomplete textbox in some simple steps:<br />
<br />
First we need some references to the jQuery files:<br />
<pre class="brush:html"><link type="text/css" href="@Href("~/Styles/jquery-ui-1.8.12.custom.css")" rel="stylesheet" />
<script type="text/javascript" src="@Href("~/Scripts/jquery-1.5.1.min.js")"></script>
<script type="text/javascript" src="@Href("~/Scripts/jquery-ui-1.8.12.custom.min.js")"></script>
</pre>
<br />
Then we can create the source and function for Autocomplete:<br />
<pre class="brush:html"><script type="text/javascript">
var availableTags = ["C#", "ASP.NET", "Razor", "jQuery"];
$(function () {
$("#tags").autocomplete({
source: availableTags
});
});
</script>
</pre>
<br />
One more simple line to create an input whose type is text and ID is "tags" like in the JavaScript function we created before:<br />
<pre class="brush:html"><input type="text" id="tags" />
</pre>
<br />
That's all we need to get our autocomplete textbox up and running.<br />
<div class="separator" style="clear: both; text-align: center;">
<img alt="Autocomplete textbox with jQuery & Razor" border="0" height="157" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV2NIMCDF-FjxKTOT6Lmo4Ph0iasB7bqalwVqrT6FBEPPHWghDenqjarjR4cLBKIZ52qMWfLHZAj-Kpd_-WNg1rKPakWKydk-76D-DagM4yOtLnFsJywFZW6SmX0GoL4svw7TcHEI1rL4/s400/autocomplete-textbox.png" width="400" /></div>
<br />
But what if we don't want to hardcode our autocomplete source but get it from a database or something? I'll show you how I did with Razor:<br />
For example, we have a tagList source (I know I'm hardcoding again to keep it simple, this list should be got with db.Query() or something):<br />
<pre class="brush:csharp">@{
var tagList = new List<string>();
tagList.Add("C#");
tagList.Add("ASP.NET");
tagList.Add("Razor");
tagList.Add("jQuery");
}
</pre>
<br />
Now we have to occupy the autocomplete source with tagList, remember that the autocomplete source is in JavaScript and tagList is in C# so it's a little bit tricky:<br />
<pre class="brush:csharp">var availableTags = new Array();
@for (var i = 0; i < tagList.Count; i++)
{
@:availableTags[@i] = '@tagList[i]';
}
</pre>
And here is all in one, the best solution I can think of for this, just create a new cshtml file and paste it in to test: <br />
<pre class="brush:csharp">@{
var tagList = new List<string>();
tagList.Add("C#");
tagList.Add("ASP.NET");
tagList.Add("Razor");
tagList.Add("jQuery");
}
<link type="text/css" href="@Href("~/Styles/jquery-ui-1.8.12.custom.css")" rel="stylesheet" />
<script type="text/javascript" src="@Href("~/Scripts/jquery-1.5.1.min.js")"></script>
<script type="text/javascript" src="@Href("~/Scripts/jquery-ui-1.8.12.custom.min.js")"></script>
<script type="text/javascript">
var availableTags = new Array();
@for (var i = 0; i < tagList.Count; i++)
{
@:availableTags[@i] = '@tagList[i]';
}
$(function () {
$("#tags").autocomplete({
source: availableTags
});
});
</script>
<input type="text" id="tags" />
</pre>
<script type="text/javascript">
SyntaxHighlighter.highlight();
</script>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com5tag:blogger.com,1999:blog-3729569185716997747.post-41271115775057371242011-02-20T18:40:00.000+07:002011-02-20T18:40:37.808+07:00Powerful apps & extensions for ChromeIt's been a long time since my <a href="http://x189.blogspot.com/2010/01/10-extensions-that-make-you-love-chrome.html">10 Extensions that make you love Chrome more</a> article, many things have changed.<br />
One day I opened Google Chrome, went to the mange extensions page and clicked on the "Get more extensions " link. I thought I would see the boring old page as usual, but I was so surprised and excited seeing that it has become <a href="https://chrome.google.com/webstore" target="_blank">Chrome Web Store</a> with not only extensions but also full of apps and themes.<br />
<div class="separator" style="clear: both; text-align: center;"><img alt="Chrome Web Store" border="0" height="245" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgddQTNlXZBqZKf_YnydwrK6lxsUG0UcsZ3xuKolMvD1dvNYmJYESRF2-4Wlg8RY8OAS0L1bIE4Sn_e0yWnATkolmpHyOQx8NN65S-JAAFTEZLCA61_NeJ_zpZEb8q_z_h2onMnAiJwO-k/s400/chrome-web-store.png" width="400" /></div><br />
These are some notable apps and extensions that I found so useful:<br />
<br />
<a href="https://chrome.google.com/webstore/detail/hdokiejnpimakedhajhdlcegeplioahd" target="_blank"><span class="Apple-style-span" style="font-size: large;">LastPass</span></a><br />
The online password manager that I should have tried long before I did, it's much better than I (and maybe you) expected.<br />
<div class="separator" style="clear: both; text-align: center;"><img alt="LastPass - the online password manager" border="0" height="203" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7_QE6IOq-6Izo1KhS_92qF04LomRclTCj7ZsR2rXJsvvK75mgEgClPoZdEX7EP13xsPbO5g4DYh8nQCU3LKJfjFcswvwbKXaI0d67eUEdmlTUDT2bGTYQ6mVrXU-cwsxF6a4m0PpclhE/s400/LastPass.png" width="400" /></div><br />
<span class="Apple-style-span" style="font-size: large;"><a href="https://chrome.google.com/webstore/detail/mgijmajocgfcbeboacabfgobmjgjcoja" target="_blank">Google Dictionary</a></span><br />
An extension from Google itself. Definitely helpful if English is not your major language, but a native English user might also need it sometimes right?<br />
<div class="separator" style="clear: both; text-align: center;"><img alt="Google Dictionary extension" border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDAdNSU5KxoPeOEjj19xFCDoucl8XS2RmRLqXbAbqubIghednUUEYbvfLaHRH9Yo3tgal_gD6Y8UlFvDHKLfNN5WUJnHLtlopIpuVUQdvzp3vJI3AaVHiGG7x_Y6dTz1kjbNbnqc3fuWM/s320/google-dictionary.png" width="269" /></div><br />
<div class="separator" style="clear: both; text-align: center;"><img alt="Google Dictionary popup" border="0" height="139" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgK8lj2Vq8iCB2ycH5lwBbfOvd865MCviJwJKWFi_tDOgQIaXpV3As9JAtN0XlWxCg9AfD-tXpHNpp55qeOuqCL7FtVjFweKyQO8GBhtKy-zZba0GvO15pa63ki3bXFoPPXh1fThO75S3k/s320/google-dictionary-popup.png" width="320" /></div><br />
<span class="Apple-style-span" style="font-size: large;"><a href="https://chrome.google.com/webstore/detail/dbpojpfdiliekbbiplijcphappgcgjfn" target="_blank">Ultimate Chrome Flag</a></span><br />
Displays Google PageRank, Alexa Rank, WOT... of the websites you're visiting. I tried many extensions like this, and this is the best so far.<br />
<div class="separator" style="clear: both; text-align: center;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJEsMsphkg7r-r3TdvJjE-C0W4EAQdGnY-VlX88AJj1yfl7hgkg9yNSZVrq0tsfNGJ2rKHK8sQTyr3i5uKUVKDsFQJr84DnvrEbklIj2ErCqjXCkKH_4SqJ7_TJFScRLhKQagh3EJsYNI/s320/ultimate-chrome-flag.png" width="203" /></div><br />
The installed apps are showed in your start page like this:<br />
<div class="separator" style="clear: both; text-align: center;"><img alt="Chrome Start Page with Apps" border="0" height="156" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiXYsgq6brlE40bgYEXXVld7VJzr1QRXR3xVtIcZ4QsPy0JzRj_o5oOO7T_IoGEs8t74C12YhnKHSGZtIljdfjNIuSJKVbwz76endXK1iW0Odcj2kqFt-ks0w_AqXL7o8NChgvFgTW9XY/s400/chrome-start-page-with-apps.png" width="400" /></div>Many of them are just a shortcut to some website like Grooveshark or wikiHow Survival Kit, but it's another good way to bookmark I think, and it's also fun to explore some good websites that you've never known in the web store.<br />
My favorite apps are Quick Note and Read Later Fast, both from Diigo and allow you to sync to cloud:<br />
<br />
<a href="https://chrome.google.com/webstore/detail/mijlebbfndhelmdpmllgcfadlkankhok#" target="_blank"><span class="Apple-style-span" style="font-size: large;">Quick Note</span></a><br />
Everyone of us need to take notes sometimes right? With this, you can add notes to the app, you can also search:<br />
<div class="separator" style="clear: both; text-align: center;"><img alt="Chrome's Quick Note app" border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisrDG9-GbETs9dPYDxmcgKrCEx1SKQeP_pHPjcFa223HyudekxiKRMzWcwqmGnVdFHEZtT38A6cI2fuA-atWWtOoZVGIOMP3yeDXSAsDbZNurnQPhN2o3EcgXqEfUv6idSBA8rIDCmYbg/s400/quick-note-app.png" width="400" /></div>... or add a note right on a webpage:<br />
<div class="separator" style="clear: both; text-align: center;"><img "quick="" border="0" height="250" note="" on="" page"="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeECUGXGH8D75tKhYtpBRmn_WUvto9VYR8ouOvlzwEyuF-38rC_F9mraFtLbpoFrHrGphZFUvn1gaZQNZWd1Qhg2q9OeHt260uq-0MKLvzGEINGiXbsPMdePJbpOL4KxxaETa1ytqAxrc/s400/quick-note-web.png" width="400" /></div><br />
<a href="https://chrome.google.com/webstore/detail/decdfngdidijkdjgbknlnepdljfaepji" target="_blank"><span class="Apple-style-span" style="font-size: large;">Read Later Fast</span></a><br />
If you've ever run into an interesting article but didn't have time (or you were so lazy :p) to read but also wanted to keep it for later then this app is just right for you. All you need to do is right clicking on that page and choose Read Later.<br />
<div class="separator" style="clear: both; text-align: center;"><img alt="Quick Note & Read Later Fast" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR0m5ZEPbU9bI5DHjbVHzzDPaMzFirBZhje3ZCjEczCrzsrmt9YanZYxswt8YoXMh1x0jpcJFFQimfIRg62kdfhDd3liG3rSFk1SfGAhNnnCPnTJ5rngNrBvaXK_62cOkXleU2mW8jltA/s1600/quick-note-and-read-later-fast.png" /></div><br />
<div class="separator" style="clear: both; text-align: center;"><img alt="Read Later Fast - Sync online" border="0" height="110" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRBEucQg0t1Y8tDCPa9Tpxhyphenhyphen_EUP7nMmNu_c_7_of-4O0LsU52-xkdZUHMnDkbZxjmbRy56ySXiJ4BG0wiZDqjJpJxaXYfTAI1jQY6MNkGpeH59NXRNfNjbygNNIgtqpPEgTnhZXDrhlw/s400/read-later-fast-sync-onine.png" width="400" /></div><br />
The two apps allow you to sync online so you're data will never be lost, it's also very useful if you use more than one computer.<br />
<br />
Last but not least, remember that Google Chrome itself can sync your data with your Google account, a good way to prevent data lost and keep your settings the same on any computer.<br />
<div class="separator" style="clear: both; text-align: center;"><img alt="Google Chrome - Configure sync" border="0" height="313" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiejbrCYysPdTMfV0vrHyS4LBKATf42x06KpsVaxczHMt_5C8c7vsaOnatqHsDNHW5AK6FkpPhwwHIq8GyFLuinHYUDum8l0Z2ld6MjhhMR4-TezEk_jsdu3vP_1DDXVVaPKo72L0HqW5g/s320/chrome-configure-sync.png" width="320" /></div>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-40157007853664665202010-11-07T22:57:00.007+07:002015-04-12T17:54:21.515+07:00Silverlight Printing with Pagination & Header/FooterSilverlight 4 supports printing, but it might take you some time to figure out how to print a document with header/footer and pagination. Hope this article of mine can save your time.<br />
<br />
First we need something as item source:<br />
<pre class="brush:csharp">public class Item
{
public int ID { get; set; }
public string Description { get; set; }
}
</pre><br />
And a user control as PrintPage:<br />
<pre class="brush:xml"><Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!--Header-->
<Grid>
<TextBlock Text="HEADER" />
</Grid>
<!--Body-->
<ItemsControl Name="BodyItemsControl" Grid.Row="1" Margin="0,24" />
<!--We will use this as a template for each item that needs to be printed-->
<ItemsControl Name="TemplateItemsControl">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding ID}" Margin="2" />
<TextBlock Text=" - " Grid.Column="1" Margin="2" />
<TextBlock Text="{Binding Description}" Grid.Column="2"
TextWrapping="Wrap" MaxWidth="500"
HorizontalAlignment="Left" Margin="2" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!--Footer-->
<Grid Grid.Row="2">
<TextBlock Text="FOOTER" />
</Grid>
</Grid>
</pre><br />
Then we need to add some fields and event handlers in our MainPage to print the document:<br />
<pre class="brush:csharp">private List<Item> items = new List<Item>();
private PrintDocument printDoc = new PrintDocument();
private int itemIndex = 0;
public MainPage()
{
InitializeComponent();
this.Loaded += (s, e) =>
{
GetItems();
printDoc.PrintPage +=
new EventHandler<PrintPageEventArgs>(printDoc_PrintPage);
};
}
</pre>Create the item source:<br />
<pre class="brush:csharp">private void GetItems()
{
for (int i = 0; i < 100; i++)
{
items.Add(
new Item()
{
ID = i,
Description = "This is item " + i
});
}
}
</pre>Handling the event when we're printing: <br />
<pre class="brush:csharp">private void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
PrintPage printPage = new PrintPage();
while (itemIndex < items.Count)
{
// get the template for an item
FrameworkElement row = printPage.TemplateItemsControl.ItemTemplate.LoadContent() as FrameworkElement;
row.DataContext = items[itemIndex];
// measure the row before getting its desired height
row.Measure(new Size(e.PrintableArea.Height, double.PositiveInfinity));
// print new page if not enough Height
// otherwise add the row to current page
if (row.DesiredSize.Height + printPage.DesiredSize.Height > e.PrintableArea.Height)
{
e.HasMorePages = true;
break;
}
else
{
printPage.BodyItemsControl.Items.Add(row);
printPage.Measure(new Size(e.PrintableArea.Height, double.PositiveInfinity));
itemIndex++;
}
}
// print current page
e.PageVisual = printPage;
}
</pre>If we don't have enough desired height, the loop will be breaked and the current PrintPage which is full of items will be printed out.<br />
Then a new PrintPage will be created and a new loop will be strarted to print the remaining items.<br />
<br />
Finally we just need to add a button to the MainPage and print the document when the button is clicked:<br />
<pre class="brush:csharp">private void Button_Click(object sender, RoutedEventArgs e)
{
printDoc.Print("Silverlight printing with pagination and header/footer");
}
</pre><br />
You should have something like this by now:<br />
<img alt="Print diaglog" border="0" height="289" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWai_VRxzAu2tPRux_YrDyzbVm2oeUE_9ZmKsao6pE1CXLMcvIcuggJFlv9i8pXBaZvPaRWxmY36ibx9yUx5BhwGzJNFxf7-PcGdSSliCbzdp-UaII8hNZYKCf3ajWMS3nSR38lUeoaJo/s320/print-dialog.png" width="320" /><br />
<img alt="Silverlight print page - Header" border="0" height="216" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioLl_Gtfn1I_Agy8LiOSMrJmi10Vyaca3KJMc6Er4uYeT3cThrEJ5_XBKsnX5Z4jaL7rcQkG4sP1yO1hM0N5w0pVTmQVmpKze0xXZFvcYq3XA8KTxOR_VBMSQAlKIp_PmBlUyrMi3Xn4k/s640/silverlight-print-page.png" width="640" /><br />
<img alt="Silverlight print page - Footer, Pagination" border="0" height="265" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLf6nR7i2WiQOvis8I76q_OAKQbK25HkYcn5OIVUC_GX8Rs87z80AM_vpS8OLYmvTvkut2sF0IWtHKEEXGn70QodYgr0rzkmZysREkycuigfTcA3ynz2LkWiUYjBfdQmwfb2hvtYlDV9g/s640/silverlight-print-page_pagination.png" width="640" />
<script type="text/javascript">
SyntaxHighlighter.highlight();
</script>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com1tag:blogger.com,1999:blog-3729569185716997747.post-35083021595296337032010-07-11T15:23:00.004+07:002013-11-30T18:13:25.456+07:00Becoming a Windows Phone 7 developerWindows Phone 7 is coming. If you're familiar with .NET, you can make your own WP7 applications or games (for work, or hobby, or to run on your device...)<br />
<br />
You might want to check out this <a href="http://msdn.microsoft.com/en-us/library/ff402529(VS.92).aspx" target="_blank">Getting Started Guide for Developing Windows Phone</a> first.<br />
You will need <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=04704acf-a63a-4f97-952c-8b51b34b00ce&displaylang=en" target="_blank">Windows Phone Developer Tools</a> to start developing.<br />
<div class="separator" style="clear: both; text-align: center;">
<img alt="Visual Studio 2010 Express for Windows Phone" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBsUaYgTBaWQx7oG9zM2uhE5c0gb7ZSmOssbLXsTRpcE56DW9zs0QqYdZ2TE1CVBINY4vSQPOE3KFQdL6EvfzFU5Ow5xkb8JWlQ3kv6Vfg_oMsJVydsBO_V_frLPwTUr8t-PoBK4tUT04/s640/VS2010-Express-Windows-Phone.png" height="418" width="640" /></div>
<br />
We have 2 options when creating a project: <a href="http://creators.xna.com/en-US/article/whichproductforWindowsPhone" target="_blank">Silverlight or XNA</a>.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><img alt="Silverlight for Windows Phone - XAML designer" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8DWIUnO4B1M6XkFXbf5iwS4xZzQ_3siN7rl6rXU1DyzRcJLwp-N3nDVbOQ51cSkFnBBfJqwBFEsaREBxBq3I7aoXzV2mUS2q4wwPIPBKN5i31GtVXLiK3i8oKuB1BKaZ43x9NdIkEXak/s640/Windows-Phone-XAML-Design.png" height="400" width="640" /></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Silverlight for Windows Phone - XAML designer</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><img alt="XNA for Windows Phone - Main class with Load/Draw/Update" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTyA7Sr-9JAAr1p3WYuBkE0S9gn_AFdzw1oR-ea7Sol_bgkyD0NkTri6ne7YTQqEFomC4a3tRzMcFNn2-QemvFdXw52DunO2OnH71Iq2eBNUe7Q3c1SJorG5_RLHmtB3a1OBx8BucjINw/s640/XNA_Main-Class.png" height="640" style="margin-left: auto; margin-right: auto;" width="528" /></td></tr>
<tr><td class="tr-caption" style="text-align: center;">XNA for Windows Phone - Main class with Load/Draw/Update...</td></tr>
</tbody></table>
<br />
Run the app on the Emulator or a Device:<br />
<div class="separator" style="clear: both; text-align: center;">
<img alt="Windows Phone 7 Build Options - Emulator or Device" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpbRPVhsC0GC8glo5L6inyhsQDRAypYBlHjXBJcmpzWlJTBjwwARHQL_KbQwLK6oTJQAlHBN_UgAm25NZZtm_fy6TF9fEUl8jBd7c3T34-QZnP_IQ6jhe9DeXEZQyluI7VmhbGnNcz3xw/s1600/Windows-Phone-Build-Options.png" /></div>
<br />
<a href="http://creators.xna.com/" target="_blank">XNA Creators Club</a> is a great place for WP7 developers with many samples, starter kits, getting started...<br />
Make sure that you visit <a href="http://developer.windowsphone.com/windows-phone-7/" target="_blank">Windows Phone for Developers</a> site, it's full of useful resources.Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-9498263473844212832010-05-08T21:44:00.000+07:002010-06-13T11:39:33.343+07:00Where to learn Silverlight (4)Want to play with Silverlight? Try out these sites, they provide you an overview of its features as well as live samples, showcases, tutorial videos...<br />
<br />
<a href="http://www.microsoft.com/silverlight/features/" target="_blank">Top Silverlight Features</a>: short descriptions with videos, some with case studies and demo.<br />
<a href="http://samples.msdn.microsoft.com/Silverlight/SampleBrowser/#/?sref=HomePage" target="_blank">Silverlight SDK Sample Browser</a>: live samples with XAML and source code (C# & VB), related documents are also listed.<br />
<a href="http://www.silverlight.net/content/samples/sl4/toolkitcontrolsamples/run/default.html" target="_blank">Silverlight Toolkit Samples</a>: live samples of controls in the Silverlight Toolkit with XAML and source code.<br />
<a href="http://channel9.msdn.com/learn/courses/Silverlight4/" target="_blank">Silverlight Training Course (Silverlight 4)</a>: a whitepaper explains Silverlight 4 features, and walkthrough videos for building a Silverlight business application... The videos run faster (with lower quality) when you run them from the Training Kit available for download here.<br />
<a href="http://www.silverlight.net/" target="_blank">Silverlight.NET</a>: the official Microsoft Silverlight site, many resources and showcases. Try it Forums when you get stuck.<br />
<br />
You need Silverlight 4 to run the sample sites.<br />
If you have other good links, they're always welcome to be added.Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-40579305476294782182010-04-18T14:37:00.002+07:002015-04-12T18:07:06.070+07:00Image in C#: Save, Resize, and Convert to BinarySooner or later, you will find the need of handling image in your code, especially when you're working with a database. So in this article, I share you some useful methods that I find myself using frequently. They include: saving image in a folder, getting thumbnail from the original image, converting image to binary for saving in database, and converting binary data back to image.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Save an image</span><br />
<pre class="brush:csharp">Image originalImage = Image.FromFile(imagePath);
string filePath = AppDomain.CurrentDomain.BaseDirectory + savedName;
originalImage.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
</pre>This code save the image to the base directory of your app or website.<br />
imagePath is the full path to the image that we need to save (e.g. "C:\Pictures\Lighthouse.jpg"), one way to get this is use an OpenFileDialog.<br />
savedName is the name for the saved image.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Save the image as a thumbnail</span><br />
<pre class="brush:csharp">public static void SaveImage(string imagePath, string savedName,
int width = 0, int height = 0)
{
Image originalImage = Image.FromFile(imagePath);
string filePath = AppDomain.CurrentDomain.BaseDirectory + savedName;
if (width > 0 && height > 0)
{
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Image imageToSave = originalImage.GetThumbnailImage(width, height, myCallback, IntPtr.Zero);
imageToSave.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
originalImage.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
private static bool ThumbnailCallback() { return false; }
</pre>Note the parameters: int width = 0 & int height = 0. This is a C# 4.0 feature: <b>Optional Parameters</b>, so we can call this method like this: (assume this method is in ImageHandling class)<br />
<pre class="brush:csharp">// Save image as original
ImageHandling.SaveImage(@"C:\Pictures\Lighthouse.jpg", "OriginalLighthouse.jpg");
// Save image as thumbnail
ImageHandling.SaveImage(@"C:\Pictures\Lighthouse.jpg", "ThumbnailLighthouse1.jpg", 160, 90);
// New feature: Named Parameter
ImageHandling.SaveImage(@"C:\Pictures\Lighthouse.jpg", "ThumbnailLighthouse2.jpg", height: 90, width: 160);
</pre><br />
<span class="Apple-style-span" style="font-size: large;">Resize the image and keep aspect ratio</span><br />
<pre class="brush:csharp">int newWidth = originalImage.Width * percentage / 100;
int newHeight = originalImage.Height * percentage / 100;
</pre>To keep the image aspect ratio, simply replace width & height parameters with percentage parameter and call the GetThumbnailImage method with our new width & height.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Convert image to binary</span><br />
<pre class="brush:csharp">public static byte[] ImageToBinary(string imagePath)
{
FileStream fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, (int)fileStream.Length);
fileStream.Close();
return buffer;
}
</pre>Use this method when you want to save images in your database. The column to store binary data is usually varbinary(MAX).<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Convert binary to image</span><br />
You store images in your database as binary, of course you must convert binary back to images so you can display them in your app.<br />
<pre class="brush:csharp">public static Image BinaryToImage(System.Data.Linq.Binary binaryData)
{
if (binaryData == null) return null;
byte[] buffer = binaryData.ToArray();
MemoryStream memStream = new MemoryStream();
memStream.Write(buffer, 0, buffer.Length);
return Image.FromStream(memStream);
}
</pre>You may need to add reference to System.Data.Linq. LINQ-to-SQL maps a varbinary column in your database to its relevant property as System.Data.Linq.Binary.<br />
<br />
What about you? What are your favorite image-handling functions? Are there any other functions you'd like to have?<br />
<a href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=5567030" rel="tag" style="display: none;">CodeProject</a>
<script type="text/javascript">
SyntaxHighlighter.highlight();
</script>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com4tag:blogger.com,1999:blog-3729569185716997747.post-85308014180649098302010-03-30T20:53:00.002+07:002011-02-20T18:49:00.169+07:00IDM may make your Chrome crashRecently I found Google Chrome crashed so frequently. I use Chrome in XP, Vista, and 7; the problem only happened in Windows 7. So I knew that's not because of Chrome itself, my guess was that the problem comes from Windows 7 or <a href="http://x189.blogspot.com/2010/01/10-extensions-that-make-you-love-chrome.html">Extensions</a> or Chrome's User Data.<br />
I googled with tons of queries, changed Chrome channel, disabled all extensions, emptied the cache, used a new User Data,... Nothing worked.<br />
Finally I discovered Internet Download Manager with its Google Chrome Integration option checked was the cause of the crashes. So if you're living with a crashing Chrome and have IDM installed, go to IDM Options -> General to make sure that Google Chrome is not checked.<br />
<br />
I guess IDM's company has been working on this. If you want to use IDM in the meantime, you can manually copy download link and add to the program or click on the link in another browser.Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com2tag:blogger.com,1999:blog-3729569185716997747.post-38752270562784399552010-03-21T18:05:00.000+07:002010-06-13T11:38:44.470+07:00Google's Cloud vs Microsoft's ServicesGoogle's emphasis on the Web as an application platform challenges the primacy of PC software and operating systems, Microsoft's traditional cash cows. Its forays into mobile devices call into question the very concept of desktop computing. Its Web-based services and open source software fly in the face of Microsoft's core business model. Philosophically speaking, Google is the anti-Microsoft -- and it's making a killing at it.<br />
<br />
By comparison, the world's largest software vendor has adapted poorly to the changing market landscape. On the Web, Internet Explorer is dead last in standards compliance, and its critical security flaws sometimes go unpatched for months. Windows Mobile claims just 7.9 percent of the smartphone market, and according to Gartner, sales are slowing. Microsoft's vaunted new search service, Bing, has won few converts from Google, except where Microsoft has strong-armed them into using it. In short, while it may be first in desktop software, Microsoft's track record outside its comfort zone has been fairly dismal, enough so that in 2007, venture capitalist Paul Graham declared, "Microsoft is dead."<br />
<br />
But Microsoft's chief software architect - Ray Ozzie has a plan. With the Windows division back on track and new version of Office set to debut this year, <b>software plus services</b> is the new mantra at Microsoft's Redmond headquarters. It marks a strategic shift that will transform everything about the company, from how it develops, markets, and deploys software to its relationships with its customers. Ozzie doesn't want to beat Google at its own game; rather, he wants to remind Google that the software game has been and remains Microsoft's. But to succeed, he's going to have to rewrite Microsoft's playbook along the way.<br />
<br />
Nearly five years ago Ozzie, then Microsoft's newly minted CTO, issued a memo outlining his vision of the next step in the company's ongoing evolution. "[People are] increasingly drawn toward the simplicity of services and service-enabled software that 'just works,'" he wrote. "Businesses are increasingly considering what services-based economics of scale might do to help them reduce infrastructure costs or deploy solutions as-needed and on subscription basis."<br />
<br />
In other words, Ozzie felt it was high time for Microsoft to compete with Google on its home turf. But in Ozzie's vision, Microsoft would embrace the Web differently than the search titan has. While Google sees the browser as the ultimate client UI for software large and small, with the cloud as the ultimate repository for all data, Ozzie sees an opportunity for Microsoft to offer services that augment and enhance traditional desktop software. Where Google sees thin clients interfacing with powerful applications, Ozzie sees rich client applications consuming lightweight services.<br />
<br />
<i>My vision: Maybe it's time for us - .NET developers to learn more about web services.</i><br />
<i>Full article: </i><a href="http://www.pcworld.com/article/189964/"><i>Microsoft Chief's Battle Plan: Vaporize Google's Cloud</i></a>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-44326323428569539842010-02-28T18:12:00.001+07:002015-04-12T18:09:27.275+07:00Basic LINQ to XMLLINQ makes it easier to work with XML documents. Below are some very basic things LINQ to XML can do to help you get stated.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">1. Create an XML file</span><br />
<pre class="brush:csharp">XElement xml = new XElement("Games",
new XElement("Game",
new XElement("Id", 1),
new XElement("Name", "Dragon Age: Origins"),
new XElement("Genre", "RPG"),
new XElement("ESRB", "Mature")),
new XElement("Game",
new XElement("Id", 2),
new XElement("Name", "HAWX"),
new XElement("Genre", "Flight Action"),
new XElement("ESRB", "Teen")),
new XElement("Game",
new XElement("Id", 3),
new XElement("Name", "World of Warcraft"),
new XElement("Genre", "Online RPG"),
new XElement("ESRB", "Teen"))
);
xml.Save("Games.xml");</pre><div class="separator" style="clear: both; text-align: center;"><img alt="XML file: Games" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-r18jEv5mF4HbkVqSIcdTD7tbfk9U1AiGuow3rGXn0BYRX6UCtd2RMy-apJo7pfDH4bCmIfvqUPfs6mOW-8xBqJ0D9tdfs_hRxWIC8x26fA9eP-q65hqz69YNAWSgacWdEQtGGc39Z8A/" /> </div><div style="text-align: center;"><i>Games.xml's content</i></div><br />
<span class="Apple-style-span" style="font-size: large;">2. Retrieve value from an XML document</span><br />
<pre class="brush:csharp">XElement xml = XElement.Load("Games.xml");
var game = from g in xml.Elements("Game")
where (int)g.Element("Id") == gameId
select g;
foreach (var g in game)
{
Console.WriteLine(g.Element("Name").Value);
}
</pre><div class="separator" style="clear: both; text-align: center;"><img alt="Retrieved value from the XML document" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrtBUC1iQsbMRhqajzlNE9zhAwdWkGqUPLH5Hk-qTPtOz7m4BSqBMEB-0lWqa7rRmvNK7dAcZKQ_8XKipMS61cwrzUCD9k4TSwyq6XLyLOe8OYWX1Ut23ctjE6FNNkDTE_4OaZ5CyXFO8/" /></div><div style="text-align: center;"><i>Retrieved value</i><br />
<i><br />
</i></div><span class="Apple-style-span" style="font-size: large;">3. Update value</span><br />
<pre class="brush:csharp">XDocument xml = XDocument.Load("Games.xml");
XElement game = xml.Descendants("Game").First();
game.SetElementValue("Genre", "Action RPF");
Console.WriteLine(game);
</pre><div class="separator" style="clear: both; text-align: center;"><img alt="Element with updated value" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhocnZJrK0GPZF3SxMrotoAdedtcR4NbcKl4OZerSoO3O5VHh36TaPNvKb4Xw_LBg__MwhRkiMyy5P9ALiIKM6mq8d7PhnfQjuBFVUlHuJ14wOEWJ-khma3LgMIhpEVbzKXLjtzCY_i5mY/" /></div><div class="separator" style="clear: both; text-align: center;"><i>Updated value</i></div><br />
<span class="Apple-style-span" style="font-size: large;">4. Add new element and attributes to the existing document</span><br />
<pre class="brush:csharp">XmlReader reader = XmlReader.Create("Games.xml");
XDocument xml = XDocument.Load(reader);
XElement game = xml.Descendants("Game").First();
game.Add(new XElement("ReleasedDate",
new XAttribute("Day", 31),
new XAttribute("Month", 12),
new XAttribute("Year", 2009)
));
StringWriter sw = new StringWriter();
XmlWriter w = XmlWriter.Create(sw);
xml.Save(w);
w.Close();
Console.WriteLine(sw);
</pre><div class="separator" style="clear: both; text-align: center;"><img alt="XML document with new element & attributes added" border="0" height="252" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSL20dFu6vxyYIgROtfU6SMoTzpUJAlp-IWMwlFSpC9cs3VB26cemXe39LhukvaxMFoRxHao8w8Nl3K58QUk1EClWz5ZXsHWMgMiX6KQU8SA1rGpyWWu2WyJqd9kn2gwoxUqAGoL-A8UI/" width="400" /></div><div class="separator" style="clear: both; text-align: center;"><i>New element and attributes were added to the first Game element</i></div><br />
<span class="Apple-style-span" style="font-size: large;">5. Remove an element</span><br />
<pre class="brush:csharp">XElement xml = XElement.Load("Games.xml");
xml.Descendants("Game").First().Remove();
Console.WriteLine(xml);
</pre><div class="separator" style="clear: both; text-align: center;"><img alt="First Game element removed" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizgBwbEL-OhBqSZOasMdelsHszifJyOnC9igRNxMjNLikzmHTT-ks2zJ2yL3lErxrOLPmH7nnHk4Y9GuCEVJBJlwMi9BSXRah3E5mZca8Xtb8E4MosG9cNeXuY8hr8oFz60fgcRPmFRCQ/" /></div><div class="separator" style="clear: both; text-align: center;"><i>The first Game element was removed</i></div><br />
Please don't criticize me for not explaining the code :-) The code should explain itself, otherwise just leave me a comment.<br />
<a href="http://www.codeproject.com/KB/WPF/wpf-mvvm-lts/LinqToXml.zip">Download Source Code</a>
<script type="text/javascript">
SyntaxHighlighter.highlight();
</script>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-38764347113844674892010-02-03T14:51:00.000+07:002010-06-13T11:39:52.477+07:00WPF Controls gone wildHave a taste of Windows Presentation Foundation with this short video gathering various applications including my <a href="http://x189.blogspot.com/2009/11/introducing-blue-rose-sale-management.html">sales management project</a> - <a href="http://x189.blogspot.com/2009/11/blue-rose-screenshots.html">Blue Rose</a>. You will see from a simple TextBox to 3D, charts...<br />
<object height="340" width="560"><param name="movie" value="http://www.youtube.com/v/x9W2ay4mSUg&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/x9W2ay4mSUg&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object><br />
See? WPF is not only for show but also functional.Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com2tag:blogger.com,1999:blog-3729569185716997747.post-68277495884620659332010-01-23T18:24:00.003+07:002010-06-13T11:39:01.923+07:00Why Windows 7 Taskbar so powerfulThere are many cool things about Windows 7: faster than Vista, short startup time, <a href="http://www.youtube.com/watch?v=MzQQcdw1qmY" target="_blank">the funny Snap</a> and <a href="http://www.youtube.com/watch?v=5CuVmAukssM" target="_blank">the crazy Shake</a> :-) , themes, Libraries... But the thing I (and I'm sure many others) like most about Windows 7 is its Taskbar.<br />
<br />
<span style="font-size: large;">The Taskbar</span><br />
Windows 7's Taskbar is the first thing made me want to use this OS. You can pin your favorite programs on the taskbar for easy access and rearrange them the way you like, you can also preview the open programs in thumbnails and in full-screen.<br />
Remember to use the taskbar's right edge to peek at and show desktop.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6e8s2E0YFb9Fm7Os0xmAMiezgYPPo-oibtrtZkUp8LPZ0nfBypIoMcST0BYTkMjP6iezgX5eDNuuqoHW70kBf0AmL489hkGkmcvHNE-l3nvWNzthrlCEuQT7hH6vC3D6wjhD3p-7nMks/s1600-h/Windows-7-Taskbar.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Windows 7 Taskbar: Preview Window" border="0" height="356" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6e8s2E0YFb9Fm7Os0xmAMiezgYPPo-oibtrtZkUp8LPZ0nfBypIoMcST0BYTkMjP6iezgX5eDNuuqoHW70kBf0AmL489hkGkmcvHNE-l3nvWNzthrlCEuQT7hH6vC3D6wjhD3p-7nMks/s640/Windows-7-Taskbar.png" width="585" /></a><br />
</div><br />
To make it easier to switch from one window to another, you may want to combine similar windows only when taskbar is full. Right click on the taskbar or start menu -> choose Properties -> switch to Taskbar tab -> at Taskbar buttons property, choose "Combine when taskbar is full" and click OK.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb1bvh_58jz9z69Dz-AnJPcuLbwmwKRzrjv7NF1rtzMd6qikwCT00qgBSR5VASyJIAovTL1uL10szFDLAdiUG2wiOFPmspEfxPc6obR7sufqXnTaWllbPiuNa4XwH69c7e0On5NK7xpMs/s1600-h/Combine-when-taskbar-is-full.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Windows 7: Combine when taskbar is full" border="0" height="192" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb1bvh_58jz9z69Dz-AnJPcuLbwmwKRzrjv7NF1rtzMd6qikwCT00qgBSR5VASyJIAovTL1uL10szFDLAdiUG2wiOFPmspEfxPc6obR7sufqXnTaWllbPiuNa4XwH69c7e0On5NK7xpMs/s640/Combine-when-taskbar-is-full.png" width="585" /></a><br />
</div><div style="text-align: center;"><i>Combine when taskbar is full</i><br />
</div><br />
<span style="font-size: large;">The Jump Lists</span><br />
Jump Lists make Windows 7's Taskbar better. They show you your recent or frequent documents, songs, websites,... You can pin your files there by drag and drop them on the taskbar; a file will be pinned to the Jump List of its relevant program: a pdf file will be pinned to Adobe Reader's jump list, a folder will be pinned to Windows Explorer's jump list...<br />
Jump Lists don't just show shortcuts to files. Sometimes they also provide quick access to commands for things like composing new e‑mail messages or playing music.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmTmM5fXdAd1ojQt5HBl-pE3ETkgfpYjHZRQKsswIupi0HCL9YtDdas5AljuXb4DklIqdVNoNPUJ8kfpFbidJw5a7LFC6FaFseejBvPPAamfwaZN2s81Gl1c1diJBhNQ8C92FAENv7KWk/s1600-h/Windows-7-Jump-Lists.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Windows 7 Start Menu and Taskbar Jump Lists" border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmTmM5fXdAd1ojQt5HBl-pE3ETkgfpYjHZRQKsswIupi0HCL9YtDdas5AljuXb4DklIqdVNoNPUJ8kfpFbidJw5a7LFC6FaFseejBvPPAamfwaZN2s81Gl1c1diJBhNQ8C92FAENv7KWk/s640/Windows-7-Jump-Lists.png" width="585" /></a><br />
</div>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com3tag:blogger.com,1999:blog-3729569185716997747.post-42737864179321565742010-01-12T20:02:00.003+07:002015-04-12T18:12:53.007+07:00Data Binding and Validating in WPFThis article shows you the power of WPF's data binding engine, we also create a custom ValidationRule to validate data along the way.<br />
<br />
First we need to create a new WPF application project. Drag a TextBox, a TextBlock, and a Button into the startup window.<br />
<div class="separator" style="clear: both; text-align: center;"><img border="0" height="227" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFwvOy6gySwdduCOZlF5b_HlRYdYg7UymOmjXr37JpGNeAo-IWl8n_BjweH616LDApSeAc_4472F_WczGbiNQRKBj-ui_xn_33nb4PqMd3mZ1Jz_C7LQf4y06pAkaaT-rhvizbbJyuOiM/s640/GUI.png" width="585" /><br />
</div><blockquote>I used Microsoft Expression Blend for designing, but since this is a very simple app, you can do everything easily with Visual Studio.<br />
</blockquote>Add a new class to your project and name it Person:<br />
<pre class="brush:csharp">public class Person
{
public int Age { get; set; }
}
</pre><br />
Now we can add some code to the startup window:<br />
<pre class="brush:csharp">public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
Person aPerson = new Person();
aPerson.Age = 19;
this.DataContext = aPerson;
}
}
</pre>By setting MainWindow's DataContext to aPerson, we've made all controls contained in MainWindow have the same DataContext - aPerson as their root element. So now we can make ageTextBox bind to Age property of aPerson by changing the textbox's Text property like this:<br />
<pre class="brush:xml">Text="{Binding Age}"
</pre>ageTextBox will show 19 when you run the app.<br />
<br />
<span style="font-size: large;">Validating</span><br />
Delete the Text property and modify the TextBox like this:<br />
<pre class="brush:xml"><TextBox x:Name="ageTextBox" ...>
<Binding Path="Age">
<Binding.ValidationRules>
<ExceptionValidationRule/>
</Binding.ValidationRules>
</Binding>
</TextBox>
</pre>Now the textbox's border will turn red when you type some non-numeric character in the textbox and click Check button (actually, Check button does nothing, ageTextBox's Text property is automatically be validated every-time the textbox loses focus)<br />
<br />
Displaying error messages is easily done with data binding.<br />
Use the TextBlock to display:<br />
<pre class="brush:xml">Text="{Binding (Validation.Errors)[0].ErrorContent, ElementName=ageTextBox}"
</pre>We can also display in ageTextBox's ToolTip itself:<br />
<pre class="brush:xml">ToolTip="{Binding (Validation.Errors)[0].ErrorContent, ElementName=ageTextBox}"
</pre><div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy9FcKop2NSM5PjkNeS8blIS0Hb3pQjcIy5LrOaBRjp9WqUFbN-tSubGtIXJwrV-5Dcc4XXXVlNz5jxANRQ1i6hracwoQi2YzRUB1ReNUBeybjNIxZk0POqN4LvHzcDJo9JB4KM4yQEBY/s1600/Displaying-Error-Message.png" /><br />
</div><br />
You can also create your own validation rule by using a new class:<br />
<pre class="brush:csharp">public class AgeRule : ValidationRule
{
public int Min { get; set; }
public int Max { get; set; }
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
{
int number;
if (!int.TryParse(value.ToString(), out number))
{
return new ValidationResult(false, "Invalid age");
}
if (number < Min || number > Max)
{
return new ValidationResult(false, string.Format("Age out of range ({0}-{1})", Min, Max));
}
return ValidationResult.ValidResult;
}
}
</pre><br />
Add<br />
<pre class="brush:xml">xmlns:local="clr-namespace:ExceptionHandling"</pre>right under<br />
<pre class="xml" name="code"><Window</pre>Change ExceptionHandling to the namespace of your project if needed.<br />
<br />
Change ageTextBox's ValidationRules to:<br />
<pre class="brush:xml"><Binding.ValidationRules>
<local:AgeRule Min="13" Max="99"/>
</Binding.ValidationRules>
</pre><br />
Run the app and make sure that ageTextBox is validated by AgeRule.<br />
<a href="http://www.codeproject.com/KB/WPF/wpf-mvvm-lts/ExceptionHandling.zip">Download Source Code</a>
<script type="text/javascript">
SyntaxHighlighter.highlight();
</script>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com1tag:blogger.com,1999:blog-3729569185716997747.post-5709551782142431452010-01-03T10:27:00.009+07:002011-02-20T18:49:00.170+07:0010 Extensions that make you love Chrome (more)<div>I love Google Chrome for its simple and beautiful User Interface, its useful New Tab and Omnibox, its multiprocess architecture, I also like its themes and its speed...<br />
</div><div>I said goodbye to Firefox and some great Add-ons.<br />
</div><div>I was happy with a non-extensions Chrome; but since Chrome Extensions released, I'm sure I can't be happy without these extensions:<br />
</div><br />
<table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0">
<tr class="extension_enabled" jstcache="4" jsvalues=".className:enabled ? 'extension_enabled' : 'extension_disabled'"><td align="center" height="50" jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top" width="62"><img alt="Chrome SEO extension" height="48" jstcache="10" jsvalues=".src:icon" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNP4hhFq6T63M5pGoSo5ySipSV27nCO7Uk_Egy-pg0k_B8TdBzO4Lp49ot9BBYfoI44p4lBNrzdjn4H5oejs9UNHBbPwCPbfvp-3_HP88fX2-TmGYP3jX0BW81TlSekyW0-C9XgvRPmIU/" width="48" /><br />
</td><td jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top"><div jstcache="0"><span style="font-weight: bold;">1. <a href="https://chrome.google.com/extensions/detail/oangcciaeihlfmhppegpdceadpfaoclj" target="_blank">Chrome SEO</a></span><br />
</div><div class="extension-description" jscontent="description" jstcache="6" style="margin-top: 0.4em;">Current features: show number of Pages Indexed on Google, Yahoo...; show Page Rank by Alexa, Google...; show IP Address, Server Location...; Back-links; Social Bookmarks; Cached Versions.<br />
</div></td></tr>
</tbody></table><span style="font-family: Arial; font-size: 12px;"></span><br />
<table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0">
<tr class="extension_enabled" jstcache="4" jsvalues=".className:enabled ? 'extension_enabled' : 'extension_disabled'"><td align="center" height="50" jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top" width="62"><img alt="Forecastfox Weather extension" height="48" jstcache="10" jsvalues=".src:icon" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKrD7xXNxsdC3Lqt3fMvmdemifamXEQS7vYf2wXhK_nTMB1Jlv8YGWu7nng4DnW6FNtW7DjGRyMciDfic4smAraizs4R8KtMGdGBaOiaxiRFjsZbMZksfnEtmOKl_Q0aadSMIj9zvYtFM/" width="48" /><br />
</td><td jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top"><div jstcache="0"><span style="font-weight: bold;">2. <a href="https://chrome.google.com/extensions/detail/ihffmkcfkejomlfnilnmkokcpgclhfeg" target="_blank">Forecastfox Weather</a></span><br />
</div><div class="extension-description" jscontent="description" jstcache="6" style="margin-top: 0.4em;">Get international weather forecasts from AccuWeather.com.<br />
</div></td></tr>
</tbody></table><span style="font-family: Arial; font-size: 12px;"></span><br />
<table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0">
<tr class="extension_enabled" jstcache="4" jsvalues=".className:enabled ? 'extension_enabled' : 'extension_disabled'"><td align="center" height="50" jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top" width="62"><img alt="goo.gl URL Shortener extension" height="48" jstcache="10" jsvalues=".src:icon" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqam-u8J1AoUDyP4f3cIh9Ew18miBPvzJ6y1tU_keNlhcSI2ckHgdKRCgnD70RLot9eAUPB2ieGno8QfkQPsvkD5Nknu1ctJVlR8fUeNWMXXvHb3CgBcy93yr0DhocyftoersehY0QR9U/" width="48" /><br />
</td><td jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top"><div jstcache="0"><span style="font-weight: bold;">3. <a href="https://chrome.google.com/extensions/detail/iblijlcdoidgdpfknkckljiocdbnlagk" target="_blank">goo.gl URL Shortener</a></span><br />
</div><div class="extension-description" jscontent="description" jstcache="6" style="margin-top: 0.4em;">Shorten url with goo.gl, the new Google URL shortener<br />
With just one click, you have a shorten URL that automatically copied to the clipboard.<br />
</div></td></tr>
</tbody></table><span style="font-family: Arial; font-size: 12px;"></span><br />
<table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0">
<tr class="extension_enabled" jstcache="4" jsvalues=".className:enabled ? 'extension_enabled' : 'extension_disabled'"><td align="center" height="50" jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top" width="62"><img alt="Google Mail Checker Plus extension" height="48" jstcache="10" jsvalues=".src:icon" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPxCh8wWBFXBgTntEpe0jz-mQq0I2D_Z51j45-XCl65ljZ6c9iRS6PiyryricA_oYiwO-ZW7DkCL_vWSZA82dDdgwkExkjJcM2_3sWOb0PpyOOGQswws1I9b-Mze78zsvZAl9oJa5dYoM/" width="48" /><br />
</td><td jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top"><div jstcache="0"><span style="font-weight: bold;">4. <a href="https://chrome.google.com/extensions/detail/gffjhibehnempbkeheiccaincokdjbfe" target="_blank">Google Mail Checker Plus</a></span><br />
</div><div class="extension-description" jscontent="description" jstcache="6" style="margin-top: 0.4em;">Displays the number of unread messages in your Gmail and Google Apps inbox. Preview mail, read, delete, archive and mark as spam!<br />
Many users admit it's better than the more-popular <a href="https://chrome.google.com/extensions/detail/mihcahmgecmbnbcchbopgniflfhgnkff" target="_blank">Google Mail Checker</a> extension.<br />
</div></td></tr>
</tbody></table><span style="font-family: Arial; font-size: 12px;"></span><br />
<table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0">
<tr class="extension_enabled" jstcache="4" jsvalues=".className:enabled ? 'extension_enabled' : 'extension_disabled'"><td align="center" height="50" jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top" width="62"><img alt="Google Reader Checker extension" height="48" jstcache="10" jsvalues=".src:icon" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkaeHFnKfdN_6V6eRVH9nFRDUZkKg-Ogzpv7L3aoMm7Hi7yWHtgEKLJpSHdw0I49AcecEHhoYHfZt1Hbj5JICjlEsu8eYyBAQMtbutv57rS79JQ2KWCjLW7cyx6lPqSzkFEwXHPHHSwtg/" width="48" /><br />
</td><td jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top"><div jstcache="0"><span style="font-weight: bold;">5. <a href="https://chrome.google.com/extensions/detail/jnmalhpnifcgaicdjnacljombhmgagin" target="_blank">Google Reader Checker</a></span><br />
</div><div class="extension-description" jscontent="description" jstcache="6" style="margin-top: 0.4em;">This extension adds a button to the menu bar which notifies when a Google Reader feed has a new item<br />
</div></td></tr>
</tbody></table><span style="font-family: Arial; font-size: 12px;"></span><br />
<table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0">
<tr class="extension_enabled" jstcache="4" jsvalues=".className:enabled ? 'extension_enabled' : 'extension_disabled'"><td align="center" height="50" jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top" width="62"><img alt="IE Tab Classic extension" height="48" jstcache="10" jsvalues=".src:icon" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZGgc6FMZEky19QCizMiLrZtNxVr4tGwlSV0sbp34bpzvmi8TSdANcfomBc3s_S8Ne2rkbryQduyZmrXNi619OTFbw_cweG2kQeBqqqhrKA38ejClWjS9NfugDxuhvSFb0FM7D6oFKlO0/" width="48" /><br />
</td><td jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top"><div jstcache="0"><span style="font-weight: bold;">6. <a href="https://chrome.google.com/extensions/detail/miedgcmlgpmdagojnnbemlkgidepfjfi" target="_blank">IE Tab Classic</a></span><br />
</div><div class="extension-description" jscontent="description" jstcache="6" style="margin-top: 0.4em;">Internet Explorer inside Chrome<br />
Cannot run some website in Chrome? (Office Live Workspace from Microsoft is an example). Try this.<br />
</div></td></tr>
</tbody></table><span style="font-family: Arial; font-size: 12px;"></span><br />
<table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0">
<tr class="extension_enabled" jstcache="4" jsvalues=".className:enabled ? 'extension_enabled' : 'extension_disabled'"><td align="center" height="50" jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top" width="62"><img alt="RSS Subscription extension" height="48" jstcache="10" jsvalues=".src:icon" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjDnsdfsx_8-BUiWiAan8PvYpaViAvLIe_qmejuTy71q3ceeQw4HnuD2-8JqOGWO0CKsAhV04bvADjn8tygc3YxU7xm82-bKuuc_QGXUGErxXPOe7JVKe4YWYe4wJT8_G0LdEZTtq97Ac/" width="48" /><br />
</td><td jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top"><div jstcache="0"><span style="font-weight: bold;">7. <a href="https://chrome.google.com/extensions/detail/nlbjncdgjeocebhnmkbbbdekmmmcbfjd" target="_blank">RSS Subscription Extension (by Google)</a></span><br />
</div><div class="extension-description" jscontent="description" jstcache="6" style="margin-top: 0.4em;">This extension auto-detects RSS feeds on the page you're reading, upon finding one will display an RSS icon in the Omnibox, allowing you to click on it to preview the feed content and subscribe.<br />
</div></td></tr>
</tbody></table><br />
<table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0">
<tr class="extension_enabled" jstcache="4" jsvalues=".className:enabled ? 'extension_enabled' : 'extension_disabled'"><td align="center" height="50" jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top" width="62"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><img alt="Slideshow extension" height="48" jstcache="10" jsvalues=".src:icon" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizs_YsWL4a0FeL54C22dvyTFaimfbjcTZjt7a6obVB86gvqLsBgxK4ygWZIf62UfNFAMik5IGTwB1AFrIXpUP1uoyF3Q1lGoe4ycym9Cjp9-_ywFklqCN3wufJvrNPwz-Jwzn2xOXv3Ec/" width="48" /><br />
</div></td><td jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top"><div jstcache="0"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="font-weight: bold;">8. <a href="https://chrome.google.com/extensions/detail/hijbjhjjipenfibfbleadidijdimlpmk" target="_blank">Slideshow</a></span><br />
</div></div><div class="extension-description" jscontent="description" jstcache="6" style="margin-top: 0.4em;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Turn your favorite photo sites, such as Flickr, Picasa, Facebook, and Google Images into a slideshow.<br />
</div></div></td></tr>
</tbody></table><table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0"> </tbody></table><span style="font-family: Arial; font-size: 12px;"></span><br />
<table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0">
<tr class="extension_enabled" jstcache="4" jsvalues=".className:enabled ? 'extension_enabled' : 'extension_disabled'"><td align="center" height="50" jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top" width="62"><img alt="Tab Menu extension" height="48" jstcache="10" jsvalues=".src:icon" menu="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq3O4WiBWuQoK-MtmfURuyyMcKyBOitceQ8ns5XwmRhyphenhyphen86W80pkBri9HeunkBUxUJlfc57DpuVqbweAUK3cRrOxJJj5Qx3gO4i3FJvXnQibKTk3PsBuVHLdY5IsKSWjo3_U_L_AIBB5po/" tab="" width="48" /><br />
</td><td jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top"><div jstcache="0"><span style="font-weight: bold;">9. <a href="https://chrome.google.com/extensions/detail/galfofdpepkcahkfobimileafiobdplb" target="_blank">Tab Menu</a></span><br />
</div><div class="extension-description" jscontent="description" jstcache="6" style="margin-top: 0.4em;">Select, close, rearrange, and search your tabs in a vertical menu! Extras: merge windows, keyboard shortcut, and tab counter!<br />
What's the solution for too many tabs? Display them vertically!<br />
</div></td></tr>
</tbody></table><span style="font-family: Arial; font-size: 12px;"></span><br />
<table cellpadding="2" cellspacing="0" jstcache="0"><tbody jstcache="0">
<tr class="extension_enabled" jstcache="4" jsvalues=".className:enabled ? 'extension_enabled' : 'extension_disabled'"><td align="center" height="50" jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top" width="62"><img alt="Xmarks Bookmarks Sync extension" height="48" jstcache="10" jsvalues=".src:icon" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio7cQSmhEv0aornV3KUA7lyKrrq4U9hXnVgAn-3RuV2BdMI_HN_SGEqvnlf0Zr1QziuP8Xqd0oP4aUNYKHJUJw0CpVv2-O_URrdbzBD6_-YwC5vngCVERZeID2mKfiTpDkgp_Vc1SaiG0/" width="48" /><br />
</td><td jstcache="0" style="padding-bottom: 4px; padding-top: 5px;" valign="top"><div jstcache="0"><span style="font-weight: bold;">10. <a href="https://chrome.google.com/extensions/detail/ajpgkpeckebdhofmmjfgcjjiiejpodla" target="_blank">Xmarks Bookmarks Sync</a></span><br />
</div><div class="extension-description" jscontent="description" jstcache="6" style="margin-top: 0.4em;">Backup and sync your bookmarks across computers and browsers. Xmarks is also available for Firefox, Safari and IE.<br />
You can sync Chrome's bookmarks on various computers with Chrome's Bookmark Sync. But you need Xmarks to sync with other browsers.<br />
</div></td></tr>
</tbody></table><br />
<div>Still have other great extensions in your mind? Feel free to share us your opinions about your favorite extensions.<br />
</div>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com5tag:blogger.com,1999:blog-3729569185716997747.post-74907316540044416142009-12-22T14:49:00.012+07:002015-04-12T18:17:21.363+07:00Simple Search Engine for Languages with AccentsIn this article, we’re creating a simple search engine to perform relevant search for English as well as languages with accents like Vietnamese (e.g. Việt Nam), French (e.g. résumé)...<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Identify whether the data string contains word(s) in the search string</span><br />
“program”. Contains(“a”) is true; but imagine Google uses Contains method :-) what will happen if we do a Google search for “a”? Our extension method will do something like this: "program".ContainsWord("pro") is false, "a program".ContainsWord("program") is true, "a program".ContainsWord("a b") is true...<br />
<pre class="brush:csharp">public static bool ContainsWord(this string dataString, string searchString)
{
string[] dataWords = dataString
.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] searchWords = searchString
.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (string searchWord in searchWords)
{
if (dataWords.Contains(searchWord))
return true;
}
return false;
}
</pre><blockquote><b>Extension Methods</b>: you might have notice the keyword "this" in the first parameter. "this string dataString" extends the string class so we can use either ContainsWord(dataString, searchString) or dataString.ContainsWord(searchString). More on <a target="_blank" href="http://msdn.microsoft.com/en-us/library/bb383977.aspx">Extension Methods</a></blockquote>dataString and searchString are separated into 2 string arrays (dataWords and searchWords), each member of the arrays is a word in the strings. If dataWords contains any of the words in searchWords, the method will return true.<br />
<div class="separator" style="clear: both; text-align: center;"><img alt="Simple Search" border="0" height="282" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzpqE4gNWE5gYdylJ5dJyOYU965_U9ts3wzxu-EgIUUhtiYi_o4XFO2h8Ii0ewM9qBaOa-KkxewE215Fc2htJ6s8D5qL2hMTAL9_pd8Ve5_r6nsHnj9u-H2ltVNIqPFZShTGa2aOGrpGQ/s400/Simple-Search.png" width="400" /></div>A search for "some resume" returns "This is a resume" because "This is a resume" contains the word "resume". But as a Vietnamese, I know people usually prefer to type what they search for without accents; so a search for "some resume" should also return "Résumé", a search for "cong bang" should return "công bằng". That's what we're gonna do next.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Accents in search string? Optional!</span><br />
<pre class="brush:csharp">private static string NormalizeString(string comparedString)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (char c in comparedString.Trim().ToLower().ToCharArray())
{
string normalizedChar = c.ToString()
.Normalize(NormalizationForm.FormD).Substring(0, 1);
stringBuilder.Append(normalizedChar);
}
return stringBuilder.ToString();
}
</pre>Trim() removes all leading and trailing white-space characters, ToLower() converts the string to lowercase, and ToCharArray() returns a character array of the string so we can normalize char by char.<br />
Normalize method turns a character like "ằ" into: "a" + circumflex accent + grave accent; by retrieving the first character with Substring method, we have a normalized character (without accents): "a". stringBuilder connects the normalized characters together.<br />
So NormalizeString("Công Bằng") returns "cong bang", NormalizeString("Résumé") returns "resume"...<br />
<br />
Then we need to use NormalizeString in ContainsWord to normalize both the dataString and the searchString, just normalize the strings before splitting them:<br />
<pre class="brush:csharp">string[] dataWords = NormalizeString(dataString)
.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] searchWords = NormalizeString(searchString)
.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
</pre><br />
That's enough for our simple search engine, do the search again and you'll have:<br />
<div class="separator" style="clear: both; text-align: center;"><img alt="Simple Search for Languages with Accents" border="0" height="283" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7kRmr084oO2hHHoTsZ6C8TMhPRzfaXQy01UXsXgFbA89asXMt0VFSb_EQbu8Sqd39ICoi8y5UgPOfrzTPKBS6kqeYUwC8Tu98l0SnJWI6dv_Rdk6K-j5PbNMOAdDytr5R8NGsBJXufIw/s400/Simple-Search-for-Languages-with-Accents.png" width="400" /></div><br />
This is a very simple search engine. I'm sure you can make lots of advancements to it, and I hope you let me know if you do.<br />
Download source code from <a href="http://www.codeproject.com/Articles/48573/Simple-Search-Engine-for-Languages-with-Accents.aspx" style="color: #999999; text-decoration: none;">CodeProject</a>.
<script type="text/javascript">
SyntaxHighlighter.highlight();
</script>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com0tag:blogger.com,1999:blog-3729569185716997747.post-45005740261333688262009-12-16T12:07:00.013+07:002010-03-21T18:14:01.457+07:00What Matters Now free ebookGet some inspirations for 2010 from <a href="http://sethgodin.typepad.com/">Seth Godin</a>'s free ebook.<br />
<div class="separator" style="clear: both; text-align: center;"><img alt="What Matters Now - Featuring" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9q3OEdRHrhxfzVHxHYRMwNtYL5KQX7k4vuOSXDLM1inQgrjkfj8z_oyYAiNEv82wmVyo5VO1W-EyeI2H1KRg615EtjFEZBLFDQgeiJXsnNSQzXtTstiK2-PuzfMvQDXO8tIKo0-3ZLV4/s640/What-Matters-Now_Featuring.png" width="585" /><br />
</div>More than seventy big thinkers, each sharing an idea for you to think about as we head into the new year. From bestselling author Elizabeth Gilbert to brilliant tech thinker Kevin Kelly, from publisher Tim O'Reilly to radio host Dave Ramsey, there are some important people riffing about important ideas here. The ebook includes Tom Peters, Fred Wilson, Jackie Huba and Jason Fried, along with Gina Trapani, Bill Taylor and Alan Webber.<br />
<div style="margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;">View <a href="http://docs.google.com/viewer?url=http://sethgodin.typepad.com/files/what-matters-now-2.pdf">What Matters Now</a>, and please share.<br />
</div>Anonymoushttp://www.blogger.com/profile/01822053062318626764noreply@blogger.com1