Sunday, April 21, 2013

Javascript Prototype Object



Prototype is a builtin js property that is part of JS objects. It was introduced in JS version 1.1.
Prototype object can be added only to Function,String, Image, Number, Date and Array.
We can use prototype on the base class not on the objects derived from it.
The prototype object help you quickly add a custom method or member to an object that is
reflected on ALL instances of it.
Prototype object can only be used to add PUBLIC member and methods. It cannot add private
members or methods.
If the prototype object is used to override the the previously set property it will not override the
properties of already created objects. It will only affect the objects that have been created after
the prototype change.

Using prototype on custom objects:


var func = function(){};
func.prototype.foo = "bar"; //adds the property foo
alert(func.foo); //alerts undefined
func2 = new func();
alert(func2.foo); //alerts bar
func2.prototype.foo2 = 'ddd'; //Error : func2.prototype is undefined
Using prototype on builtin JS objects:

String.prototype.foo = "bar";
Image.prototype.foo = "bar";
Number.prototype.foo = "bar";
Array.prototype.foo = "bar";
You cannot use prototype on derived objects:
var str = new String();
str.prototype.foo = 'bar'; //Error : str.prototype is undefined




With Regards,
Animesh Nanda,
Sr. Software Engineer | Photon Infotech
Bengaluru | Karnataka | INDIA.

Wednesday, October 17, 2012

How to read directory or folder contents in PHP

TO GET ALL FILES ON RECURSIVE DIRECTORIES IN SINGLE ARRAY USE THE CODE GIVEN BELOW.




function getFilesFromDir($dir) { 

  
$files = array(); 
  if (
$handle = opendir($dir)) { 
    while (
false !== ($file = readdir($handle))) { 
        if (
$file != "." && $file != "..") { 
            if(
is_dir($dir.'/'.$file)) { 
                
$dir2 = $dir.'/'.$file; 
                
$files[] = getFilesFromDir($dir2); 
            } 
            else { 
              
$files[] = $dir.'/'.$file; 
            } 
        } 
    } 
    
closedir($handle); 
  } 

  return
$this->array_flat($files); 
} 

function 
array_flat($array) { 

  foreach(
$array as $a) { 
    if(
is_array($a)) { 
      
$tmp = array_merge($tmp, array_flat($a)); 
    } 
    else { 
      
$tmp[] = $a; 
    } 
  } 

  return 
$tmp; 
} 
// Code to get folder contents (Usage) $dir = '/data'; $foo = $this->getFilesFromDir($dir); print_r($foo); ?>  




With Regards,
Er.Animesh Nanda
Sr. Programmer Analyst,
Innovate Search Pvt. Ltd..
Bengaluru,Karnataka,INDIA.

Wednesday, July 13, 2011

Showing and Hiding Windows Form in System Tray in VB .net

Show and Hide Windows Form in System Tray

How to show and hide your form in windows system tray.

1. Add NotifyIcon class in your project (System.Windows.Forms.NotifyIcon) and drag it into form.




2. Change NotifyIcon properties.

BalloonTipIcon = Info
BalloonTipText = Running
Change Icon
Text = Running Your Program
Visible = True






3. Add code in Event Form1_Resize.

Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Resize
' If minimize form that will show in system tray.
If System.Windows.Forms.FormWindowState.Minimized = WindowState Then
sysMonTray.ShowBalloonTip(5, "Running", "Running Your Program", ToolTipIcon.Info)
Me.Hide()
End If
End Sub


4. Add code in Event NotifyIcon_Click to hide and show form.

Private Sub sysMonTray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles sysMonTray.Click

If Me.Visible Then
Me.Hide()
Else
Me.Show()
Me.ShowInTaskbar = True
Me.WindowState = FormWindowState.Normal
Me.StartPosition = FormStartPosition.CenterScreen
End If

End Sub



With Regards,
Er.Animesh Nanda
Manusis Technologies Pvt.Ltd.
Bengaluru,
Karnataka,INDIA.

Thursday, July 7, 2011

Sphinx Commands For Beginners

#INDEXER

Configuring single index
indexer --config /full path/sphinx.conf myindex
Configuring all indices
indexer --config /full path/sphinx.conf --all
Rotating single index
indexer --rotate myindex
Rotating all indices
indexer --rotate --all
No output on rotation
indexer --rotate --all --quiet
Not to display progress detail
indexer --rotate --all --noprogress

#SEARCHD

Help
searchd --help
Configuring searchd
searchd --config /full path/sphinx.conf
Configuring port
searchd --port 9313

Status
searchd --status

Checking Status
searchd --config /full path/sphinx.conf --status
IO status
searchd --config /full path/sphinx.conf --iostats
CPU status
searchd --config /full path/sphinx.conf --cpustats

Setting PID file
searchd --config /full path/sphinx.conf --pidfile /home/myuser/sphinx.pid
Forcing to search specified index
searchd --index myindex
Stopping search process
searchd --config /full path/sphinx.conf --stop
Killing all search process
killall searchd


STEPS TO DO IF SPHINX SEARCH IS NOT WORKING

1. killall searchd
2. searchd --config /full path/sphinx.conf --status
3. searchd --pidfile --config /fullpath/sphinx.conf
4. searchd --config /full path/sphinx.conf --status
5. indexer --config /full path/sphinx.conf --all
6. indexer --rotate --all

COMMAND TO SEARCH
search -i myindex -e 'test'

Search Attributes
1. Match modes (--any / --phrase / --boolean / --ext / --ext2 / --filter attr v)
2. Set Limit (--limit count)
3. Set offset value (--offset count)
4. Sort by group (--group attr)
5. Sort by ASC/DESC (--sortby clause)
6. Sort by timestamp attribute (--rsort)




With Regards,
Er.Animesh Nanda
Software Developer,
Manusis Technology Pvt. Ltd.
Bengaluru,Karnataka,INDIA.

Tuesday, July 5, 2011

How to write Sphinx confugiration file ?

Four Steps to create a sphinx confugiration file

STEP - 1
Create a file named as sphinx.conf

STEP - 2
Declare a source as per following.

source src1
{
type = mysql
sql_host = host name
sql_user = user name
sql_pass = password
sql_db = database name
sql_port = 3306 # optional, default is 3306
sql_query = sql query for fetching data
sql_attr_uint = unique column eg id #can use more than one sql_attr_uint
sql_attr_timestamp = date_added
sql_query_info = sql query for viewing in command prompt
}

STEP - 3
Declare an index as per following.

index test1
{
source = src1
path = /var/lib/sphinxsearch/data/test1
docinfo = extern
charset_type = sbcs
enable_star = 1
min_prefix_len = 1
}


indexer
{
mem_limit = 32M
}


STEP - 4
Declare a searchd function as per following.

searchd
{
port = 9312
log = /var/log/sphinxsearch/searchd.log
query_log = /var/log/sphinxsearch/query.log
read_timeout = 5 #return null if no results found for 5 secs
max_children = 30
#maximum result to show in a dropdown or autocomplete
pid_file = /var/run/searchd.pid
max_matches = 1000 #maximum matches to get from database
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
}



After each modification on sphinx.conf file, developer needs to rotate the index declared in the confugiration file.



With Regards,
Er.Animesh Nanda
Software Developer,
Manusis Technology Pvt. Ltd.
Bengaluru,Karnataka,INDIA.

Wednesday, June 29, 2011

Adding Twitter follow button to a web page

There are three ways you can add the Tweet Button to your webpage.
Using javascript

The easiest way to add the Tweet Button to your website is to use javascript. This method requires adding a line of javascript and an HTML anchor to your webpage. Using this method you can customise the Tweet Button using data attributes and query string parameters.

Notice how the anchor element has a class of twitter-share-button. This is required for the Tweet Button javascript to know which anchor elements to convert to buttons.




Using an iframe

If you prefer you can add a Tweet Button using an iframe. When using this method you have to use query string parameters to customise the Tweet Button’s behavior.



Build your own

If you want to be able to customise the way the Tweet Button looks you will want to use this basic format. When using this method you have to use query string parameters to customise the Tweet Button’s behavior as well as handle the popup of the Share Box.

The dimensions of the Share Box are listed in our Tweet Button FAQ.

Tweet

Properties

There are several properties for the Tweet Button which allow you to customise its behavior. Whilst the Tweet Button will work without any of this properties, using them allows you to provide default values for the user to Tweet. If the query string, data source or link source are not provided the Tweet Button will use the default values available from the web page and referrer information.

To learn more about each property and to see ways you can use them check the examples further down this page.
Properties which can be used by all types of Tweet Button

The properties in this table can be used by the javascript, iframe and build your own Tweet Buttons. Each property is a query string parameter for the http://twitter.com/share URL.
Query String Parameter Description
url URL of the page to share
via Screen name of the user to attribute the Tweet to
text Default Tweet text
related Related accounts
count Count box position
lang The language for the Tweet Button
counturl The URL to which your shared URL resolves to


With Regards,
Er.Animesh Nanda
Software Developer,
Manusis Technology Pvt. Ltd.
Bengaluru,Karnataka,INDIA.

Adding facebook like button to a web page

The Like button lets a user share a content with friends on Facebook. When the user clicks the Like button on a site, a story appears in the user's friends' News Feed with a link back to that website.



There are two Like button implementations: XFBML and Iframe. The XFBML version is more versatile, but requires use of the JavaScript SDK. The XFBML dynamically re-sizes its height according to whether there are profile pictures to display, gives you the ability (through the Javascript library) to listen for like events so that you know in real time when a user clicks the Like button, and it always gives the user the ability to add an optional comment to the like. If users do add a comment, the story published back to Facebook is given more prominence.

Attributes

href - the URL to like. The XFBML version defaults to the current page.
send - specifies whether to include a Send button with the Like button. This only works with the XFBML version.
layout - there are three options.
standard - displays social text to the right of the button and friends' profile photos below. Minimum width: 225 pixels. Default width: 450 pixels. Height: 35 pixels (without photos) or 80 pixels (with photos).
button_count - displays the total number of likes to the right of the button. Minimum width: 90 pixels. Default width: 90 pixels. Height: 20 pixels.
box_count - displays the total number of likes above the button. Minimum width: 55 pixels. Default width: 55 pixels. Height: 65 pixels.
show_faces - specifies whether to display profile photos below the button (standard layout only)
width - the width of the Like button.
action - the verb to display on the button. Options: 'like', 'recommend'
font - the font to display in the button. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
colorscheme - the color scheme for the like button. Options: 'light', 'dark'
ref - a label for tracking referrals; must be less than 50 characters and can contain alphanumeric characters and some punctuation (currently +/=-.:_). The ref attribute causes two parameters to be added to the referrer URL when a user clicks a link from a stream story about a Like action:
fb_ref - the ref parameter
fb_source - the stream type ('home', 'profile', 'search', 'other') in which the click occurred and the story type ('oneline' or 'multiline'), concatenated with an underscore.


Open Graph Tags

Open Graph tags are meta tags that you add to the head of your website to describe the entity your page represents, whether it is a band, restaurant, blog, or something else.

An Open Graph tag looks like this:

meta property="og:tag name" content="tag value"

If you use Open Graph tags, the following six are required:

og:title - The title of the entity.
og:type - The type of entity. You must select a type from the list of Open Graph types.
og:image - The URL to an image that represents the entity. Images must be at least 50 pixels by 50 pixels. Square images work best, but you are allowed to use images up to three times as wide as they are tall.
og:url - The canonical, permanent URL of the page representing the entity. When you use Open Graph tags, the Like button posts a link to the og:url instead of the URL in the Like button code.
og:site_name - A human-readable name for your site, e.g., "IMDb".
fb:admins or fb:app_id - A comma-separated list of either the Facebook IDs of page administrators or a Facebook Platform application ID. At a minimum, include only your own Facebook ID.


With Regards,
Er.Animesh Nanda
Software Developer,
Manusis Technology Pvt. Ltd.
Bengaluru,Karnataka,INDIA.