শনিবার, ১১ নভেম্বর, ২০১৭

Best example of Singleton

class User {
    private static final User INSTANCE;
    private User() {}
    public static User getInstance() {
        synchronized(User.INSTANCE) {
            if (User.INSTANCE == null) {
                User.INSTANCE = new User();
            }
        }
        return User.INSTANCE;
    }
    public String getName() {
        // return user's name
    }

রবিবার, ৩০ আগস্ট, ২০১৫

Spring Data JPA

http://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-creating-database-queries-from-method-names/

সোমবার, ২ মার্চ, ২০১৫

Difference between loading context via DispatcherServlet and ContextLoaderListener



In Spring Web Applications, there are two types of container.

  1. Application Context : Initialized by contextloaderlistener or ContextLoaderServlet and defined in web.xml. middle-tier transactional services, data access objects, or other objects that you might want to use (and re-use) across the application. There will be one application context per application.
  2. Web Application Context: child context of the application context. web- related components such as controllers and view resolvers.

    source: http://syntx.io/difference-between-loading-context-via-dispatcherservlet-and-contextloaderlistener/

বৃহস্পতিবার, ৩ জুলাই, ২০১৪

Java: Check if enum contains a given string?



public class EnumTest {

    public static > boolean contains(Class _enumClass, String value) {
        try {
            return EnumSet.allOf(_enumClass).contains(Enum.valueOf(_enumClass, value));
        } catch (Exception e) {
            return false;
        }
    }

    public static void main(String[] args) {
        for (String value : new String[]{"Y", "a3", null}) {
            System.out.println(contains(YesNo.class, value));
        }

    }
}




public enum YesNo {

    Y("Yes"),
    N("No");

    private String label;

    YesNo(String label) {
        this.label = label;
    }

    public String getLabel() {
        return label;
    }
}


source: http://stackoverflow.com/questions/4936819/java-check-if-enum-contains-a-given-string

সোমবার, ১৭ ফেব্রুয়ারী, ২০১৪

Connecting your Android phone or tablet to Ubuntu with MTPFS

Connecting your Android phone or tablet to Ubuntu with MTPFS

  1. Setup
    First up, install the necessary tools with sudo apt-get install mtp-tools mtpfs
    Connect your Galaxy Nexus to your computer. On your phone, open up the notification drawer, and click on "USB Connection type". Make sure that MTP is selected.
    image showing Android USB connection settings
    Then, run these commands:
    mtp-detect | grep idVendor
    mtp-detect | grep idProduct
    
    You shall get an output like this: enter image description here
    Now, run these commands:
    gksu gedit /etc/udev/rules.d/51-android.rules
    
    A Gedit window should open up. Type this text in it, all in a single line:
    SUBSYSTEM=="usb", ATTR{idVendor}=="VENDORID", ATTR{idProduct}=="PRODUCTID", MODE="0666"
    
    Replace VENDORID with the idVendor you had noted down earlier. Similarly, replace PRODUCTID with the idProduct you had noted down. In my case, they were 04e8 and 685c respectively, but they might have been different for you.
    Save and close the file. Then, disconnect your phone and run these commands:
    sudo service udev restart
    sudo mkdir /media/GalaxyNexus
    sudo chmod a+rwx /media/GalaxyNexus
    sudo adduser $USER fuse
    
    $USER is a default shell variable and should be the user you want to add (usually yourself). Now, run this command:
    gksu gedit /etc/fuse.conf
    
    In the Gedit window, remove the # at the beginning of the last line (the one that begins with #user_allow_other) like this:
    enter image description here
    You're almost done! Now, restart your computer, and then run these three commands:
    echo "alias android-connect=\"mtpfs -o allow_other /media/GalaxyNexus\"" >> ~/.bashrc
    echo "alias android-disconnect=\"fusermount -u /media/GalaxyNexus\"" >> ~/.bashrc
    source ~/.bashrc
    
  2. Usage
    Connect your phone, make sure your phone is using MTP and run android-connect.
    Voila! You can now browse your Android phone contents using Nautilus. Just fire up the file manager, and then in the side bar click GalaxyNexus to browse your phone contents just like you would do with a USB stick. You can also add, remove and modify files just like a normal file system.
    screenshot of nautilus displaying phone contents
    To safely remove the phone, just run android-disconnect.
  3. Conclusion
    From now onward, you just need to run android-connect to mount your phone and then android-disconnect to safely remove your phone. Everything else should be handled automatically. I tried many ways of getting the mount and unmount to happen automatically on cable connect, but this was the best solution I could come up with.
    These two commands won't require root permissions to run. All users who are members of the fuse user group should be able to run these commands without root access.
    That's it! You've successfully connected your Ice Cream Sandwich phone to your Ubuntu computer. The process may be long for a newbie, but I’m sure someone will come around and make a GUI for all of this so that everything happens smoothly. :)


    http://askubuntu.com/questions/87667/getting-mtp-enabled-devices-to-work-with-ubuntu/308366#308366

সোমবার, ২০ জানুয়ারী, ২০১৪