Internet protocol joke of the day

by Joey deVilla on August 5, 2014

i don't always tell udp jokes

Thanks to Joe Smith for pointing me to the original, which I spruced up.

{ 0 comments }

stealth mode activated

Seriously, the right to be forgotten is a silly, unenforceable concept.

{ 0 comments }

legal books

Creative Commons image by Thomas Eagle. Click the photo to see the source.

A preeminent U.S. law firm with over 1,000 employees and an inventory of over 2,000 mobile devices was facing a number of costly problems:

  • Hundreds of zero-use devices that were still being paid for
  • Unchecked fees arising from overages
  • Mixing of personal and business mobile expenses leading to accounting woes
  • Skyrocketing mobile costs that weren’t being measured or managed

The firm needed to bring their wireless devices and spending under control, and did so with GSG’s help. Using GSGCloud, we were able to perform an audit of their mobile assets, services, and costs, and set into motion a plan to bring them under control.

download pdf

Download our case study [1.1MB PDF] to find out how we brought them an annualized savings of $511,000 and complete visibility into their wireless spending and allocation of costs.

this article also appears in the GSG blog

{ 0 comments }

evil monkey pointing at swift code

What happens when you mark operator overload definitions as private?

swift kickWhile I was translating the code in the RayWenderlich.com article Sprite Kit Tutorial for Beginners from its original Objective-C to Swift, I got to the point where he provides some routines to do vector math on CGPoints. These are “standalone” utility functions and aren’t methods inside any class.

The first three functions are for vector arithmetic:

  • Adding two vectors together: (x1, y1) + (x2, y2) = (x1 + x2, y1 + y2)
  • Subtracting on vector from another: (x1, y1) - (x2, y2) = (x1 - x2, y1 - y2)
  • Multiplying a vector by a scalar: (x, y) * k = (k * x, k * y)

Here’s his original code, written in Objective-C:

// Objective-C

static inline CGPoint rwAdd(CGPoint a, CGPoint b) {
    return CGPointMake(a.x + b.x, a.y + b.y);
}
 
static inline CGPoint rwSub(CGPoint a, CGPoint b) {
    return CGPointMake(a.x - b.x, a.y - b.y);
}

static inline CGPoint rwMult(CGPoint a, float b) {
    return CGPointMake(a.x * b, a.y * b);
}

I’ve always found methods like add(firstThing, secondThing) a little clunky-looking; I’d much rather write it as firstThing + secondThing. Since Swift supports operator overloading (Objective-C doesn’t), I decided to implemented the rwAdd(), rwSub(), and rwMult() functions as overloads of the +, -, and * operators. Here’s my equivalent Swift code:

// Swift

// Vector addition
private func + (left: CGPoint, right: CGPoint) -> CGPoint {
  return CGPoint(x: left.x + right.x, y: left.y + right.y)
}

// Vector subtraction
private func - (left: CGPoint, right: CGPoint) -> CGPoint {
  return CGPoint(x: left.x - right.x, y: left.y - right.y)
}

// Vector * scalar
private func * (point: CGPoint, factor: CGFloat) -> CGPoint {
  return CGPoint(x: point.x * factor, y:point.y * factor)
}

Note that I added a private access modifier to each of the functions above. As I pointed out in my last Swift article, Swift’s access modifiers are based on files and modules, not the class hierarchy. In Swift, any entity marked private is visible and accessible within its own file, and invisible and inaccessible from outside its own file. I wanted to see what would happen to operator overloads.

Here’s what I found:

Operator overloads marked private are available within the file where they’re defined, and are not available outside that file. Outside the file where the private operator overloads were defined, any attempt to use them results in an error.

A little testing confirmed that I could add and subtract CGPoints and multiply them by scalars using the + operation from inside the same file, but couldn’t do so from inside in other files.

What happens when you mark extensions as private?

The next couple of functions that were in Sprite Kit Tutorial for Beginners were for getting and normalizing the length of a vector. Here’s the original Objective-C code:

// Objective-C

static inline float rwLength(CGPoint a) {
    return sqrtf(a.x * a.x + a.y * a.y);
}
 
// Makes a vector have a length of 1
static inline CGPoint rwNormalize(CGPoint a) {
    float length = rwLength(a);
    return CGPointMake(a.x / length, a.y / length);
}

Swift supports the addition of functionality to types by means of extensions. I thought that implementing these functions as computed properties of CGPoint in an extension would make for more elegant code — I’d rather write vector.length and vector.normalized than rwLength(vector) and rwNormalize(vector). Here’s what I wrote:

// Swift

private extension CGPoint {
  // Get the length (a.k.a. magnitude) of the vector
  var length: CGFloat { return sqrt(self.x * self.x + self.y * self.y) }
  
  // Normalize the vector (preserve its direction, but change its magnitude to 1)
  var normalized: CGPoint { return CGPoint(x: self.x / self.length, y: self.y / self.length) }
}

Note that I marked the entire extension as private. How would that affect their visibility inside and outside the file where the extension was defined?

The members of extensions marked private are available within the file where they’re defined, and are not available outside that file. Outside the file where the private extension members were defined, any attempt to use them results in an error, and auto-complete wouldn’t even list them.

Once again, testing confirmed that I could normalize and get the length of vectors represented by CGPoints from inside the same file, but couldn’t do so from inside in other files.

What happens when you mark “monkeypatches” as private?

Marking overrides and extensions as private led me to wonder what would happen if I marked a “monkeypatch” as private.

Monkeypatching is a term that’s used in the Python and Ruby developer communities, and it means dynamically replacing an existing class method with one of your own. It’s takes some effort to do in Objective-C (thanks to Joe Smith for the heads-up!), but it’s quite simple to do in Swift — and not just to methods, but properties as well. Here’s a quick example, in which I redefine the String class property utf16Count, which returns the number of UTF-16 characters in a string (it maps to NSString‘s length method):

extension String {
  var utf16Count: Int { return 5 }
}

With this extension, I’ve monkeypatched utf16Count so that it always returns 5, no matter what the number of UTF-16 characters in the string is.

Monkeypatching is powerful, and it’s sometimes useful, but as smarter people than I have pointed out, it can create more problems than it solves. As Jeff Atwood asked in Coding Horror, “Can you imagine debugging code where the String class had subtly different behaviors from the Stringyou’ve learned to use?”

That’s what got me thinking: what if private could be used to limit the scope of a monkeypatch, to limit the applicability of my warped verstion of utf16Count to a single file? Is such a thing possible? To answer these questions, I created this extension to String in one file:

// File: ViewController.swift

private extension String {
  var utf16Count: Int { return 5 }  // already defined in String
  var someNumber: Int { return 10 } // a new addition to String
}

This extension provides two things:

  • A monkeypatch for String‘s already-existent utf16Count property so that it always returns the value 5
  • A new property for String called someNumber, which always returns the value 10

In the same file where I defined my extension to String, I wrote this code:

// File: ViewController.swift

let testString = "This is a test"
println("UTF-16 count inside: \(testString.utf16Count)")
    
doOutsideCount()

And in another file, I defined the doOutsideCount method:

// File: SomeOtherFile.swift

func doOutsideCount() {
  let testString = "This is a test"
  println("UTF-16 count outside: \(testString.utf16Count)")
}

If making the extension private limited my redefinition of utf16Count to the file where I redefined it, the output of doOutsideCount() would be “UTF-16 count outside: 14″, since there are 14 UTF-16 characters in testString. I noticed that while typing in the code in this file, utf16Count was available to me in auto-complete.

Here’s the output that appeared on the console when I ran the app:

UTF-16 count inside: 5
UTF-16 count outside: 5

It appears that monkeypatching (redefining an existing member) in an extension marked private does not limit the monkeypatch to the file where the monkeypatch was defined. You can’t use private to limit the scope of a monkeypatch to a single file.

I changed the code in both files to try calling on someNumber, a method that didn’t already exist in String:

// File: ViewController.swift

func doOutsideCount() {
  let testString = "This is a test"
  println("someNumber inside: \(testString.someNumber)")
}

// File: SomeOtherFile.swift

func doOutsideCount() {
  let testString = "This is a test"
  println("someNumber inside: \(testString.someNumber)")
}

This wouldn’t even compile. Calling on the someNumber property of String outside of the file where I defined the private extension raises an error: 'String' does not have a member named 'SomeNumber'.

My conclusion from this little bit of experimenting is also this article’s title:

You can use Swift’s private access modifier to limit the reach of overrides and extensions, but not monkeypatches.

{ 1 comment }

Americans can unlock their phones again…legally!

by Joey deVilla on August 1, 2014

it's legal again

It’s official: President Obama will sign the Unlocking Consumer Choice and Wireless Competition Act, which brings back an important exemption to the Digital Millennium Copyright Act that lets customers and authorized third parties modify a phone’s firmware and thus removing restrictions that most carriers put on their phones. The White House blog explains how this change was brought about in greater detail, but for those of you who’d rather not get into all the legal stuff, here’s the practical upshot:

You can now unlock your phone (or hire a service to do it for you) so that you can switch carriers, all without getting fined or sued.

Have a happy Friday!

this article also appears in the GSG blog

{ 2 comments }

Amazon’s Fire Phone: Made up of $205 of parts and so-so reviews

fire phone - 205 in parts

In their latest “teardown”, research firm took apart an Amazon Fire Phone, looked at its components and tallied up their total cost to be $205. As of this writing, it sells for $649 without contract on Amazon’s site. This is more than the cost of parts in the current iPhones (according to IHS, the parts for an iPhone 5C cost $173, and for an iPhone 5S, the cost is “at least $199″), and less than the cost of parts for a Samsung Galaxy S5 (which IHS says is about $256).

Upon examining the Fire Phone’s components, IHS analyst Andrew Rassweiler says that it’s “a pretty standard mid-range phone from a hardware perspective”, with the notable exception of its “Dynamic Perspective” feature, which is enabled by additional sensors in each corner. Dynamic Perspective uses the sensors to determine the phone’s orientation in relation to the user’s head combined with some imaging tricks to make pictures on the screen look almost three-dimensional:

Among the parts found in the Fire Phone were a member of the Qualcomm Snapdragon chip family as its main processor, which also power Samsung’s Galaxy S5, Nokia’s Lumia 1520, and ZTE’s Grand S II, and a 720p display, which at $27, is considerably cheaper than the display in the iPhone 5S ($43) or the Galaxy S5′s ($63).

If you’re more concerned about the reviews of the Fire Phone in action rather than its innards:

Expect to see more 64-bit phones on the market next year

qualcomm parts

Right now, Apple has the only devices with 64-bit processors: the iPhone 5S and the 2013 family of iPads, and that development is said to have created a lot of concern among the competition. In an interview with Dan Lyons, an unnamed Qualcomm employee is quoted as saying:

“The 64-bit Apple chip hit us in the gut. Not just us but everyone, really. We were slack-jawed, and stunned, and unprepared. It’s not that big a performance difference right now, since most current software won’t benefit. But in ‘Spinal Tap’ terms it’s like, 32 more, and now everyone wants it.”

When we talk about “32-bit” and “64-bit” processors, we’re talking about the number of bits — that is, BInary digITs — that the processor can use to access memory. A 32-bit processor can access 232 memory locations, which corresponds to 4 gigabytes. There’s no point to putting more than 4GB of RAM in a 32-bit device — it wouldn’t be able to use access any more than the first 4 gigs. That’s the 64-bit advantage: A 64-bit processor can access 264 memory locations, or 16 exabytes, where an exabyte is a billion gigabytes. Being able to access more memory means than programs can be larger (and more feature-filled), and can perform even more complex tasks. Keep in mind that we’re talking about active memory, or RAM, which the CPU uses to perform its tasks, and not the storage or “hard drive” space.

That situation is expected to change next year with the release of the Qualcomm Snapdragon 810 series of chips, their first 64-bit mobile processors. Aimed at high-end “flagship” phones, you should start seeing them appear in top-of-the-line 2015 smartphones and tablets, with the usual “trickle-down” effects appearing in less expensive devices over time.

Faster RAM for mobile devices on the way

cheetah

Not only will mobile devices be able to access more memory soon, they’ll also be able to do so much faster. It’s expected that LP-DDR4 technology, a low-power version of the DDR4 RAM already seen in today’s better desktop and laptop computers, will go mainstream in 2016, which is two years earlier than projected. Samsung estimates that the new memory technology will be 50% faster and 40% more power-efficient than the current LP-DDR3 technology used in to smartphones, and will offer data transfer speeds of 17 gigabytes per second — 34 gigabytes a second for 64-bit devices. As one might expect, Qualcomm have already announced support for LP-DDR4 technology in the Snapdragon 810 chipset.

this article also appears in the GSG blog

{ 0 comments }

Charge your smartphone in 15 minutes with the Ultrapak

15 minutes to full charge

Sometimes it happens: you’ve been making heavy use of your phone or tablet, and now it’s low on power. Sometimes, you get lucky and have both the time and nearby outlet to get enough power to carry on. For those other times when you’re short on both time and a convenient power source, you might want to have an Ultrapak handy. Farhad Manjoo reports on his experience with the Ultrapak in a New York Times piece, where he calls it “a lifesaver” and closes with “If there’s a better way to power up quickly, I haven’t seen it.”

Find out which hotels have the best wifi at HotelWifiTest.com

hotel wifi rating site

There’ve been many times where I’ve had to get work done from my hotel room or in the lobby or cafe and found myself packing up for the nearest Starbucks after getting frustrated with the wifi speed. While there are many sites that rate hotels on many dimensions, wifi connectivity hasn’t been one of those criteria. Luckily for us, there’s HotelWifiTest, a site that provides speed test results for various hotels around the world. The database is a bit small as of this writing: it covers 160 hotels in New York, 42 in San Francisco, and 52 in London, England for starters, but since it lets users run tests and submit results from their hotels, it’ll become more useful as it becomes more popular. (You can also use their speed test to check the wifi speed anywhere, including your home and office.)

Hilton hotels switching to smartphone-enabled locks

your phone is your key

The Wall Street Journal may have hidden this story behind their paywall, but other sites such as Gizmodo are reporting this news: the Hilton Hotel chain is upgrading its rooms and equipping them with smartphone-enabled door locks. Not only will you be able to use your smartphone as your room key, you’ll be able to bypass the whole front desk check-in dance entirely. They expect to have the majority of their hotels upgraded by 2016.

this article also appears in the GSG blog

{ 0 comments }