Google’s Currency Converter and JSON API

There are a lot of online Currency Converter Calculators on web. I want to share one more with you.
You can believe it; because its Google’s Currency Converter Calculator. It can be used to see changes live for currency and foreign exchange rates with this free currency converter.

Here is the Google’s Currency Converter

Open JSON API
Good news is here – Google have a secrete API for Currency Conversion. Its a simple open API you can use for all type of foreign currencies.

How to use it?
If you want currency converter £ to dollars, use it like this –
http://www.google.com/ig/calculator?hl=en&q=1GBP=?USD

If you want to calculate currency converter $ to £ –
http://www.google.com/ig/calculator?hl=en&q=1USD=?GBP

You can change value of input currency, for example you want to know the value for $100 in India Rupees
http://www.google.com/ig/calculator?hl=en&q=100USD=?PKR

Hope you enjoyed the post.

Advertisements

Custom Pagination for CI

I have tried Codeigniter pagination for some grid but its bump. So I decide to write own pagination for Codeigniter you can also use it for Core PHP with some alteration. So here is the code:

/*
* @param
* total = number of records
* diff = number of records per page to display
* base_url = url of the page where record is being display
* page = current page displaying
*/
public function pagination($total, $diff, $base_url,$page) {
$output = '

';
$output .= '
Display ';
$output .= form_dropdown('diff', array(15, 30, 45, 60));
$output .= 'Replies';
$output .= '
Next';
$output .= '';
$output .= '
';
$output .= '

';
$output .= 'Previous
';
//generate pagination for specific page
$i = ($page>0 && $page<5)?0:$page-5;
$j = 0;
$total_page = ($page<$total && ($page5))?'...':'';
$page = ($page>0 && $page<5)?0:$page-5;
for (; $i <= $total; $i+=$diff) { $j++; $page++; if ($page >= $total/$diff){
break;
}
if ($j < 10) { // generate pagination with sorting through field is on if ($this->CI->input->get('field') != "")
{
$total_page .= ' ' . $page . ' ';
}
//generate simple pagination link
else
{
$total_page .= ' ' . $page . ' ';
}
}
else
{
$total_page .= '...';
break;
}
}
$output .= $total_page;
$output .= '

';

return $output;
}

Hope this will help, Happy coding.

Windows Run Commands and Shortcuts

Windows XP Home / Pro Run Commands and Short Cuts

How To – Click Start, Click Run and enter the command Click OK

Run commands

Calc – Calculator
Cfgwiz32 – ISDN Configuration Wizard
Charmap – Character Map
Chkdisk – Repair damaged files
Cleanmgr – Cleans up hard drives
Clipbrd – Windows Clipboard viewer
Cmd – Opens a new Command Window (cmd.exe)
Control – Displays Control Panel
Dcomcnfg – DCOM user security
Debug – Assembly language programming tool
Defrag – Defragmentation tool
Drwatson – Records programs crash &amp; snapshots
Dxdiag – DirectX Diagnostic Utility
Explorer – Windows Explorer
Fontview – Graphical font viewer
Ftp – ftp.exe program
Hostname – Returns Computer’s name
Ipconfig – Displays IP configuration for all network adapters
Jview – Microsoft Command-line Loader for Java classes
MMC – Microsoft Management Console
Msconfig – Configuration to edit startup files
Msinfo32 – Microsoft System Information Utility
Nbtstat – Displays stats and current connections using NetBios over TCP/IP
Netstat – Displays all active network connections
Nslookup – Returns your local DNS server
Odbcad32 – ODBC Data Source Administrator
Ping – Sends data to a specified host/IP
Regedit – registry Editor
Regsvr32 – register/de-register DLL/OCX/ActiveX
Regwiz – Reistration wizard
Sfc /scannow – Sytem File Checker
Sndrec32 – Sound Recorder
Sndvol32 – Volume control for soundcard
Sysedit – Edit system startup files (config.sys, autoexec.bat, win.ini, etc.)
Systeminfo – display various system information in text console
Taskmgr – Task manager
Telnet – Telnet program
Taskkill – kill processes using command line interface
Tskill – reduced version of Taskkill from Windows XP Home
Tracert – Traces and displays all paths required to reach an internet host
Winchat – simple chat program for Windows networks
Winipcfg – Displays IP configuration

Management Consoles

certmgr.msc – Certificate Manager
ciadv.msc – Indexing Service
compmgmt.msc – Computer management
devmgmt.msc – Device Manager
dfrg.msc – Defragment
diskmgmt.msc – Disk Management
fsmgmt.msc – Folder Sharing Management
eventvwr.msc – Event Viewer
gpedit.msc – Group Policy -XP Pro only
iis.msc – Internet Information Services
lusrmgr.msc – Local Users and Groups
mscorcfg.msc – Net configurations
ntmsmgr.msc – Removable Storage
perfmon.msc – Performance Manager
secpol.msc – Local Security Policy
services.msc – System Services
wmimgmt.msc – Windows Management

Shortcuts

access.cpl – Accessibility Options
hdwwiz.cpl – Add New Hardware Wizard
appwiz.cpl – dd/Remove Programs
timedate.cpl – Date and Time Properties
desk.cpl – Display Properties
inetcpl.cpl – Internet Properties
joy.cpl – Joystick Properties
main.cpl keboard – Keyboard Properties
main.cpl – Mouse Properties
ncpa.cpl – Network Connections
ncpl.cpl – Network Properties
telephon.cpl – Phone and Modem options
powercfg.cpl – Power Management
intl.cpl – Regional settings
mmsys.cpl sounds – Sound Properties
mmsys.cpl – Sounds and Audio Device Properties
sysdm.cpl – System Properties
nusrmgr.cpl – User settings
firewall.cpl – Firewall Settings (sp2)
wscui.cpl – Security Center (sp2)

Windows Environment Commands

%ALLUSERSPROFILE% – Open the All User’s Profile
%HomeDrive% – Opens your home drive e.g. C:\
%UserProfile% – Opens you User’s Profile
%temp% Opens – temporary file Folder
%systemroot% – Opens Windows folder

Wupdmgr – Takes you to Microsoft Windows Update

General keyboard shortcuts

CTRL+C(Copy)
CTRL+X (Cut)
CTRL+Z (Undo)
DELETE (Delete)
SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin)
CTRL while dragging an item (Copy the selected item)
CTRL+SHIFT while dragging an item (Create a shortcut to the selected item)
F2 key (Rename the selected item)
CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)
CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)
CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)
CTRL+SHIFT with any of the arrow keys (Highlight a block of text)
CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)
SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document)
CTRL+A (Select all)
F3 key (Search for a file or a folder)
ALT+ENTER (View the properties for the selected item)
ALT+F4 (Close the active item, or quit the active program)
ALT+ENTER (Display the properties of the selected object)
ALT+SPACEBAR (Open the shortcut menu for the active window)
CTRL+F4 (Close the active document in programs that enable you to have multiple documents open simultaneously)
ALT+TAB (Switch between the open items)
ALT+ESC (Cycle through items in the order that they had been opened)
F6 key (Cycle through the screen elements in a window or on the desktop)
F4 key (Display the Address bar list in My Computer or Windows Explorer)
SHIFT+F10 (Display the shortcut menu for the selected item)
ALT+SPACEBAR (Display the System menu for the active window)
CTRL+ESC (Display the Start menu)
ALT+Underlined letter in a menu name (Display the corresponding menu)
Underlined letter in a command name on an open menu (Perform the corresponding command)
F10 key (Activate the menu bar in the active program)
RIGHT ARROW (Open the next menu to the right, or open a submenu)
LEFT ARROW (Open the next menu to the left, or close a submenu)
F5 key (Update the active window)
BACKSPACE (View the folder one level up in My Computer or Windows Explorer)
ESC (Cancel the current task)
SHIFT when you insert a CD-ROM into the CD-ROM drive (Prevent the CD-ROM from automatically playing)
CTRL+SHIFT+ESC (Open Task Manager) Dialog box keyboard shortcuts

If you press SHIFT+F8 in extended selection list boxes, you enable extended selection mode. In this mode, you can use an arrow key to move a cursor without changing the selection. You can press CTRL+SPACEBAR or SHIFT+SPACEBAR to adjust the selection. To cancel extended selection mode, press SHIFT+F8 again. Extended selection mode cancels itself when you move the focus to another control.

CTRL+TAB (Move forward through the tabs)
CTRL+SHIFT+TAB (Move backward through the tabs)
TAB (Move forward through the options)
SHIFT+TAB (Move backward through the options)
ALT+Underlined letter (Perform the corresponding command or select the corresponding option)
ENTER (Perform the command for the active option or button)
SPACEBAR (Select or clear the check box if the active option is a check box)
Arrow keys (Select a button if the active option is a group of option buttons)
F1 key (Display Help)
F4 key (Display the items in the active list)
BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)

Microsoft natural keyboard shortcuts

Windows Logo+BREAK (Display the System Properties dialog box)
Windows Logo+D (Display the desktop)
Windows Logo+M (Minimize all of the windows)
Windows Logo+SHIFT+M (Restore the minimized windows)
Windows Logo+E (Open My Computer)
Windows Logo+F (Search for a file or a folder)
CTRL+Windows Logo+F (Search for computers)
Windows Logo+F1 (Display Windows Help)
Windows Logo+ L (Lock the keyboard)
Windows Logo+R (Open the Run dialog box)
Windows Logo+U (Open Utility Manager)

Accessibility keyboard shortcuts

Right SHIFT for eight seconds (Switch FilterKeys either on or off)
Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off)
Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off)
SHIFT five times (Switch the StickyKeys either on or off)
NUM LOCK for five seconds (Switch the ToggleKeys either on or off)
Windows Logo +U (Open Utility Manager)

Windows Explorer keyboard shortcuts

END (Display the bottom of the active window)
HOME (Display the top of the active window)
NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder)
NUM LOCK+Plus sign (+) (Display the contents of the selected folder)
NUM LOCK+Minus sign (-) (Collapse the selected folder)
LEFT ARROW (Collapse the current selection if it is expanded, or select the parent folder)
RIGHT ARROW (Display the current selection if it is collapsed, or select the first subfolder)

Shortcut keys for Character Map

After you double-click a character on the grid of characters, you can move through the grid by using the keyboard shortcuts
RIGHT ARROW (Move to the right or to the beginning of the next line)
LEFT ARROW (Move to the left or to the end of the previous line)
UP ARROW (Move up one row)
DOWN ARROW (Move down one row)
PAGE UP (Move up one screen at a time)
PAGE DOWN (Move down one screen at a time)
HOME (Move to the beginning of the line)
END (Move to the end of the line)
CTRL+HOME (Move to the first character)
CTRL+END (Move to the last character)
SPACEBAR (Switch between Enlarged and Normal mode when a character is selected)

Microsoft Management Console (MMC) main window keyboard shortcuts

• CTRL+O (Open a saved console)
CTRL+N (Open a new console)
CTRL+S (Save the open console)
CTRL+M (Add or remove a console item)
CTRL+W (Open a new window)
F5 key (Update the content of all console windows)
ALT+SPACEBAR (Display the MMC window menu)
ALT+F4 (Close the console) • ALT+A (Display the Action menu)
ALT+V (Display the View menu)
ALT+F (Display the File menu)
ALT+O (Display the Favorites menu)

MMC console window keyboard shortcuts

CTRL+P (Print the current page or active pane)
ALT+Minus sign (-) (Display the window menu for the active console window)
SHIFT+F10 (Display the Action shortcut menu for the selected item)
F1 key (Open the Help topic, if any, for the selected item)
F5 key (Update the content of all console windows)
CTRL+F10 (Maximize the active console window)
CTRL+F5 (Restore the active console window)
ALT+ENTER (Display the Properties dialog box, if any, for the selected item)
F2 key (Rename the selected item)
CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)

Remote desktop connection navigation

CTRL+ALT+END (Open the Microsoft Windows NT Security dialog box)
ALT+PAGE UP (Switch between programs from left to right)
ALT+PAGE DOWN (Switch between programs from right to left)
ALT+INSERT (Cycle through the programs in most recently used order)
ALT+HOME (Display the Start menu)
CTRL+ALT+BREAK (Switch the client computer between a window and a full screen)
ALT+DELETE (Display the Windows menu)
CTRL+ALT+Minus sign (-) (Place a snapshot of the entire client window area on the Terminal server clipboard and provide the same functionality as pressing ALT+PRINT SCREEN on a local computer.)
CTRL+ALT+Plus sign (+) (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.)

Microsoft Internet Explorer navigation

CTRL+B (Open the Organize Favorites dialog box)
CTRL+E (Open the Search bar)
CTRL+F (Start the Find utility)
CTRL+H (Open the History bar)
CTRL+I (Open the Favorites bar)
CTRL+L (Open the Open dialog box)
CTRL+N (Start another instance of the browser with the same Web address)
CTRL+O (Open the Open dialog box, the same as CTRL+L)
CTRL+R (Update the current Web page)
CTRL+ CTRL+P (Open the Print dialog box)
W (Close the current window)

Note Some keyboard shortcuts may not work if StickyKeys is turned on in Accessibility Options, Some of the Terminal Services client shortcuts that are similar to the shortcuts in Remote Desktop Sharing are not available when you use Remote Assistance in Windows XP Home Edition.
Thanks to The New Tech for the original forum posting.
Microsoft Office run commands
If the Microsoft Office is installed you can use following run commands to run its components:

winword – Microsoft Word
excel – Microsoft Excel
powerpnt – Microsoft PowerPoint
msaccess – Microsoft Access
outlook – Microsoft Outlook
ois – Microsoft Picture Manager

New Release PHP 5.4.0

New PHP Version 5.4.0 is planned to be released on February, 2 2012. It is a result of many months of development.

In the PHP Version 5.4.0 many features included. Some features are listed below.

  • Traits
  • Built-in Web server
  • Binary notation for integer values
  • Array short syntax
  • Annotations

Traits

PHP does not support multiple inheritance. This means that unlike languages such as C++, it is not possible to create one class by inheriting the behavior of multiple other classes.

However, PHP implements the support to have classes with multiple interfaces since version 5. This is a simple approach inspired in Java that avoids the ambiguity problems of C++ multiple inheritance implementation.

The problem of using either multiple inheritance or multiple interfaces is that it becomes easy for creating bloated classes that have much more inherited functions than they may really need in practice.

Traits provide a simpler alternative. You can define a trait practically the same way you define a class or an interface with whatever functions you need. Then you use them in a new class you want to have those functions.

Here is an example taken from the original proposal RFC document:

<?php

  trait ezcReflectionReturnInfo {
    function getReturnType() { /*1*/ }
    function getReturnDescription() { /*2*/ }
  }

  class ezcReflectionMethod extends ReflectionMethod {
    use ezcReflectionReturnInfo;
    /* ... */
  }

  class ezcReflectionFunction extends ReflectionFunction {
    use ezcReflectionReturnInfo;
    /* ... */
  }

 ?>

Built-in Web server

Although Apache has been losing popularity in the latest years for more efficient Web servers in use in production environments, it is still very popular among PHP developers that use it to test their applications in their development environments.

However, Apache is still too cumbersome and complicated to configure, especially when you just want to set it up for a simple development environment. Therefore, PHP 5.4 introduces a Web server that comes built in the PHP command line version.

This means that you only need to execute a simple PHP command and you have Web server running ready for you to test your applications without depending on setting Apache or any other external Web server.

Another interesting purpose of this built-in Web server is that you can develop browser based applications that run in the local machine and you only need the base PHP installation for that.

Here is an example command of how to run PHP to work as a Web server.

$ php -S localhost:8000

 Server is listening on localhost:8000... Press CTRL-C to quit.
 [Thu Mar  3 05:42:06 2011] ::1:56258: /
 [Thu Mar  3 05:42:06 2011] ::1:56259: /?=PHPE9568F34-A769-00AA02
 [Thu Mar  3 05:42:06 2011] ::1:56260: /?=PHPE9568F35-A769-00AA04

Binary notation for integer values

When you need to use literal values in your PHP code you can represent them in decimal, hexadecimal or octal. Now in PHP 5.4 you can also represent them in binary.

In octal you would need to prefix the value with a 0. For instance, 010 represents the number 8, not 10 as some may expect. In hexadecimal you would need to prefix the values with 0x, for instance 0x12 represents the number 18. In binary you need to prefix the number with 0b, for instance 0b101 represents the number 5.

Array short syntax

The popularity of JSON made it a common format for exchanging serialized data between code eventually written on different languages.

One basic difference between JSON and PHP literal value format is that arrays are represented by brackets instead the usual array() construct. Some people proposed to add support for a shorter syntax similar to JSON, but the proposal was not approved by PHP core developers.

Annotations

Annotations are a form of adding metadata to your code. The metadata information can be used by those tools for instance to produce additional support code, so you do not have to write such code manually. One common use is to generate PHP code or SQL statements to map data between class objects and database tables.

There were several proposals to implement annotations in PHP, very similar to the way they work in other languages like Java and C#. Those proposals ended up not being accepted or fully implemented to make into PHP 5.4.

Still, there are alternative approaches that consist in separate annotation parser tools that extract annotation metadata from PHP comments.

Jquery set Cookie and Check

In this we set the cookie and then check it available or not. If available then what we want to do next to that.  By this we check the users comes again or not. On the basis of that we have several option to what to show them.

Requirement:

–       Jquery

–       Jquery Cookie Function

Code: 

// global variable to check form hide or show
var opt;
// function that create the cookie on form submission when it is shown
show = function(){
// create the cookie name opt with value show1 and expire after 7 days
opt = jQuery.cookie("opt", "show1", { expire: 7, path: '/' });
}
// function that checks the cookie is set or not
function getCookie(opt) {
// set the opt value to variable
var nameEQ = opt + "=";
// split cookies
var ca = document.cookie.split(';');
// check all cookies one by one
for(var i=0;i < ca.length;i++) {
var c = ca[i];
// check the cookie value is not null
while (c.charAt(0)==' '){
c = c.substring(1,c.length);
// find the cookie with the condition we sets
if (c=='opt=show1'){
// after finding cookie what we want to do we set here, here we get the div and set to null
document.getElementById('WFItem96692').innerHTML="";
// then set the value what we want to show
document.getElementById('WFItem96692').innerHTML="new text";
}
}
// return data
if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length,nameEQ.length + 4);
}
}

Use of Singleton Pattern in PHP

There are many design patterns we use in our Project, one of the most used design patterns is Singleton. Thats save a lot of efforts of us in OOP.

The main purpose of the Singleton pattern is to deliver a single instance of object no matter how many times you instantiate it.  This saves memory consumption by preventing the creation of multiple instances of an object. Thus Singleton pattern is used to improve the performance of our application.

<?php
class SingletonPattern
{
private static $instance;
public function __construct()
{
if (!self::$instance)
{
self::$instance = $this;
echo “New Instance”;
return self::$instance;
}
else
{
echo “Old Instance”;
return self::$instance;
}
}
}
?>

Now, let check how it works on calling…

<?php
$a = new SingletonPattern();
$b = new SingletonPattern();
$c = new SingletonPattern();
$d = new SingletonPattern();
$e = new SingletonPattern();
?>

Output of the above ;

New Instance
Old Instance
Old Instance
Old Instance
Old Instance

Now, we can check that the it recall its instance after first instance of the object.

Collecting all PHP Errors as Exception

If you want to collect all PHP errors (except the FATAL errors) as exception, you can use the following code:

<?php
function exception_handler($severity, $message, $filename, $lineno)
{
throw new ErrorException($message,0,$severity,$filename,$lineno);
}
set_exception_handler(‘exception_handler’);
?>