Get referrer using GA (google analytics script)

ga(function(tracker) {


Starting mysql using chkconfig

chkconfig --add mysqld
chkconfig mysqld on

Save password using git (credential save)

git config --global credential.helper store

Scheduled Annotation for JAVA

// second, minute, hour, day, month, weekday
@Scheduled(cron = "*/10 * * * * *")
public void do {}

Short UID using JavaScript

function generateUID() {
    var firstPart = (Math.random() * 46656) | 0;
    var secondPart = (Math.random() * 46656) | 0;
    firstPart = ("000" + firstPart.toString(36)).slice(-3);
    secondPart = ("000" + secondPart.toString(36)).slice(-3);
    return firstPart + secondPart;

Hiding the Navigation Bar in Android

View decorView = getWindow().getDecorView();
              | View.SYSTEM_UI_FLAG_FULLSCREEN;

Shipping Multiple APKs in Android

  1. armeabiv-v7a: Version 7 or higher of the ARM processor. Most Android phones released from 2011-15 are using this.
  2. arm64-v8a: 64-bit ARM processors. Found on new devices, like the Samsung Galaxy S6.
  3. armeabi: Older phones using v5 or v6 of the ARM processor.
  4. x86: Mostly used by tablets, and by emulators.
  5. x86_64: Used by 64-bit tablets.

android {
  // rest of your app's logic
  splits {
    abi {
        enable true
        include 'x86', 'x86_64', 'arm64-v8a', 'armeabi-v7a', 'armeabi'
        universalApk false

Change drawer icon back to back arrow in Android

<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/black</item>

How to use "sec:authorize" for checking multiple Roles?

<sec:authorize access="hasAnyRole('ROLE_A', 'ROLE_B')">

Show dependencies for gradle

./gradlew dependencies

or (for android)

./gradlew app:dependencies

Output sample:

testRuntime - Runtime dependencies for source set 'test'.
+--- org.springframework:spring-webmvc:3.1.3.RELEASE
|    +--- org.springframework:spring-asm:3.1.3.RELEASE
|    +--- org.springframework:spring-beans:3.1.3.RELEASE
|    |    \--- org.springframework:spring-core:3.1.3.RELEASE
|    |         +--- org.springframework:spring-asm:3.1.3.RELEASE
|    |         \--- commons-logging:commons-logging:1.1.1 -> 1.1.3
|    +--- org.springframework:spring-context:3.1.3.RELEASE
|    |    +--- org.springframework:spring-aop:3.1.3.RELEASE

Android statusbar icons to black.

<item name="android:windowLightStatusBar">true</item>

0.1 + 0.2 == 0.3 Is it wrong?

0.1 + 0.2 == 0.3
-> false

0.01 + 0.02 == 0.03
-> true

0.1 + 0.2
-> 0.30000000000000004

Binary floating point math is like this. In most programming languages, it is based on the IEEE 754 standard. JavaScript uses 64-bit floating point representation, which is the same as Java's double. The crux of the problem is that numbers are represented in this format as a whole number times a power of two; rational numbers (such as 0.1, which is 1/10) whose denominator is not a power of two cannot be exactly represented.


Add finish loading listener for WebView on Android

mWebView.setWebViewClient(new WebViewClient() {
   public void onPageFinished(WebView view, String url) {
        // do your stuff here

Handling Orientation Changes on Android Fragment


Calling setRetainInstance(true) on a Fragment is similar to setting the android:configChanges flag on an Activity. It signals to Android that you want to continue using the same instance of the current Fragment, so all of your member variables will remain untouched. If you rotate your device when you have an Activity that is NOT using the configChanges flag and a Fragment that IS being retained, the following lifecycle methods will be called on the Fragment:

jQuerify.js - jQuerify Bookmarklet

jQuerify Bookmarklet

Combining 2 Images in Android using Canvas (Side by Side)

public Bitmap combineImages(Bitmap c, Bitmap s) { // can add a 3rd parameter 'String loc' if you want to save the new image - left some code to do that at the bottom 
    Bitmap cs = null; 
    int width, height = 0; 
    if(c.getWidth() > s.getWidth()) { 
      width = c.getWidth(); 
      height = c.getHeight() + s.getHeight(); 
    } else { 
      width = s.getWidth(); 
      height = c.getHeight() + s.getHeight(); 
    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
    Canvas comboImage = new Canvas(cs); 
    comboImage.drawBitmap(c, 0f, 0f, null); 
    comboImage.drawBitmap(s, 0f, c.getHeight(), null); 
    // this is an extra bit I added, just incase you want to save the new image somewhere and then return the location 
    /*String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png"; 
    OutputStream os = null; 
    try { 
      os = new FileOutputStream(loc + tmpImg); 
      cs.compress(CompressFormat.PNG, 100, os); 
    } catch(IOException e) { 
      Log.e("combineImages", "problem combining images", e); 
    return cs; 

Open a file in another app via using file Uri

Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file);
String mime = getContentResolver().getType(uri);

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, mime);
intent.setDataAndType(uri, socketMessageDataFile.getMimeType());


Subscribe to: Posts (Atom)