Skip to content

Instantly share code, notes, and snippets.

View shazron's full-sized avatar
😆

Shazron Abdullah shazron

😆
View GitHub Profile
@shazron
shazron / gist:2238079
Created March 29, 2012 14:43
PhoneGap 1.4.1 hack to load external url - override in MainViewController.m
// 0. Override these in your MainViewController.m
// 1. your .startPage is http://www.google.com for example, set in your AppDelegate.m
// 2. don't forget to add that url in your whitelist
static BOOL isExternalUrlHack = NO;
- (NSString*) pathForResource:(NSString*)resourcepath;
{
if ([self.startPage isEqualToString:resourcepath] && [self.startPage hasPrefix:@"http://"]) {
isExternalUrlHack = YES;
// return non-nil so it doesn't fail
@shazron
shazron / gist:2572545
Created May 2, 2012 00:08
Cordova - testing events (manual tests)
var dm = {};
function msg_delay(e, m)
{
if (!m) { m = e; }
dm[e] = m;
}
function msg(m, d)
{
@shazron
shazron / gist:2876989
Created June 5, 2012 18:59
test geolocation.js for CB-866
function testOld(p) {
var result = p.timestamp || new Date();
console.log("\told: " + result);
}
function testNew(p) {
var result = (p.timestamp === undefined ? new Date() : ((p.timestamp instanceof Date) ? p.timestamp : new Date(p.timestamp)));
console.log("\tnew: " + result);
}
@shazron
shazron / gist:2957061
Created June 19, 2012 23:05
Test navigator.network.connection.type
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta charset="utf-8">
<!-- iPad/iPhone specific css below, add after your main css >
@shazron
shazron / com.apple.MobileBackup.js
Created August 3, 2012 02:49
setting com.apple.MobileBackup for Cordova
document.addEventListener("deviceready", onDeviceReady,false);
function setFolderMetadata(localFileSystem, subFolder, metadataKey, metadataValue)
{
var onSetMetadataWin = function() {
console.log("success setting metadata")
}
var onSetMetadataFail = function() {
console.log("error setting metadata")
}
@shazron
shazron / UIWebView WebKit Bugs
Last active October 8, 2015 06:20
Unresolved UIWebView WebKit bugs
Fundamentally, this is a WebKit bug that cannot be worked around currently (it does not release memory of images that a not used anymore). I did extensive measurements by loading huge images in a previous project, and it consistently crashes because of this bug.
I believe it has been reported to the WebKit project, with no resolution:
https://bugs.webkit.org/show_bug.cgi?id=31253
https://bugs.webkit.org/show_bug.cgi?id=39628
Usually, setting the image src to null I think would flag the gc to recycle the memory, but I don't think it will work because of this bug.
Others have the same problem, from the Apple Dev Forums (login needed):
https://devforums.apple.com/search.jspa?resultTypes=MESSAGE&q=UIWebView+memory&peopleEnabled=true&start=1&dateRange=all
@shazron
shazron / check_apache_jira.sh
Created August 12, 2012 14:07
Check Apache Jira at a 5 minute interval
while :; do curl https://issues.apache.org/jira 2>/dev/null | (grep "Maintenance in progress" || say "The Apache Jeera Site is back online.") | grep -v "<h1>Maintenance in progress</h1>"; sleep 300; done
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width;" />
<title>Hello World</title>
<script type="text/javascript" src="cordova-2.1.0rc1.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, true);
@shazron
shazron / testinappbrowser.html
Created November 20, 2012 22:04
Testing InAppBrowser for Cordova 2.3.0
<script type="text/javascript">
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str){
return this.slice(0, str.length) == str;
};
}
function launchUrl() {
try {
@shazron
shazron / gist:4477622
Created January 7, 2013 19:20
OnDeviceReady
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready to be used!
//
function onDeviceReady() {
// do stuff here
var exec = cordova.require('cordova/exec');
exec.setJsToNativeBridgeMode(exec.jsToNativeModes.IFRAME_NAV);
}