Warning: potential spoilers may be written in this post. In my previous posts, the common topic was Android app development. But this post is going to be about androids (robots) in the anime Plastic Memories. 🙂 This anime features androids called “Giftia”, and they look and move exactly like humans — they can even get […]
CSS / JavaScript: Twitter Bootstrap center modal vertically on mobile web view
I’ve been working with modal boxes using Twitter Bootstrap. And the page I’m working on needs to be viewed in mobile devices. The modal looks nice and centered when viewed on desktop, but when run in mobile web browsers, it’s aligned to the top. Someone on StackOverflow suggested the use of a helper div plus […]
JavaScript: Get current function name
getCallingFunctionName() is the important function here.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function getCallingFunctionName() { var re = /function (.*?)\(/ var s = getFunctionName.caller.toString(); var m = re.exec( s ) return m[1]; } function myCurrentFunction(){ var func_name = getCallingFunctionName(); alert(func_name); //displays "myCurrentFunction" } myCurrentFunction(); |
Source: Can I get the name of the currently running function in JavaScript?
Android: Switch into another activity
To switch into another activity, the method we use is startActivity(). This is what starts another Android activity:
|
1 2 |
Intent i = new Intent(this, NameOfActivity.class); startActivity(i); |
Replace NameOfActivity with the name of any activity you’d like to switch into.
Android: Basic WebView Tutorial
A WebView lets you pull a web page and display it in your Android app. It doesn’t take long to implement an Android WebView. Read on. I’ll show you how. AndroidManifest.xml First, open your manifest file to add this permission for INTERNET:
|
1 |
<uses-permission android:name="android.permission.INTERNET" /> |
The web page won’t be loaded into your app without this permission. […]
PHP dynamic variable names tutorial
I think it’s very convenient for us developers, being able to name our variables dynamically. I’ll show you how to do it in PHP. 🙂 For example, we have variable $foo with “bar” as value like this:
|
1 2 |
<?php $foo = "bar"; |
If we want to create a variable named based on the “value” of variable $foo, this is […]
PHP: get full URL of current page with GET params or without
The following string variable’s value will get the full URL of the current page, including GET arguments/params, if present.
|
1 2 3 4 5 6 |
<?php $full_current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; echo $full_current_url; ?> |
To get the full URL of current page but WITHOUT the GET args/params, do this instead:
|
1 2 3 4 5 6 |
<?php $full_current_url = "http://" . strtok($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], "?"); echo $full_current_url; ?> |
The strtok function will return only the part of the URL string up to the character before question […]
PHP: avoid backslash on json_encode
Hey! 🙂 If you are encoding your Arrays to JSON in PHP using json_encode() and the function adds backslash before your slashes, I’m gonna show you a quick fix. This is my original code:
|
1 2 3 4 5 6 |
<?php $arr = array(); $arr['success'] = true; $arr['message'] = "Please enter email/phone number."; echo json_encode($arr); ?> |
And the result is: {“success”:true,”message”:”Please enter email\/phone number.”} See the added backslash before the slash? Ugly, right? To avoid that, […]
Lazada owes me money. Their customer service people disregard my requests for assistance.
Think twice before buying anything from Lazada. They can send you the wrong item, have you return the wrong item with a promise of refund, give you no refund, and never get back to you again even when you already paid! Long story short: I purchased an item last year (already paid) and Lazada sent […]
Android NetworkOnMainThreadException at StrictMode fix (with deprecated methods used)
A JSON Parser developed by some members of the Android dev team. But a few weeks after completion of the parser, several methods became deprecated. And when we use that parser, we get errors. Part of the stack trace is as follows:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[...] E/AndroidRuntime: Caused by: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1148) at java.net.InetAddress.lookupHostByName(InetAddress.java:405) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:251) at java.net.InetAddress.getAllByName(InetAddress.java:229) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) [...] |
Not sure if the NetworkOnMainThreadException is being thrown because of the deprecated […]