ASP Classic Connection String Romance

New job and brand new works is giving me new things to learn. Currently I am staying with ASP again! This time it is not but ASP classic.

New job and brand new works is giving me new things to learn. Currently I am staying with ASP again! This time it is not but ASP classic. Continue reading “ASP Classic Connection String Romance”

Random Character With LINQ

Just now, I checked my forgotten stackoverflow account. I looked on some common questions and upvoted the good ones. Then I stumbled to this great answer. Why it was so great? Because it solves common problem, just creating random characters, but using such advance thing. I mean people usually just use Random and create character. This awesome man, using LINQ, giving range of characters to create the random set of character. If you are too lazy to see that, you can see the code below.

var random = new Random();
var result = new string(
    Enumerable.Repeat(chars, 8)
              .Select(s => s[random.Next(s.Length)])

all credits goes to dtb

Some Weird Thing on VS2010 Today

Returning to ASP after a long journey in PHP made me had some weird and awkward situations with Visual Studio. One of them wass when I tried to use ConfigurationManager class. I included the System.Security in my reference, but then nothing seemed to show. The message kept saying that The name ‘ConfigurationManager’ does not exist in the current context!

I tried to look on the reference and check the class, it exist. Then I rebuilt my project (It was using Orchard and I needed to compile about 25 modules). Still, the same notification and build error occurred.

I tried to do it “dumb way”. I removed the using statement and commented the code line that using ConfigurationManager class. I removed the reference, too! Then I rebuilt (clean first then build). It success. I re-added the reference and rewrite the code line. Voilà it works just fine now!

Making YouTube Thumbnail as Post Thumbnail in WordPress

Creating video thumbnail can be tricky on WordPress. You will need to add new meta on your post so that the post writer can insert the video ID and update the whole post. This time the key of the post meta that I used is video_id. Have a look on the code! 😀

function store_vid_info($post_id){
    if(($_POST['post_status'] == 'publish') && (in_category('video', $post_id))) {
        $vid_id = get_post_meta($post_id, 'video_id'); /* needed to take meta data. The return will be in array */
        $url = "" . $vid_id[0] . "?v=2&alt=jsonc";

        $content = json_decode(file_get_contents($url)); /* If you use curl, then the header will be overrode and result in error. */

        $post = array(
            'ID' => $post_id,
            'post_content' => "" /* This line will insert the video in iframe to the post content */

         * This will update the post meta (if exist in case of editing post) and will add it.
         * You can change the code to really insert the YouTube thumbnail into your WP thumbnail.
         * I add  the image to a new meta because I'm afraid the theme did not support post thumbnail.
         * If it is, then feel free to change to code.
        if (!update_post_meta($post_id, '_video_thumb', $content->data->thumbnail->hqDefault))
            add_post_meta($post_id, '_video_thumb', $content->data->thumbnail->hqDefault);


add_action('publish_post','store_vid_info'); /* This will hook the function that we have just made to WordPress publish */

Feel free to give comments and feedback 🙂

PHP yeay!

Hello world!

Well, I am back to PHP! After a long time I haven’t used this, I am back again to PHP! So, I am working on a WordPress plugin.

It will allow the user to post through another web. Well, it is intended for a digital agencies, not for really commercial use. I will keep posting on it as the project grows.

C ya!

PS. Any suggestion about flexible and easy to use ASP.NET CMS is most welcome 😀