作者: Keefe Dunn

  • Displaying DateTime Object as Desired

    DateTime is a common type we deal with frequently in the development of C#-ASP.NET project. As a result, how to display a DateTime object properly is the knowledge we have to know as a web service developer.

    In the following paragraphs, I made a summary of formatting DateTime object in several circumstances to get it displayed as needed:

    • Format DateTime string retrieved from database and to be binded to Data Controls.
      <ASP:BoundColumn DataField="JoinTime" DataFormatString="{0:yyyy-MM-dd}" >
      </ASP:BoundColumn>
      <ASP:BoundColumn DataField="CheckoutTime" DataFormatString="{0:yyyy-MM-dd HH24:mm:ss}">
      </asp:BoundColumn>

    • Statement in the CodeFile to get a DateTime string.
      e.Item.Cell[0].Text = Convert.ToDateTime(e.Item.Cell[0].Text).ToShortDateString();

    • With the help of String class.
      String.Format( "yyyy-MM-dd ", theDateTimeObj);

    • With the help of Convert method.
      Convert.ToDateTime("2008-12-09").ToString;
      Convert.ToDateTime(dr["PubDate"]).ToShortDateString();

    • ToString method of DateTime class.
      DateTime.Now.ToString("yyyyMMddhhmmss");
      DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");

    • Show only year and month.
      DataBinder.Eval(Container.DataItem,"starttime","{0:yyyy-MM}");

    Certainly, there are more situations when you have to format a DateTime object, and the rules could be deduced from above.

    Technorati Tags: ,,
  • Update Firmware to Solve the Seagate 1.5T Random Halt Bug

    Got a new PC lately. Including:

    CPU: Intel Quad6600
    Motherboard: ASUS P5Q Pro
    Memory: Kingston DDR2 800 2G x4
    Hard Disk: Seagate 1.5TB
    Video Adapter: Galaxy 9800GTX+
    Power Supply: Thermaltake W3030
    Case: Thermaltake Armor+
    Keyboard: Microsoft Natural Ergonomic 4000

    Everything seems to work well, except, err… the hard disk. Rumor has it that Seagate 1.5T with the model ST31500341AS has a bug that, while running low speed writing/reading task, it halts randomly. The bad news is, my 1.5T is without exception.

    Phenomenon

    When I watch some .avi video, the playing process ceases at some random point and the hard disk LED indicator starts flashing endlessly. After a while, everything becomes normal as if nothing ever happened.

    Detail Info

    Hard disk model: ST31500341AS
    Firmware version: SD19
    Video player: Windows Media Player, Media Player Classic
    Video codec: XviD
    Operating System: Windows Vista Ultimate x64

    Solution – firmware update

    Seagate gave out a new version of firmware some time ago, but not publicly. You have to contact [email protected] for this update. If you can’t wait and want to update the firmware right now, follow the steps below AT YOUR OWN RISK:

    1. Download the SD1A firmware in ISO format.
    2. Burn the ISO to a disc. Since the disk is bootable, change the boot device priority in your BIOS & set the first one to CDROM.
    3. Detach all the PATA and SATA devices except the hard disk you’re going to update. IDE device is safe during the process, so you can leave it there.
    4. Restart your computer and the disc will be loaded & run automatically.
    5. A readme text file will be displayed at first, press ESC or F10 to exit and enter the command-line environment.
    6. Enter “S” to select the “scan for ATA devices” command and make sure there is only one device found.
    7. Enter “A” to download the firmware, whose version is SD1A. The update process will start automatically. DO keep the power on during the whole procedure or the hard disk will be damaged permanently.
    8. When everything is done, press any key and the system will shut down. Power on again and that’s it. DO NOT Ctrl-Alt-Del to restart, power off or press any key as what is told in the instruction.

    Looks like a long story but it is simple when you do it yourself. I’ve done it myself and tested the hard disk with firmware SD1A. The bug does go away. If you’ve got any doubts or questions, feel free to contact and I’ll see what I can help.

  • Remove Duplicate Records in a DataTable the Easy Way

    The Merge method of DataTable class is convenient for combining two tables into one. However, the result table may contain duplicate data after the operation. We could write our own function to remove the duplicates, or, we could take advantage of a built-in method of DataView class.

    Method Intro

    There is this DataView method called ToTable with two parameters: (and a three-parameter overloaded version)

    a boolean param distinct
    If true, the returned System.Data.DataTable contains rows that have distinct values for all its columns. The default value is false.

    a string array param columnNames
    A string array that contains a list of the column names to be included in the returned System.Data.DataTable. The System.Data.DataTable contains the specified columns in the order they appear within this array.

    Thought

    We could first create a DataView object dv using the source table dt, then we turn dv into the destination "slim" DataTable dt through that ToTable method introduced above. The redundant data will be removed automatically.

    Coding

    Let’s assume dt is the source DataTable object with duplicate records.

    // create a dv from the source dt
    DataView dv = new DataView(dt);
    // set the output columns array of the destination dt
    string[] strColumns = {"NodeID", "Title", "Url"};
    // true = yes, i need distinct values.
    dt = dv.ToTable(true, strColumns);

    That’s it, the easy way to get redundant data removed from a DataTable object.

    Technorati Tags: ,,
  • Clean up Out-dated Custom Field Data in WordPress Post

    If you ever used a magazine-style theme, you must be familiar with the concept "custom field". In essence, it’s a key-value pair storing post data about what additional info to display in a specific page. In most cases, we take advantage of custom field to display an image related to the post.

    Problems We Have

    There are two major problems with this.

    Firstly, the name of the keys differ among various themes, as a result of which, some custom field data turn to be outmoded when you change the theme.

    Secondly, while a post is becoming out-dated as time goes, there’s little chance for that post to be displayed in any page at all. And the custom field data belonging to that post is getting redundant as well.

    Solutions We Get

    For the first question, the answer is in the following steps:

    Step 1: Go to WordPress admin page and edit whichever post contains that custom field key, then write down the name of the key. In the example below, it is "image".

    Step 2: Go to you phpMyAdmin page and choose the WordPress database from the left column, then click the SQL query window icon.

    Step 3: Type in following query string and "GO". That’s it. (Replace "image" with your key name.)

    # remove entries with "image" as key name
    DELETE FROM wp_postmeta WHERE meta_key = ‘image’

    For the second case, I’ll just provide a way of thinking, instead of a solid answer. For instance, I’ve got five posts with custom fields to show in a specific page, then I should keep the custom fields belonging to the latest five post, and delete the rest of them. A small change of the query string above will do just fine.

    # get the latest post_id
    SELECT @idMax := MAX(post_id) FROM wp_postmeta;
    # keep the latest five and remove the rest of them
    DELETE FROM wp_postmeta WHERE (@idMax – post_id > 5) AND meta_key = ‘image’

    NOTICE: Use the statements above at your own risk, because the value of post_id does not always increase normally.

  • 5D Mark II on Sale in China Finally

    So, here it comes eventually, with the price of about $2900, body only. Not that acceptable though. Start to save money for this baby.

    Some lucky guy has already bought it, the kit.

    Info via CanonRumors.

    Technorati Tags: ,,
  • Talented Artwork Collection 081122

    Alexander Kayiambakis

    a photographer prefers backlighting effect to get the profile


    Julie Pike

    do you feel the intimacy?


    Tommy Næss

  • Customize Flickr Photo Album Plugin to Fit Your Theme

    What Is Flickr Photo Album(FPA) Plugin?

    Flickr Photo Album for WordPress is a fantastic plugin that allows you to pull in your Flickr photo sets and display them as albums on your WordPress blog.

    There is a pretty simple template provided, but you can customize the templates 100% to match the look and feel of your own site.

    And this post will guide you through the process of the customization. It’s pretty easy thanks to the great structuring of this plugin. See FPA in action here.

    Preliminaries before We Start

    From the “Look and Feel Customization” part of FPA’s wiki, we know that to customize this thing, we have to make sure the photoalbum-index.php template file (which is located inside the “template” folder in the plugin’s directory) closely match your own theme’s page.php.

    Let’s first take a look at what the photoalbum-index.php file is like:

    <?php
    /*
    Template Name: Photo Album

    More comments here are omitted…

    */
    global $TanTanFlickrPlugin;
    if (!is_object($TanTanFlickrPlugin)) wp_die(‘Flickr Photo Album plugin is not installed / activated!’);

    get_header();

    // load the appropriate albums index, album’s photos, or individual photo template.
    // $photoTemplate contains the template being used
    ?>
    <div id=“content” class=“narrowcolumn”>
    <?php
    include($tpl = $TanTanFlickrPlugin->getDisplayTemplate($photoTemplate));

    // uncomment this line to print out the template being used
    // echo ‘Photo Album Template: ‘.$tpl;
    ?>

    <?php if (!is_object($Silas)):?>
    <div class=“flickr-meta-links”>
    Powered by the <a href=“http://tantannoodles.com/toolkit/photo-album/”>Flickr Photo Album</a> plugin for WordPress.
    </div>
    <?php endif; ?>

    </div>
    <?php

    // uncomment this if you need a sidebar
    //get_sidebar();

    get_footer();
    ?>

    It is just like a standard page template of WordPress theme, isn’t it?

    Then we shall look into the page template as indicated. There should be a page template file sample in your theme’s directory, named page.php or something like that. Take my current theme as an example, the codes inside look like:

    <?php get_header(); ?>

    <div id=“whitewrap”>

    <div class=“wrapper”>

    <div id=“location”>
    <p><a href=<?php echo get_option(‘home’); ?>/” title=<?php bloginfo(‘name’); ?>>Home</a> / <?php the_title(); ?></p>
    </div>

    <div id=“secondary”>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div id=“postcontent”>
    <?php the_content(); ?>
    </div>
    <?php endwhile; else: ?>
    <?php endif; ?>
    </div> <!– end secondary –>

    <?php include (TEMPLATEPATH . ‘/sidebar-page.php’); ?>

    </div> <!– end wrapper –>

    </div> <!– end whitewrap –>

    <?php get_footer(); ?>

    Compare these two code snipplets and you’ll realize that the main structure is nearly the same. Hence what we’re going to do next is pretty simple bearing this in mind. Besides, those comments inside photoalbum-index.php almost have told you everything you need to do(not very much, though ^^).

    Step 1: Merging the two

    First thing’s first, copy everything between <?php get_header(); ?> and <?php get_footer(); ?> from page.php to photoalbum-index.php to replace its counterpart.

    Step 2: Main Replacement

    Our purpose is to make the structure of photoalbum-index.php accords with that of page.php. So we ought to wipe out lines between <div id=“secondary”> and its closing </div>, then add following codes there:

    <?php
    include($tpl = $TanTanFlickrPlugin->getDisplayTemplate($photoTemplate));
    ?>

    <?php if (!is_object($Silas)):?>
    <div class=“flickr-meta-links”>
    Powered by the <a href=“http://tantannoodles.com/toolkit/photo-album/”>Flickr Photo Album</a> plugin for WordPress.
    </div>

    Keep the promotion link as a tribute to the author.

    Step 3: Tiny Moderation

    In fact, we’ve already finished the job. But there’s a little more to be done: Make the patching where necessary. In my sample, the navigation title should be fixed as below:

    <div id=“location”>
    <p><a href=<?php echo get_option(‘home’); ?>/” title=<?php bloginfo(‘name’); ?>>Home</a> / <?php e(‘Gallery’); ?></p>
    </div>

    Mission Accomplished!

    Now the photoalbum-index.php should look like this:

    <?php
    /*
    Template Name: Photo Album

    So many comments…

    */
    global $TanTanFlickrPlugin;
    if (!is_object($TanTanFlickrPlugin)) wp_die(‘Flickr Photo Album plugin is not installed / activated!’);

    get_header();

    ?>

    <div id=“whitewrap”>

    <div class=“wrapper”>

    <div id=“location”>
    <p><a href=<?php echo get_option(‘home’); ?>/” title=<?php bloginfo(‘name’); ?>>Home</a> / <?php _e(‘Gallery’); ?></p>
    </div>

    <div id=“secondary”>
    <div id=“postcontent” class=“narrowalbum”>
    <?php
    include($tpl = $TanTanFlickrPlugin->getDisplayTemplate($photoTemplate));
    ?>

    <?php if (!is_object($Silas)):?>
    <div class=“flickr-meta-links”>
    Powered by the <a href=“http://tantannoodles.com/toolkit/photo-album/”>Flickr Photo Album</a> plugin for WordPress.
    </div>
    <?php endif; ?>
    </div>
    </div> <!– end secondary –>

    <?php include (TEMPLATEPATH . ‘/sidebar-page.php’); ?>

    </div> <!– end wrapper –>

    </div> <!– end whitewrap –>

    <?php get_footer(); ?>

    In case you need more customization like hooking FPA up with Lightbox or any other display libraries, you can find out more info about how to customize this plugin here.

  • 腾讯,弹窗,见鬼了!

    忍无可忍。

    一直使用官方原版的 QQ ,好些年了。免费用着人家的服务,时不时弹个窗啥的,能理解。但弹窗出来骗点击,就是你腾讯的不对了!

    弹个小窗美其名曰信息聚合,日,你都聚合到火星上去了吧!看见一条广州车展的新车介绍消息,感兴趣之下点击之,咦,怎么到了图库页面?也罢,看到那条新闻标题了,位置挺显眼的,再点,shit ,继续开新窗口,又不是,还是标题,还在正中,好吧,都已经开了这么多个窗口啦,不在乎多开一个,接着点,holy mother fucker ,居然就是不见内容!我RI你个仙人板板,点击率不是这么骗的啊,太TM不厚道了。

    (更多…)

  • Funny Photo Collection 081115

    Image Hosted by ImageShack.us


    Seriously, What the heck have you two done all your life?

    Image Hosted by ImageShack.us


    Most lovely cats I’ve ever seen.

    Image Hosted by ImageShack.us