WKWebView Example

Reference:
https://developer.apple.com/reference/webkit/wkwebview

Sample Code:

import UIKit
import WebKit

class ViewController: UIViewController , WKNavigationDelegate {

var webView : WKWebView!

override func viewDidLoad() {
  super.viewDidLoad()

  let adreq = "https://g.adspeed.net/ad.php?do=html&zid=xxxx"
  let url = NSURL(string: adreq)
  let request = NSURLRequest(URL: url!)

  webView = WKWebView(frame: self.view.frame)
  webView.navigationDelegate = self
  webView.loadRequest(request)

  self.view.addSubview(webView)
  self.view.sendSubviewToBack(webView)
}

override func didReceiveMemoryWarning() {
  super.didReceiveMemoryWarning()
}

// WKNavigationDelegate

func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
  print(error.localizedDescription)
}
func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
  print("Loading")
}
func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
  print("Loaded")
}

}

Optimization with foreach() an empty array

<?php
$vResult = array();
$vAry = array(‘abc’);
$vLimit = 10000000;

$vStart = microtime(true);
for ($i=1;$i<$vLimit; $i++) {
foreach ($vAry as $a) {}
} // rof
$vResult[] = “NoEmptyCheck= “.(microtime(true)-$vStart);

$vStart = microtime(true);
for ($i=1;$i<$vLimit; $i++) {
if (!empty($vAry)) {
foreach ($vAry as $a) {}
}
} // rof
$vResult[] = “WithEmptyCheck= “.(microtime(true)-$vStart);

echo implode(“\n”,$vResult).”\n”;

/* Result

For an often-non-empty array scenario:
NoEmptyCheck= 2.10900402069
WithEmptyCheck= 2.59749412537

For an often-empty array scenario:
– NoEmptyCheck= 1.08695101738
– WithEmptyCheck= 1.01621007919

*/

?>

Optimization with in_array()

Ever wonder with many in_array() checks, you can speed it up depending on your scenario. In my case, 99% it’s empty so it’s better with an empty() check

<?php
$vResult = array();
$vAry = array();
$vLimit = 10000000;

$vStart = microtime(true);
for ($i=1;$i<$vLimit; $i++) {
if (in_array(123,$vAry)) {
}
} // rof
$vResult[] = “NoEmptyCheck= “.(microtime(true)-$vStart);

$vStart = microtime(true);
for ($i=1;$i<$vLimit; $i++) {
if (!empty($vAry) && in_array(123,$vAry)) {
}
} // rof
$vResult[] = “WithEmptyCheck= “.(microtime(true)-$vStart);

echo implode(“\n”,$vResult).”\n”;

/* Result

For an often-non-empty array scenario:
– NoEmptyCheck= 3.76290512085
– WithEmptyCheck= 4.59545087814

For an often-empty array scenario:
– NoEmptyCheck= 3.46415710449
– WithEmptyCheck= 1.08467411995

*/

?>

Planter Clearance @ Lowe’s

Got a bunch of outdoor plastic planters on sales at Lowes.com: 9x 22″ red $4, colorful 21″ ones for $5, some cilantro color for $3.11.

Garden Treasures 11.42-in H x 14.61-in W x 14.61-in D Green Brushed Indoor/Outdoor Planter $3.75
Item #: 485048 | Model #: P13011511241CG

Garden Treasures 14.45-in H x 17.2-in W x 17.2-in D Blue Brushed Indoor/Outdoor Planter $5
Item #: 485043 | Model #: P13011811242B

14-in H x 16-in W x 16-in D Navy Indoor/Outdoor Planter $2.49
Item #: 555919 | Model #: SN1606DB
14-in H x 16-in W x 16-in D Emerald Indoor/Outdoor Planter $2.49
Item #: 555921 | Model #: SN1606ED

10.5-in H x 12-in W x 12-in D Red Indoor/Outdoor Planter $1.49
Item #: 555907 | Model #: SN1212RD

10.5-in H x 12-in W x 12-in D Navy Indoor/Outdoor Planter $0.5
Item #: 555911 | Model #: SN1212DB

10.5-in H x 12-in W x 12-in D Emerald Indoor/Outdoor Planter $0.5
Item #: 555913 | Model #: SN1212ED

Some future predictions

WhatsApp sold for 19B! SMS has changed. Communication has changed. Everything is coming back to data and telcos only has Internet/data plan to charge. Before they have voice (long distance, international), text, data. Now it’s only data that matters.

I see these as hot: Data Compression and Caching/Optimization as they become more and more important to reduce the bandwidth while delivering more. Serve more with less.

HDD to SSD and Windows 8.1

Couple issues
– Acronis True Image HD shipped with Crucial M500 does not work with Windows 8 and GPT partitions. It will not see the HDD and therefore cannot clone it. Need to use a newer version, like Acronis True Image 2014 Premium
– ATI/AMD Catalyst 7730 driver crashes in Windows 8.1 so when it sleeps and wakes up, it will crash and do a hard reboot. Solution: download the latest “beta” driver from ATI/AMD

– Working drivers: ATI/AMD graphic driver v 13.250.18.0 (11/7/2013) and Intel Wifi v 15.10.3.2 (8/22/2013)

LVS, director and SSL cipher

Some odd behavior, handshake with a specific cipher passed with the director but not when handshake directly with a realserver.

openssl s_client -connect VIP:443 -cipher EDH-RSA-DES-CBC-SHA
openssl s_client -connect VIP:443 -cipher DES
=> Connected

openssl s_client -connect RIP:443 -cipher EDH-RSA-DES-CBC-SHA
openssl s_client -connect RIP:443 -cipher DES
=> No connection

Asus Router – Port Forwarding

Caused me some grief for its lack of notification in the UI. I enabled uPnP on the IP camera and it showed up in the port forwarding log but it could not be accessed. Port is open. It turned out that I need to also explicitly enable Port Forwarding (and leave the it other settings empty). It’s good for security but at least it should have a log to show why it’s not working properly.

Gravity drip irrigation

I’ve been setting up a system of cheap drip irrigation for a remote location. Here are the facts and criteria

  1. Remote, no electricity, off-grid
  2. Water from well, well pump run only by generator
  3. Multiple trees
  4. Drip time before refilling (about one per week)
  5. Hot summer (80-100F), wet mild winter
  6. Windy site, full sun, no shade

Here is the setup so far:

  1. 1/4 tubing
  2. 1/4 tubing w/ 1/2GPH emitters at 6″/12″ spacing
  3. 1/4 fittings (tee, connector)
  4. 1/2 tubing
  5. 1/2 fittings (tee, connector, cap)
  6. mini sprinklers
  7. 1/2 GPH PC/non-PC emitters
  8. Trash cans (32G), many, cheap at OSH $10/each, this acts as the rain barrel, container
  9. 8x8x16 Concrete blocks ($1.48=>$1.54 at HomeDepot)

Basic steps for a single emitter

  1. Drill trash can to connect out to 1/4 pipe with valve
  2. Connect 1/4 tubing with 1/2GPH emitter at the end
  3. Place water container on top of concrete blocks to create pressure
  4. Place emitter at base of tree

Other setups:

  1. Single tree, single barrel
  2. Single barrel, several emitters

Problems encounters:

  1. Run out of water from a single trash can too quickly
  2. Time to manually water and refill containers

Google Drive, XAMPP, MacBook

  1. Rename “Google Drive” to one without space. Example: GoogleDrive to avoid issues
  2. Move app to that folder: /Users/xxx/GoogleDrive/htdocs/MyApp
  3. Edit XAMPP etc/httpd/extra/httpd-vhost.conf:
    <VirtualHost *:80>
    DocumentRoot “/Applications/XAMPP/xamppfiles/htdocs”
    ServerName localhost
    </VirtualHost>

    <VirtualHost *:80>
    DocumentRoot “/Users/xxx/GoogleDrive/htdocs/MyApp1/webroot”
    ServerName dev.app1
    </VirtualHost>

    <VirtualHost *:80>
    DocumentRoot “/Users/xxx/GoogleDrive/htdocs/MyApp2/webroot”
    ServerName dev.app2
    </VirtualHost>

  4.  Map custom domain to localhost in /etc/hosts:
    127.0.0.1 dev.app1
    127.0.0.1 dev.app2