Skip to content

Instantly share code, notes, and snippets.

@mstoic
mstoic / Current_Page_URL.php
Created April 18, 2021 16:45
WordPress - Get The Current Page URL
global $wp;
$current_url = home_url(add_query_arg(array(),$wp->request));
@mstoic
mstoic / reverse_a_string_using_string_builder
Created September 1, 2020 19:28
Reverse a String Using StringBuilder
StringBuilder str = new StringBuilder("Hey");
int len = str.length();
for (int i = 0; i < len; i++) {
str.append(str.substring(len - 1 - i, len - i));
}
str.delete(0, len);
System.out.println("string: " + str);
@mstoic
mstoic / reverse_a_string_using_string_class
Last active September 1, 2020 19:43
Reverse a String
String originalString = "This is Mstoic Blog";
String reversedString = "";
for (int i = 1; i <= originalString.length(); i++) {
reversedString += (originalString.charAt(originalString.length()-i));
}
System.out.println("Reversed: " + reversedString);
$('.xenForm').find('fieldset').each(function() {
$(this).find('input[value="delete"]').prop("checked", true);
});
android:fillViewport="true"
@mstoic
mstoic / get_foreground_app
Last active September 27, 2018 11:11
Crashes on devices before Lolipop
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public String getForegroundApp(Context context) {
String currentApp = "NULL";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
try {
Class.forName( "android.app.usage.UsageStatsManager" );
UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
long time = System.currentTimeMillis();
List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000 * 1000, time);
if (appList != null && appList.size() > 0) {
KeyguardManager myKM = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
if( myKM.inKeyguardRestrictedInputMode()) {
// Phone is locked
return;
}
app:backgroundTint="@color/colorMuted"
android:tint="@color/colorBlack"
// See all the settings pages
// https://developer.android.com/reference/android/provider/Settings
try {
context.startActivity(new Intent(Settings.ACTION_FINGERPRINT_ENROLL));
} catch (Exception e) {
e.printStackTrace();
}
// Add Below Code oncreate
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Add below code in activity
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}