Skip to content

Instantly share code, notes, and snippets.

View ryantbd's full-sized avatar
🌐

Ryan ryantbd

🌐
View GitHub Profile
@ryantbd
ryantbd / react-native-gitignore
Created April 4, 2015 07:54
react-native-gitignore
# Most part of this file is created by https://www.gitignore.io
### Node ###
# Logs
logs
*.log
# Runtime data
pids
*.pid
@ryantbd
ryantbd / weinre-debug
Last active August 29, 2015 13:58
Add weinre debug as the first child of <body>
;(function(e) {
e.setAttribute("src", location.protocol + "//" + location.hostname + ":2014/target/target-script-min.js#dev");
document.getElementsByTagName("body")[0].appendChild(e);
})(document.createElement("script"));
@ryantbd
ryantbd / sub-ch-string
Last active August 29, 2015 13:57
Javascript substr() optimized for Chinese Characters.
String.prototype.strLen = function() {
var len = 0,
offset;
for (var i = 0, tmp = this.length; i < tmp; i++) {
offset = (this.isCHS(i)) ? 2 : 1;
len += offset;
}
return len;
};
@ryantbd
ryantbd / tab-control
Last active August 29, 2015 13:57
Simple function to monitor tab visibility, do something while current tab is active / hidden.
/**
* Able to monitor tab visibility, do something while current tab is active / hidden.
* Works also on mobile browsers
* @return {[type]} [description]
*/
var TabControl = {
tabVisibilityChanged: function () {
if (this.tabIsHidden()) {
// tab is hidden
} else {