Authenticate Using Spring Security
@Override
public boolean authenticate(String username, String password) {
try {
Authentication request = new UsernamePasswordAuthenticationToken(username, password);
Authentication result = authenticationManager.authenticate(request);
SecurityContextHolder.getContext().setAuthentication(result);
} catch (AuthenticationException e) {
//Authentication Exception
}
Unix Directory Structure
/ Root |---root The home directory for the root user |---home Contains the user's home directories | |----ftp Users include many services as listed here | |----httpd | |----samba | |----user1 | |----user2 |---bin Commands needed during bootup that might be needed by normal users |---sbin Like bin but commands are not intended for normal users. Commands run by LINUX. |---proc This filesystem is not on a disk. Exists in the kernels imagination (virtual). | | This directory Holds information about kernel parameters and system configuration. | |----1 A directory with info about process number 1. Each process has a directory below proc. | |---usr Contains all commands, libraries, man pages, games and static files for normal operation. | | | |----bin Almost all user commands. some commands are in /bin or /usr/local/bin. | |----sbin System admin commands not needed on the root filesystem. e.g., most server programs. | | | |----include Header files for the C programming language. Should be below /user/lib for consistency. | | | |----lib Unchanging data files for programs and subsystems | |----local The place for locally installed software and other files. | |----man Manual pages | |----info Info documents | |----doc Documentation for various packages | |----tmp | |----X11R6 The X windows system files. There is a directory similar to usr below this directory. | | | |----X386 Like X11R6 but for X11 release 5 |---boot Files used by the bootstrap loader, LILO. Kernel images are often kept here. |---lib Shared libraries needed by the programs on the root filesystem | |----modules Loadable kernel modules, especially those needed to boot the system after disasters. | |---dev Device files for devices such as disk drives, serial ports, etc. |---etc Configuration files specific to the machine. | |----skel When a home directory is created it is initialized with files from this directory | |----sysconfig Files that configure the linux system for networking, keyboard, time, and more. |---var Contains files that change for mail, news, printers log files, man pages, temp files | |----file | |----lib Files that change while the system is running normally | |----local Variable data for programs installed in /usr/local. | |----lock Lock files. Used by a program to indicate it is using a particular device or file | |----log Log files from programs such as login and syslog which logs all logins, logouts, | | and other system messages. | |----run Files that contain information about the system that is valid until the system is next booted | | | |----spool Directories for mail, printer spools, news and other spooled work. | |----tmp Temporary files that are large or need to exist for longer than they should in /tmp. | | | |----catman A cache for man pages that are formatted on demand |---mnt Mount points for temporary mounts by the system administrator. |---tmp Temporary files. Programs running after bootup should use /var/tmp.
File Transfers in UNIX
Connect to a remote machine thru ssh:
$ ssh username@hostname
Download remote file using rsync:
$ rsync -v -e ssh username@hostname:~/path_to_file.txt /destination_folder
Upload file from a local computer to a remote server:
$ rsync -v -e ssh /path_to_file.txt username@hostname:~/destination_folder
Download remote folder using rsync:
$ rsync -r -v -e ssh username@hostname:~/path_to_folder /destination_folder
Synchronize a local directory with a remote directory:
$ rsync -r -a -v -e “ssh -l username” –delete hostname:/remote_dir/ /local_dir
Synchronize a remote directory with a local directory:
$ rsync -r -a -v -e “ssh -l username” –delete /local_dir hostname:/remote_dir
Change the default select list(jQuery)
$("select#country option[selected]").removeAttr("selected");
$("select#country option[value='INDIA']").attr("selected", "selected");
OR
setDefaultForDropDown("country", "newDefaultValue");
function setDefaultForDropDown(objId, defaultText){
var objElement=document.getElementById(objId);
for(i=0;i<objElement.length;i++){
if(defaultText == objElement.options[i].text){
objElement.selectedIndex = i;
break;
}else{
objElement.selectedIndex = 0;
}
}
}
Attach submit events to forms on enter keypress(jQuery)
$(function(){
$('input').keydown(function(e){
if (e.keyCode == 13) {
$(this).parents('form').submit();
return false;
}
});
});
Round Off to decimal places
public String roundOff(String s, int decimalPlaces){
if(s == null || s.trim().length() == 0 ||
"0.00".equalsIgnoreCase(s) || "0".equalsIgnoreCase(s)
|| "-0.00".equalsIgnoreCase(s)
|| "-00.0".equalsIgnoreCase(s)
|| "-00.00".equalsIgnoreCase(s)
|| "-0".equalsIgnoreCase(s)
|| "-0.0".equalsIgnoreCase(s)){
return "0.00";
}
double d = 0.00;
int ind = s.indexOf('.');
if (ind > 0){
String dec = s.substring(ind);
if(dec.length() == 1){
s = s.concat("00");
return s ;
}
if(dec.length() == 2){
s = s.concat("0");
return s ;
}
if(dec.length() == 3){
return s ;
}
}
if(ind == -1){
return s.concat(".00");
}
try{
d = Double.parseDouble(s);
BigDecimal bd = new BigDecimal(d);
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
d = bd.doubleValue();
return String.valueOf(d);
}
catch(java.lang.NumberFormatException nfe){
return s.substring(0,ind);
}
}
Ubuntu – Connect Apple Time Capsule
Steps to connect Apple Time Capsule to UBUNTU(Hardy Heron)
1. Client Side Software – Install smbfs and smbclient
2. Make a Mount Point -
cd /media
sudo mkdir capsule
3. Interactive Mount Statement -
sudo mount.cifs //windowsShare/“TimeCapsuleName” /media/capsule/ -o pass=password
i. the windowsShare is the IP that you assign to the Time Capsule using your Apple AirPort Utility on a windows/mac machine,
ii. The ‘TimeCapsuleName’ is the name enclosed in double quotes is the name assigned to your Time Capsule when it it set up on the Windows/Mac.
iii. /media/capsule is the name of the mount point that you selected,
iv. password is replaced with whatever password you elected to use during the Airport configuration.
Ubuntu – Restore Panels
Command Line
$ gconftool-2 –shutdown
$ rm -rf ~/.gconf/apps/panel
$ pkill gnome-panel
Ubuntu Firefox – Font Smoothening
Step 1: Open a new window or tab and paste this into the address bar – about-config
Step 2 : create/set gfx.use_text_smoothing_settin to true
Ubuntu – Install Adobe Air
- Download the file wget http://download.macromedia.com/pub/labs/air/linux/adobeair_linux_a1_033108.bin
- The name of the file is adobeair_linux_a1_033108.bin
- Save the file in the Home folder (Places > Home Folder)
- Run this command:
chmod +x adobeair_linux_a1_033108.bin - Now run this command:
sudo ./adobeair_linux_a1_033108.bin