Code

Code

Get referrer using GA (google analytics script)

ga(function(tracker) {
  console.log(tracker.get('referrer'));
});

라벨:

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;
}

http://stackoverflow.com/questions/6248666/how-to-generate-short-uid-like-ax4j9z-in-js

Hiding the Navigation Bar in Android

View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

https://developer.android.com/training/system-ui/navigation.html#behind


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
        reset()
        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>
</style>


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

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

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>

http://stackoverflow.com/a/26637752/1015731

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

http://stackoverflow.com/questions/588004/is-floating-point-math-broken

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
    }
});

http://stackoverflow.com/questions/3149216/how-to-listen-for-a-webview-finishing-loading-a-url

Handling Orientation Changes on Android Fragment

Fragment.setRetainInstance(true);

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:

http://code.hootsuite.com/orientation-changes-on-android/

jQuerify.js - jQuerify Bookmarklet

jQuerify Bookmarklet


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

http://www.jondev.net/articles/Combining_2_Images_in_Android_using_Canvas

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.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(uri, socketMessageDataFile.getMimeType());

startActivity(intent);



Subscribe to: Posts (Atom)