Thursday, May 27, 2010

Local Time Setting from any time zone

 

Ever faced a problem where you capture the date-time and find that it turned out to be server’s local time. This is a common thing with servers spread across the world and being accessed from anywhere. If we need time specific to a zone, here’s a small code snippet…

* This function returns the Indian Standard Time (GMT +0530). You can change the CaseOffset variable as per your need.

(Applies to VB.NET)

''' <summary>
''' Function to return the Current Indian Standard Time (GMT +0530)
''' </summary>
''' <returns>Current IST</returns>
''' <remarks>VSR</remarks>
Public Shared Function getDate() As DateTime

    Dim IST As DateTime
    Dim CaseOffset As TimeSpan = New TimeSpan(5, 30, 0)
    IST = DateTime.UtcNow.Add(CaseOffset)
    Return IST

End Function

Friday, May 07, 2010

Facebook Social Plugins (Part 1)


facebook logo  This article is a part of my series on
Facebook Developers 


Facebook Developers were gifted the new Graph API recently. With this, came the all new documentation. Everything was restructured and many people were left confused. Even I had a little tough time figuring out few things. Then I found Social Plugins section. Social Plugins enables Facebook Users interact with content on your site like Sharing it, Liking it etc. Some of these plugins also enable you to show the interaction that facebook users are having across web.

Following Social Plugins are currently supported by Facebook…

 

Activity Feed (Recent Activity)

http://developers.facebook.com/docs/reference/plugins/activity

If you are using Social Plugins on your website, you would like to show what others are doing there. So Activity Feed is basically what all people did on your site (not facebook) and this information can be shown on any site or blog. For Example, you have an article on your site, which is having a “LIKE” or a “SHARE” button.

So whenever someone shares it on Facebook, or likes it on your site, it will be recorded as an Activity and shown in this box. Currently, if you are logged in, you will see something in box above, but if you are not logged in, you will find a ‘login’ button.

Facebook provides following settings for this Plugin

Domain This is the domain to show activity for. In XFBML, it defaults to the domain the plugin is on.
Width Width of the control (in pixels)
Height Height of the control (in pixels)
Header It specifies whether to show the Facebook Header on Plugin or not. (In sample above, the ‘Recent Activity’ title is the Header)
Color Scheme Facebook offers two color schemes. Light and Dark. Light is the default blue scheme of FB and Dark is the new Black scheme. (In sample above, I used the dark scheme)
Font A wide choice of fonts, that facebook supports are listed here. You can pick one as per your site’s style
Border Color This is the optional border color of plugin. You can specify color in RGB format (prefixed by pound sign #) or the web safe color names (like RED, WHITE etc.)

There are two ways, in which we can include the plugin. One is IFRAME (like I used in example), and other is FBJS/XFBML.

 

Like Button

http://developers.facebook.com/docs/reference/plugins/like


Like button is probably the most common thing asked by most of the clients when they demand something on facebook or related to facebook. The updated Like button has some new features like images of friends, who liked your site and look n’ feel customizations. Note that when we say images of friends, it means that it will show the pics of all those people who are friend of person who is currently viewing the web page and who have liked this web page. So the person viewing the page must be logged into system so images can appear. Otherwise, a simple Like button will come and if user clicks it, s/he will have to login first.

Following settings are supported by Like Button

URL to Like This is the URL, that is to be liked
Layout This can be chosen from Standard or button count.If chosen button count, it shows only the total number of likes in front of Like button.
Show Faces This option can be used if you want to show the pictures of friends of logged person. It will show list of people who liked it.
Width Width of plugin in pixels
Verb to Display This is the text of Like button. It can be “Like” or “Recommend”
Font A wide choice of fonts, that facebook supports are listed here. You can pick one as per your site’s style
Color Scheme There are two color schemes supported by Facebook. One is LIGHT (as in example above) and other DARK

This can be used via IFRAME or XFBML.

 

Like Box

http://developers.facebook.com/docs/reference/plugins/like-box

This plugin allows you to display activity from your facebook page on your website and attract people from website towards your facebook page.

Following properties are supported by this plugin

Facebook Page ID This is the numeric ID of page for which box is to be displayed
Width Width in pixels
Height Height in pixels
Connections Number of faces shown. This will show list of fans (pics). Note that it wont appear if Height is less than 500
Stream Check this if you want to show Live Stream from Page
Header If checked, it will show the “Find us on Facebook” header

This can be used via IFRAME or XFBML.

 

 

… More coming soon

Monday, April 19, 2010

Facebook Application Development


facebook logo  This article is a part of my series on
Facebook Developers 

Facebook has recently grown as most popular social networking site. A large number of applications are currently running on Facebook, and much more are under construction. I also tried my hands on facebook application development and was surprised to see how less support is available for VB.NET based application development for facebook. So, from this article, I start a series on how to create good applications for facebook using Microsoft Visual Basic.NET.

 

Basic Abbreviations and terminology


FB Often used as an abbreviation of facebook
FBML Facebook Markup Language
XFBML Extended Facebook Markup Language
FQL Facebook Query Language (or Functional Query Language)
FBJS Facebook JavaScript
Connect Set of APIs so Facebook data can be accessed outside Facebook
Canvas Area on facebook, where your application will run

(more terms will be explained in later articles)

 

Types of Application….


Facebook Applications

Applications that run inside facebook (CANVAS APPLICATIONS)

Application that run inside facebook can be of either iFrame type or FBML type. Though both can interchangeably be used (with some tweaking). These applications are also called facebook Canvas Applications

FBML is more like HTML, but with slightly changed syntax. You can use FBJS (facebook version of JavaScript) and FQL (Facebook version of SQL)

iFrame is a very beautiful way introduced by facebook. They simply call a URL within the facebook and you are free to play the way you want. If you want to incorporate FBML into an iFrame application or anywhere outside Facebook, you need to use a little more tweaked syntax called XFBML. FBJS and FQL are also supported here.

Application that run outside facebook (CONNECT APPLICATIONS)

Applications that run outside facebook (i.e. on your website, desktop or mobile phone) can access facebook data using facebook Connect. You can also use XFBML and FBJS where HTML or JavaScript is allowed. FQL helps everywhere.

 

For more information, visit http://wiki.developers.facebook.com/

Tuesday, August 19, 2008

Knol, Beyond blogging...

 

 

knol-logo

 

We guys Blog, and now Google tells us to go beyond it. In words of Google, a knol is an authoritative article about a specific topic.

In first look, it seems like a combination of Blogs and Wikipedia. Here you create articles as you do in Blogs, but they are consolidated as in Wiki. There can be contributors, communities and collaborations. Moreover, you can have revisions. You can review Knols, post comments and reply to comments. So this makes it more like forums.


I found some really nice topics in there like Blood Transfusion, Muscle Cramps and the best part is, that these topics are by authentic people from respective fields. Google verifies experts so their content is genuine.

 

So go on....

Add your piece of knowledge to KNOL

 

http://knol.google.com/k/knol#

 

Oh by the way, I loved the way it uses AJAX. Really SUPERFAST

Friday, August 01, 2008

AJAX (Updated Function)

Hi friends,

Here I present an updated way of using AJAX. In my previous post, I explained the use of AJAX through 3 functions. First one will create object, second will send request, and third will receive the response.

Now I have combined these three functions to one. Here it is...

function getPage(CallPage, DivToPopulate)
{
// Declare Object
var httpObject=false;
if(window.XMLHttpRequest) {
// Opera 8.0+, Firefox, Safari
httpObject=new XMLHttpRequest();
}
else if(window.ActiveXObject) {
//Internet Explorer
httpObject=new ActiveXObject("Microsoft.XMLHTTP");
if(!httpObject){
httpObject=new ActiveXObject("Msxml2.XMLHTTP");
}
}
else{
alert("Your Browser is not compatible to use this application");
}
// Show some default message in the Div, that will contain the Content
document.getElementById(DivToPopulate).innerHTML = 'Loding Content...';

//Cache work around
var datevar = new Date();
var timevar = datevar.getTime();
var timestamp= 'TEMP=' + timevar + Math.random();
if (CallPage.indexOf("?") > 0)
{
CallPage = CallPage + '&' + timestamp;
}
else
{
CallPage = CallPage + '?' + timestamp;
}

httpObject.open("GET", CallPage, true);
httpObject.onreadystatechange = function(){
if (httpObject.readyState == 4) {
var txt = httpObject.responseText;
// Show content
document.getElementById(DivToPopulate).innerHTML = txt;
}
};
httpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpObject.send(null);
// Function by Vikramjit R.Rai http://www.vikramjits.com
// For any help, feel free to contact vikramjit.rooprai@gmail.com
}

USAGE:

Simply call the getPage function with two arguments. First is the page to be called and second is the DIV to be populated with the contents of the Page called.

that's it...

Happy Coding :)

Thursday, July 17, 2008

Generate SQL Script with Data - SQL Server

Finally I found a solution to a major problem that almost every developer face at least once in his programming career. This problem is of remote deployment, where you have to send data through a script. It is a real headache to write hundreds of insert queries. Well, the life saver is here...

The solution is "DATABASE PUBLISHING WIZARD"

You can download it from http://www.codeplex.com/sqlhost/Wiki/View.aspx?title=Database%20Publishing%20Wizard

 

Simply install this file and it will appear in your start menu. Click it, run the GUI wizard, and follow the steps.

 

If you want to do this by command line, or want to know more about this tool, its readme file can help. I am pasting it here for your reference.

----

README FILE OF DATABASE PUBLISHING WIZARD

SQL Server Database Publishing Wizard
(c) Copyright Microsoft Corporation, 2006. All rights reserved.
Website:
http://www.codeplex.com/sqlhost

=======================================
What is the Database Publishing Wizard?
=======================================

The Database Publishing Wizard enables the deployment of SQL Server databases
(both schema and data) into a shared hosting environment.  The tool supports
both SQL Server 2005 and 2000 and does not require that source and target
servers are the same version.

The tool provides two modes of deployment:

  1) It generates a single SQL script file which can be used to recreate
  a database when the only connectivity to a server is through a
  web-based control panel with a script execution window.

  2) It connects to a web service provided by your hoster and directly
  creates objects on a specified hosted database

The tool may also be used by hosters to script out databases for backup or
transfer purposes.

=====
Usage
=====

The Database Publishing Wizard provide both a graphical and a command-line
interface.  To use the graphical interface, simply execute "sqlpubwiz.exe"
without any arguments.

To retrieve details on the arguments supported by the command-line
interface, execute the following command:

  sqlpubwiz help

The tool also integrates directly into Visual Web Developer 2005 Express
Edition and all non-Express SKUs of Visual Studio.  Right click on any
SQL Server database connecton and select "Publish to provider..." to launch
the wizard.

For further details on usage please see:

http://www.codeplex.com/Wiki/View.aspx?ProjectName=sqlhost&title=Database%20Publishing%20Wizard

======================================
Simple Command Line Scripting Examples
======================================

The following command will script the FooDB database existing on the local
machine and default instance using the Windows credentials of the executing
user to C:\FooDB.sql:

  sqlpubwiz script -d FooDB C:\FooDB.sql

The following command will script the FooDB database from the default
instance on a machine named MYSERVER using SQL Server authentication with
the username "Alice" and the password "7h92-v6k3" to the file C:\FooDB.sql:

  sqlpubwiz script -d FooDB -S MYSERVER -U Alice -P 7h92-v6k3 C:\FooDB.sql

============
Known Issues
============

For a list of known issues, please see:
http://www.codeplex.com/Wiki/View.aspx?ProjectName=sqlhost&title=DPW%20Known%20Issues

================================================
Support, Feedback, Bug Reports, Feature Requests
================================================

For support and any feedback on the tool, please use the following forum:
  http://www.codeplex.com/Project/ListThreads.aspx?ProjectName=sqlhost&ForumId=1807

 

----

Tuesday, May 27, 2008

Fun with Binary and ASCII

Wanna have fun with Binary and ASCII stuff...

 

open command prompt. Press ALT key and while key is kept pressed, type the Binary code for 'A', which is 1000001. Now, when you will release the ALT key, you will get 'A' printed on prompt. But if you try typing Binary of 'B' (1000010), you will get 'J'.

WHY???

The answer is simple...

Console does not understand Binaries. Instead, it works with ASCII codes. If you press ALT key and type some ASCII code, it will print the character equivalent of that ASCII. In case the number is larger than 256, it will be divided by 256 and remainder will be treated as the new number to be evaluated. As a matter of fact, when we mod binary code or 'A', we get ASCII code for 'A' itself. But in binaries of 'A' and 'B', there is a difference of 10 decimal numbers. So J is printed.

 

So, just hv fun with other binary stuff.