We are Red Devil !!
Saturday, August 27, 2016
Tuesday, June 21, 2016
Peace of Mind
![]() |
| “It's a good idea always to do something relaxing prior to making an important decision in your life.”
― Paulo Coelho, The Pilgrimage |
Monday, June 22, 2015
Sort the content of select element using JavaScript
While I was working for the solution to the scenario that I had to copy list of location from one multiple select element to another. I had an issue that those location were not sorting alphabetically.After some googling and playing around, I come up with following solution
function sortSelectElement(selElement) {
var tmpAry = new Array();
for (var i=0;i<selElement.options.length;i++) {
tmpAry[i] = new Array();
tmpAry[i][0] = selElement.options[i].text;
tmpAry[i][1] = selElement.options[i].value;
}
tmpAry.sort();
while (selElement.options.length > 0) {
selElement.options[0] = null;
}
for (var i=0;i<tmpAry.length;i++) {
var op = new Option(tmpAry[i][0], tmpAry[i][1]);
selElement.options[i] = op;
}
return;
}
Hope it will helps for someone :)
function sortSelectElement(selElement) {
var tmpAry = new Array();
for (var i=0;i<selElement.options.length;i++) {
tmpAry[i] = new Array();
tmpAry[i][0] = selElement.options[i].text;
tmpAry[i][1] = selElement.options[i].value;
}
tmpAry.sort();
while (selElement.options.length > 0) {
selElement.options[0] = null;
}
for (var i=0;i<tmpAry.length;i++) {
var op = new Option(tmpAry[i][0], tmpAry[i][1]);
selElement.options[i] = op;
}
return;
}
Hope it will helps for someone :)
Sunday, May 31, 2015
Monday, December 1, 2014
Is there a shortcut which invokes the “Login Window…” on MAC ? - NO
I got tired of clicking on "Login Windows..." on my mac when I want to lock my logged user account. I discovered a solution to create a easy shortcut command to solve this problem. If you also want to give it a try, you can :)
- Start Applications » Automator
- Select "Service" for the template of the new Automator workflow
- In the top of the right pane, select "Service receives no input in any application"
- Drag action "Run Shell Script" from the left pane into the workflow on the right pane
- Leave Shell at its default "/bin/bash", and replace the default command
catwith the following, without any line breaks:/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend - Optional: click the Run button to test
- Hit Cmd-S to save. The name you type will be the name in the Services menu. The workflow will be saved in
~/Library/Services.
To assign a keyboard shortcut, in 10.6:
- Open System Preferences » Keyboard » pane Keyboard Shortcuts
- Select "Services" in the left pane
- Scroll down to General in the right pane
- Double-click to the right of the Automator workflow you just created
- Press the keys you want to use, and switch panes to ensure the new shortcut is saved.
For details please click here.
Sunday, September 28, 2014
Memory Leak
As we know Java is the garbage collected language. Programmer do not need to worry about the memory management. But its not true always.
The memory leak can reduced the performance due to the increased garbage collector activity resulting disk paging and even program failure with an OutOfMemoryError.
Consider the following simple implementation of stack,
import java.util.Arrays;
import java.util.EmptyStackException;
/**
*
* @author
*/
public class Stack {
private Object[] elements;
private int size = 0;
private static final int DEFAULT_INITIAL_CAPACITY = 16;
public Stack() {
elements = new Object[DEFAULT_INITIAL_CAPACITY];
}
public void push(Object e) {
ensureCapacity();
elements[size++] = e;
}
public Object pop() {
if (size == 0) {
throw new EmptyStackException();
}
return elements[--size];
}
/**
* Ensure space for at least one more element, roughly doubling the capacity
* each time the array needs to grow.
*/
private void ensureCapacity() {
if (elements.length == size) {
elements = Arrays.copyOf(elements, 2 * size + 1);
}
}
}
Did you spot the memory leak ?
If the stack grows and then shrinks, the objects that were popped off the stack will not be garbage collected, This is because the stack maintain the absolute reference to these objects.
If an object reference is unintentionally retained, not only object excluded from garbage collection, but also many many objects may be prevented from being garbage collected, with potentially large effect on performance.
Solution : null out the reference once they become obsolete.
public Object popCorrected() {
if (size == 0) {
throw new EmptyStackException();
}
Object result = elements[--size];
elements[size] = null; // Eliminate obsolete reference
return result;
}
The memory leak can reduced the performance due to the increased garbage collector activity resulting disk paging and even program failure with an OutOfMemoryError.
import java.util.Arrays;
import java.util.EmptyStackException;
/**
*
* @author
*/
public class Stack {
private Object[] elements;
private int size = 0;
private static final int DEFAULT_INITIAL_CAPACITY = 16;
public Stack() {
elements = new Object[DEFAULT_INITIAL_CAPACITY];
}
public void push(Object e) {
ensureCapacity();
elements[size++] = e;
}
public Object pop() {
if (size == 0) {
throw new EmptyStackException();
}
return elements[--size];
}
/**
* Ensure space for at least one more element, roughly doubling the capacity
* each time the array needs to grow.
*/
private void ensureCapacity() {
if (elements.length == size) {
elements = Arrays.copyOf(elements, 2 * size + 1);
}
}
}
Did you spot the memory leak ?
If the stack grows and then shrinks, the objects that were popped off the stack will not be garbage collected, This is because the stack maintain the absolute reference to these objects.
If an object reference is unintentionally retained, not only object excluded from garbage collection, but also many many objects may be prevented from being garbage collected, with potentially large effect on performance.
Solution : null out the reference once they become obsolete.
public Object popCorrected() {
if (size == 0) {
throw new EmptyStackException();
}
Object result = elements[--size];
elements[size] = null; // Eliminate obsolete reference
return result;
}
whenever a class manages its own memory, the programmer should be alert for memory leaks.
Another common source of memory leaks is caches.
Source: Effective Java 2nd Edition, Chapter 2
Saturday, September 27, 2014
Design Pattern : Builder
When we have so many parameters in constructor. To deal with this problem we have an alternative to use the Builder pattern. We define a static inner class Builder, whose job it is to collect the parameters and then construct the object in one fell swoop
Example:
public class NutritionFacts {
private final int servingSize;
private final int servings;
private final int calories;
private final int fat;
private final int sodium;
private final int carbohydrate;
public static class Builder {
// Required parameters
private final int servingSize;
private final int servings;
// Optional parameters - initialized to default values
private int calories = 0;
private int fat = 0;
private int carbohydrate = 0;
private int sodium = 0;
public Builder(int servingSize, int servings) {
this.servingSize = servingSize;
this.servings = servings;
}
public Builder calories(int val)
{ calories = val; return this; }
public Builder fat(int val)
{ fat = val; return this; }
public Builder carbohydrate(int val)
{ carbohydrate = val; return this; }
public Builder sodium(int val)
{ sodium = val; return this; }
public NutritionFacts build() {
return new NutritionFacts(this);
}
}
private NutritionFacts(Builder builder) {
servingSize = builder.servingSize;
servings = builder.servings;
calories = builder.calories;
fat = builder.fat;
sodium = builder.sodium;
carbohydrate = builder.carbohydrate;
}
}
Note that NutritionFacts is immutable, and that all parameter default values
are in a single location. The builder’s setter methods return the builder itself so
that invocations can be chained. Here’s how the client code looks:
NutritionFacts cocaCola = new NutritionFacts.Builder(240, 8).
calories(100).sodium(35).carbohydrate(27).build();
This client code is easy to write and, more importantly, to read. The Builder pattern
simulates named optional parameters.
In summary, the Builder pattern is a good choice when designing classes
whose constructors or static factories would have more than a handful of
parameters, especially if most of those parameters are optional.
Source : Effective Java 2nd Edition Chapter 2
Thursday, February 21, 2013
jQuery Validiate Custome Rules
Followings are the few custom rule to validate German telephone and zip followed by city.
German telephone:
jQuery.validator.addMethod("checkTelephone", function(value, element) {return this.optional(element) || /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/] {3,20}) ((x|ext|extension)[ ]?[0-9]{1,4})?$/.test(value);
});
zip followed by city:
jQuery.validator.addMethod("checkPlzort", function(value, element) {return this.optional(element) || /^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})([a-zA-Zäöüß \s\d()/\-)]+?)$/.test(value);
});
German telephone:
jQuery.validator.addMethod("checkTelephone", function(value, element) {return this.optional(element) || /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/] {3,20}) ((x|ext|extension)[ ]?[0-9]{1,4})?$/.test(value);
});
zip followed by city:
jQuery.validator.addMethod("checkPlzort", function(value, element) {return this.optional(element) || /^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})([a-zA-Zäöüß \s\d()/\-)]+?)$/.test(value);
});
Friday, January 4, 2013
Replication of local Database to live Database
Recently i was working for one of the Government Office's Intranet based software. I had to develop a module "Sync Database to live". It was only replication (from Localhost to live site).
Mysql has replication feature. As i had little time to implement so i thought understanding of it and implementing into project will take me longer time. Then i developed my own module. Which i m going to describe here.
Firstly i prepared array of tables which are need to be replicated.
e.g : $tables = array('authors','book_authors','publication','books','book_category');
Using PHPExcel, I generated the multi-sheet excel file with all the data from given tables in respective sheet dynamically.
Using cURL, I uploaded excel file to target (live server). Then i had to run a script in live server via cURL which reads the excel file and insert data to respective tables of live database.
$ch = curl_init();
$data = array('file' => "@$filepath");
curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
Sending @ before the filepath makes sure that cURL sends the file as a part of a “multipart/form-data” post. That was what i exactly needed.
Mysql has replication feature. As i had little time to implement so i thought understanding of it and implementing into project will take me longer time. Then i developed my own module. Which i m going to describe here.
Firstly i prepared array of tables which are need to be replicated.
e.g : $tables = array('authors','book_authors','publication','books','book_category');
Using PHPExcel, I generated the multi-sheet excel file with all the data from given tables in respective sheet dynamically.
Using cURL, I uploaded excel file to target (live server). Then i had to run a script in live server via cURL which reads the excel file and insert data to respective tables of live database.
$ch = curl_init();
$data = array('file' => "@$filepath");
curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
Sending @ before the filepath makes sure that cURL sends the file as a part of a “multipart/form-data” post. That was what i exactly needed.
Wednesday, December 29, 2010
IDEA that can change the "YOUTH"
Five points that can change the youth (with the perspective of Information technology):
1)develop a platform, where all youth can participate n can share their problem about making right decision at right time, what their family wants from them and importantly what they wants themself in their life.
2)Individual counceling through a radio program. Program that is dedicated to youth, wher there will be lots of discussion concerning about the how youth can be benifited from education i.e involvement of youth in science and technology....so that they can develop their career in Information and Technology field.
3)personal from IT sector(engineers, software developers, network engineers, professors, system admin) can give a presentation for group of youth or in selected school where they give their presentation on challeenges and future in IT.they can develop interest of student in IT, motivation is the key factor to attract the student in IT sector.they will explore what is the benifit of IT......in their presentation and youth can be attracted.
4)Concept of E- Library in school. Students can know lots of things about Information technology with the use of computer.Indirectly that will help to change in behavoir of student and enthusiasm to know new thing, innovative idea and eager to know new things will develop. "Learning by doing" ultimately youth can be surely attracted in IT field.
5)Make a group of Youth(every youth are having some sorts of problems,ie what is their intrest and what they exactly wants to become in future). Start a discussion about their problems, they will share individual problems in group and will discuss what could be the solution of problems and ofcourse you can be one facilitator to them.
Conclusion:
Its not necessary for every students ( youth ) to go to science and technology field but if most of youth are from science and technology background, it will be easy to develop the nation."Engineers moves the nation ahead". More the engineers, fast will be the development of nation. For this all, there should be political stability and proper policies to utilise educated manpower and technomanagerial personals with in the country.
Wednesday, November 17, 2010
Facebook announces new messaging system
Facebook CEO Mark Zuckerberg Monday announced the creation of a new messaging system that will have seamless messaging, history and a social inbox.
"E-mail is too slow," Zuckerberg said. "It's too formal."
With those comments, Zuckerberg announced the launch of the company's new messgaing service. Users will have the option of getting facebook.com e-mail addresses, but the system will be a suite of messaging services. The key features will be seamless messaging across different media, conversation history and a social inbox.
"This is not an e-mail killer," Zuckerberg said. "It's a messaging system that has e-mail as a part of it.
The new service will have a feature called "social inbox," which allows users to label or sort e-mails by closest friends and associates, then a separate inbox for "others," and one for junk. That, in itself, is not a new feature in most e-mail programs, such as Gmail and Outlook. Another feature will be the ability to bounce e-mail from people who are not on Facebook.
A major point that Facebook stressed was that the new system will aggregate conversations into one thread, incorporating e-mails and other Facebook messaging with wall postings so that a user will have a complete compendium of all messages, regardless of method, in one place.
In answering reporter questions, Facebook says users can link Gmail or other accounts to its new message suite. Users do not have to use a facebook.com address. Zuckerberg called Gmail "a pretty good product." He also said Facebook e-mail will have advertising, similar to what users see on their Facebook pages, but the ads will not be targeted based on the content of the e-mails.
Zuckerberg does not anticipate users will cancel their existing e-mail accounts. He says it is just a way to make messaging simpler and more social.
Facebook says will roll out the new service gradually on an invitation basis over several months.
"E-mail is too slow," Zuckerberg said. "It's too formal."
With those comments, Zuckerberg announced the launch of the company's new messgaing service. Users will have the option of getting facebook.com e-mail addresses, but the system will be a suite of messaging services. The key features will be seamless messaging across different media, conversation history and a social inbox.
"This is not an e-mail killer," Zuckerberg said. "It's a messaging system that has e-mail as a part of it.
The new service will have a feature called "social inbox," which allows users to label or sort e-mails by closest friends and associates, then a separate inbox for "others," and one for junk. That, in itself, is not a new feature in most e-mail programs, such as Gmail and Outlook. Another feature will be the ability to bounce e-mail from people who are not on Facebook.
A major point that Facebook stressed was that the new system will aggregate conversations into one thread, incorporating e-mails and other Facebook messaging with wall postings so that a user will have a complete compendium of all messages, regardless of method, in one place.
In answering reporter questions, Facebook says users can link Gmail or other accounts to its new message suite. Users do not have to use a facebook.com address. Zuckerberg called Gmail "a pretty good product." He also said Facebook e-mail will have advertising, similar to what users see on their Facebook pages, but the ads will not be targeted based on the content of the e-mails.
Zuckerberg does not anticipate users will cancel their existing e-mail accounts. He says it is just a way to make messaging simpler and more social.
Facebook says will roll out the new service gradually on an invitation basis over several months.
Wednesday, November 3, 2010
review : Windows server 2008 R2
Windows Server 2008 R2 builds on the award-winning foundation of Windows Server 2008, expanding existing technology and adding new features to enable IT professionals to increase the reliability and flexibility of their server infrastructures. New virtualization tools, Web resources, management enhancements, and exciting Windows 7 integration help save time, reduce costs, and provide a platform for a dynamic and efficiently managed data center. Powerful tools such as
Internet Information Services (IIS) version 7.5,
updated Server Manager and
Hyper-V platforms and Windows PowerShell version 2.0 combine to give customers greater control, increased efficiency and the ability to react to front-line business needs faster than ever before.
Features :
It offers an updated Web server role, Internet Information Services (IIS) 7.5, and greater support for .NET on Server Core. Design goals for IIS 7.5 concentrated on improvements that enable Web administrators to more easily deploy and manage Web applications that increase both reliability and scalability. Additionally, IIS 7.5 has streamlined management capabilities and provides more ways to customize your Web serving environment. The following improvements to IIS and the Windows Web platform are included in Windows Server 2008 R2:
Internet Information Services (IIS) version 7.5,
updated Server Manager and
Hyper-V platforms and Windows PowerShell version 2.0 combine to give customers greater control, increased efficiency and the ability to react to front-line business needs faster than ever before.
Features :
It offers an updated Web server role, Internet Information Services (IIS) 7.5, and greater support for .NET on Server Core. Design goals for IIS 7.5 concentrated on improvements that enable Web administrators to more easily deploy and manage Web applications that increase both reliability and scalability. Additionally, IIS 7.5 has streamlined management capabilities and provides more ways to customize your Web serving environment. The following improvements to IIS and the Windows Web platform are included in Windows Server 2008 R2:
- Reduced Effort to Administer and Support Web-Based Applications
- Reduced Support and Troubleshooting Effort
- Improved File-Transfer Services
- Ability to Extend Functionality and Features
- Improved .NET Support
- Improved Application Pool Security
- IIS.NET Community Portal
Tuesday, October 5, 2010
US Government to Upgrade to IPv6 by 2012
The US chief information officer announced the Obama administration's
ambitious plans to upgrade the networks and services of all US government
agencies to IPv6 by September 2012.
Internal networks would be expected to be upgraded by September 2014.
Priority will be placed on public-facing web services.
ambitious plans to upgrade the networks and services of all US government
agencies to IPv6 by September 2012.
Internal networks would be expected to be upgraded by September 2014.
Priority will be placed on public-facing web services.
Saturday, September 25, 2010
Beginings...............
Every time i thought of creating own blog, i felt like "kasto alchhi lageko".
I m going to finish my B.E(Computer) degree very soon and i flash back my four years past. Then i decided to create it now so that i can write my JPT thoughts ........lol. Anyway it good practice .......First day in pulchowk engg college.....those Book Bank's BOOK(which i never use,tara hostel samma bokera leuda sarai garho hunthiyo).......frenz .....XAM's Parties ..........everything.
(alchhi lagyo)
see u in next post !!
I m going to finish my B.E(Computer) degree very soon and i flash back my four years past. Then i decided to create it now so that i can write my JPT thoughts ........lol. Anyway it good practice .......First day in pulchowk engg college.....those Book Bank's BOOK(which i never use,tara hostel samma bokera leuda sarai garho hunthiyo).......frenz .....XAM's Parties ..........everything.
(alchhi lagyo)
see u in next post !!
Subscribe to:
Posts (Atom)
