iOS6 Text Centering Issue

After upgrading Xcode, I hadn’t used it much until today when I tried to set the centering property for a label. I discovered that the previously used text centering property, UITextAlignment, is now deprecated. See the image below. Upon checking the documentation, I found that iOS6 introduced a new property, NSTextAlignment. The new property includes Justified and Natural, so out of curiosity, I tried the Natural property on a label. It resulted in an error. ...

March 5, 2013 · 1 min · Zhiya

Javascript Study Notes - Pseudo-classes and Inheritance

Inheritance in Javascript can be divided into two main categories (non-constructor inheritance and constructor inheritance). Let’s start with the simpler one and get to know constructor-based inheritance. Javascript is a prototype-based language and does not have the concept of classes inherently, so we can only simulate class-based patterns to implement classes and class inheritance. We use constructor functions to simulate the concept of classes. For example, let’s define a Person class. ...

January 6, 2013 · 2 min · Zhiya

A Small Issue Triggered by the 'nettop' Command

I came across a post online mentioning that Mac OSX 10.7 introduced a new command called nettop, which allows you to view current network connections and data flow in real-time. Here is the description of the nettop command: The nettop program displays a list of sockets or routes. The counts for network structures are updated periodically. I decided to give it a try in Terminal. After experimenting with it, I didn’t pay much attention to it. However, about a minute or two after closing Terminal, the fan on my Mac suddenly started spinning wildly. According to iStatMenu, it reached around 5300rpm. Typically, the fan only spins up like this when playing games or watching Flash content, but when I checked the dock, I found that only Chrome, iMessage, and iTunes were open, and no services like Apache were running. Opening Activity Monitor, I discovered that all four CPU cores were maxed out, and two nettop processes were consuming almost all CPU resources. ...

December 19, 2012 · 2 min · Zhiya

browser.js - Browser and Operating System Detection

A JavaScript for browser detection created by me. By importing browser-min.js into the head of your HTML file, it will return a global variable browser, where browser.browser represents the browser, browser.engine represents the browser engine, browser.version represents the browser version, and browser.system represents the operating system. Download the uncompressed version: http://labs.simpleapples.com/browser/browser.js.zip (6.025kb) Download the compressed version: http://labs.simpleapples.com/browser/browser-min.js.zip (1.387kb) Demo: http://labs.simpleapples.com/browser GitHub: http://github.com/simpleapples/browser.js

December 11, 2012 · 1 min · Zhiya

A Small Test About Javascript

I came across a small test called “Do You Really Understand Javascript?” on SAE’s microblog. Although it consists of only a few lines of code, it highlights some easily overlooked issues. Here’s the original image from the microblog: Result of the first code snippet: 1 Javascript does not provide block-level scope, so the variable a inside the if statement’s {} is visible outside. Result of the second code snippet: 1 Here, the function name and the variable name are the same, but ...

December 3, 2012 · 2 min · Zhiya