FIX: Unable to download data from https://rubygems.org/ - certificate verify failed

I've used rvm for a while to manage my ruby installations and it works great. Today I've tried updating my gems with gem update and it tells me "nothing is to be updated". Eh? At least I know cocoapods is updated from my installed 0.24 to 0.26. What happened?

Then I tried to update gems manually. Firstly:

> gem install cocoapods
ERROR:  Could not find a valid gem 'cocoapods' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://s3.amazonaws.com/production.s3.rubygems.org/latest_specs.4.8.gz)

 Great! That's the reason. There is a long long list of the issue under https://github.com/rubygems/rubygems/issues/515

The solution suggested are:
1. use an insecure connection to rubygems.org with:

> gem update  --source http://rubygems.org

It works. But it doesn't solve the problem

2. RVM should update its certificates:

> rvm osx-ssl-certs status all
Certificates for /etc/openssl/cert.pem: Old.

> rvm osx-ssl-certs update all
Updating certificates for /etc/openssl/cert.pem: Updating certificates in '/etc/openssl/cert.pem'.
mkdir: /etc/openssl: Permission denied
Admin password required for 'mkdir -p /etc/openssl':

Then everything should be fine now.

A detailed information can be found at http://railsapps.github.io/openssl-certificate-verify-failed.html

For non-RVM and non-MAC users, here is the answer: http://stackoverflow.com/questions/19150017/ssl-error-when-installing-rubygems-unable-to-pull-data-from-https-rubygems-o


FIX: A blank view appears after QLPreviewController dismissed in iOS 7

Recently when I am working with iOS 7, I encounter the following problem: If the modalPresentationStyle of an view controller is set as UIModalPresentationFormSheet or UIModalPresentationPageSheet and after one uses the QLPreviewController once in the view controller and dismisses the Quick Look, a blank / gray view will appear on the screen instead of the presented view controller. This blank view cannot be dismissed or interacted.

That seems a serious bug in iOS 7. :(

After some days trying errors, I've found the following workaround:

in the presenting ViewController:

if ([self DeviceSystemMajorVersion] >= 7) {
modalVC.transitioningDelegate = self;
modalVC.modalPresentationStyle = UIModalPresentationCustom;
} else {
modalVC.modalPresentationStyle = UIModalPresentationFormSheet;

The function to detect iOS 7:

- (NSUInteger) DeviceSystemMajorVersion {
    static NSUInteger _deviceSystemMajorVersion = -1;
    static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_deviceSystemMajorVersion = [[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue];
return _deviceSystemMajorVersion;

The presenting view controller should conform to the protocol UIViewControllerAnimatedTransitioning and UIViewControllerTransitioningDelegate, in order to use the custom transaction style that indroduced in iOS 7. Continue to add these methods:

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
                                                                  presentingController:(UIViewController *)presenting
                                                                      sourceController:(UIViewController *)source {
return self;
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
UIView *inView = [transitionContext containerView];
    UIView *toView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view;
    UIView *fromView = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey].view;
UIView *preferenceOverlay = [[UIView alloc] initWithFrame:inView.frame];
preferenceOverlay.backgroundColor = [UIColor blackColor];
preferenceOverlay.alpha = 0;
[inView addSubview:preferenceOverlay];
toView.frame = CGRectMake(0, 0, 540, 540);
toView.center = CGPointMake(CGRectGetMidX(inView.frame), CGRectGetMidY(inView.frame));
[inView addSubview:toView];
    [UIView animateKeyframesWithDuration:(1.0) delay:0 options:0 animations:^{
preferenceOverlay.alpha = 0.4;
    } completion:^(BOOL finished) {
        [transitionContext completeTransition:finished];

Then in the presented view controller:

-(void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
if ([self DeviceSystemMajorVersion] >= 7) {
if (QLOpened) {
self.view.frame = CGRectMake(0, 0, 540, 540);
CGFloat xCenter = CGRectGetMidX(self.view.superview.frame) + 125;
CGFloat yCenter = CGRectGetMidY(self.view.superview.frame) - 125;
self.view.center = CGPointMake(xCenter, yCenter);
NSLog(@"Center X:%f Y:%f",xCenter,yCenter);

Then let the view controller to conform the protocol QLPreviewControllerDelegate and add the following method:
- (void)previewControllerWillDismiss:(QLPreviewController *)controller {
NSLog(@"QLView dismissed");
[self.view setNeedsLayout];


If you have the centering problem of the modal view controller, try fine-tuning the center point of the method viewWillLayoutSubviews


HOWTO: Compile Sigil under Mac OS X from source codes

Sigil is a very powerful ePub file publisher, which can be used to create, modify and edit ebooks. Since the source codes of Sigil is put on GitHub(https://github.com/user-none/Sigil/), I have to compile Sigil directly from source codes. Now here is the HOWTO。 :)

Firstly, you need brew(http://brew.sh) to let it install different packages for compiling.

Once brew is installed, you should install the following packages using terminal:

> brew install cmake
> brew install qt5

> export Qt5_DIR=/usr/local/opt/qt5

Check out the source codes from GitHub or download the ZIP . Go to the directory in Terminal and execute the following commands:

> mkdir build
> cd build
> make

At the end in the folder "bin" is the compiled Sigil.app, which can be dragged into Application folder.



FIX: Running PEAR, PECL & Co. under Mac OS X Mavericks DP6

When I tried to use pear under Mac OS X Mavericks DP6, I got a very unhelpful error message:

$ pecl
Could not open input file: /usr/lib/php/peclcmd.php

It seems that pear & pecl are not preinstalled! No problem, at least Mavericks provides an install package.

sudo php -d detect_unicode=0 /usr/lib/php/install-pear-nozlib.phar

Then the nightmare began:

$ sudo pecl install uploadprogress
downloading uploadprogress- ...
Starting to download uploadprogress- (9,040 bytes)
.....done: 9,040 bytes
4 source files, building
running: phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
building in /private/tmp/pear/temp/pear-build-rootTuNmJz/uploadprogress-
running: /private/tmp/pear/temp/uploadprogress/configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i386-apple-darwin13.0.0
checking host system type... i386-apple-darwin13.0.0
checking target system type... i386-apple-darwin13.0.0
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
checking for PHP extension directory... /usr/lib/php/extensions/no-debug-non-zts-20100525
checking for PHP installed headers prefix... /usr/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable uploadprogress functions... yes, shared
checking for ld used by cc... /Applications/Xcode5-DP6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode5-DP6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking for /Applications/Xcode5-DP6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 196608
checking command to parse /usr/bin/nm output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fno-common
checking if cc PIC flag -fno-common works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/Applications/Xcode5-DP6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin13.0.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /private/tmp/pear/temp/pear-build-rootTuNmJz/uploadprogress- --mode=compile cc  -I. -I/private/tmp/pear/temp/uploadprogress -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootTuNmJz/uploadprogress- -I/private/tmp/pear/temp/pear-build-rootTuNmJz/uploadprogress- -I/private/tmp/pear/temp/uploadprogress -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /private/tmp/pear/temp/uploadprogress/uploadprogress.c -o uploadprogress.lo
mkdir .libs
 cc -I. -I/private/tmp/pear/temp/uploadprogress -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootTuNmJz/uploadprogress- -I/private/tmp/pear/temp/pear-build-rootTuNmJz/uploadprogress- -I/private/tmp/pear/temp/uploadprogress -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/uploadprogress/uploadprogress.c  -fno-common -DPIC -o .libs/uploadprogress.o
In file included from /private/tmp/pear/temp/uploadprogress/uploadprogress.c:23:
/private/tmp/pear/temp/uploadprogress/php_uploadprogress.h:34:10: fatal error: 'php.h' file not found
#include <php.h>
1 error generated.
make: *** [uploadprogress.lo] Error 1

ERROR: `make' failed

No way! The /usr/include doesn't exist for phpize....Hours of trying error and searching... Thanks a post from Homebrew community, I got that problem fixed through:

sudo ln -s /Applications/Xcode5-DP6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/ /usr/include


FIX: Errors with installing MySQL on Ubuntu

In order to install a LNMP environment on a VPS, I've tried the following command to install MySQL server, but what I got is:

130816 18:53:17  InnoDB: Waiting for the background threads to start
130816 18:53:18 InnoDB: 5.5.32 started; log sequence number 1595675
130816 18:53:18  InnoDB: Starting shutdown...
130816 18:53:19  InnoDB: Shutdown completed; log sequence number 1595675
start: Job failed to start
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing mysql-server-5.5 (--configure):
 subprocess installed post-installation script returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Processing triggers for ureadahead ...
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

It's really an error message that says nothing. The ubuntu is freshly installed. After hours of trying with solutions from Internet, I've found the following solution working for me:

sudo apt-get clean

sudo apt-get autoclean

sudo apt-get remove --purge mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5

sudo apt-get install mysql-server

before reinstalling, you may need also the following commands:

rm -rf /var/lib/mysql
rm -rf /etc/mysql*

So it is.


FIX: Xcode failed to get the task for process XXX

Recently by debugging an app on devices, Xcode keeps throwing the error message "Failed to get the task for process XXX" like this:

enter image description here

After long searching on the internet, one solution has saved my day:

It turns out that using a different provisioning profile (one with a wildcard rather than one without) solved this issue.

So I changed the provisioning profile by debugging from app specified to ios team provisioning profile. BRAVO,  now it works like a charm.

via StackOverflow


Workaround for "AssertMacros: queueEntry, file: /SourceCache/IOKitUser_Sim/IOKitUser-920.1.11/hid.subproj/IOHIDEventQueue.c, line: 512"

I am busy recently with testing some apps under iOS 7 Beta 5. Now while running the app, the debug console keeps outputting some useless information like:

AssertMacros: queueEntry, file: /SourceCache/IOKitUser_Sim/IOKitUser-920.1.11/hid.subproj/IOHIDEventQueue.c, line: 512

 It is really annoying and makes the debug info useless, since it appears every time when I touch the screen. Thanks 0xced, now here is a workaround solution for that:

Here is a workaround to this annoying problem.

  1. Download fishhook
  2. Copy fishhook.h and fishhook.c in your project
  3. Compile this file (QuietAssertMacros.c) in your project:

#include <dlfcn.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "fishhook.h"

int slient_fprintf(FILE * restrict stream, const char * restrict format, ...)
    if (strncmp(format, "AssertMacros:", 13) == 0)
        return 0;
        va_list args;
        va_start(args, format);
        int result = vfprintf(stream, format, args);
        return result;

__attribute__((constructor)) void QuietAssertMacros(void)
    rebind_symbols((struct rebinding[1]){{"fprintf", slient_fprintf}}, 1);
Unfortunately, you will have to repeat these steps for every project you are working on.

via devforum apple


MySQL Error 1130 "Host 'xx.xx.xx.xx' is not allowed to connect to this MySQL server."

When I tried to connect a mysql server from outside today morning, I got a mysql error like:

ERROR 1130: Host 'xx.xx.xx.xx' is not allowed to connect to this MySQL server.

That means the mysql server is configured to allow only local connections. The configuration can be modified easily in mysql tables.

Under terminal, type the following commands

> mysql -u root -pmypassword

mysql> use mysql;

mysql> update user set host = '%' where user = 'root';

mysql> flush privileges;

Now you could connect the mysql server from the outside client.


Strange Behavior: UIButton Text will be not shown.

Because of a multilingual project, all the texts should be translated and replaced with the correct language version. Everything was fine until I found that a button won't show the text assigned.

The code:

 [button titleLabel].text = @"I won't be changed";

The result is: the button shows always the text that is set up in the storyboard. If I delete the text in Storyboard, it will even disappear when I tap!

The solution is also simple:

[button setTitle:@"I will change" forState:UIControlStateNormal]

via StackOverflow


One Class for One Problem

The keyboard on iOS devices is sometimes a nightmare for a programmer.  Take the UITextField as an example, when a keyboard appears, it will cover most screen area and let the text fields hidden in the back of the soft keyboard. A solution provided by Apple is using the UIScrollView, but there are a lot of mathematical calculation for a programmer. :(

After a while research on the internet, I've found that Michael Tyson has built a drop-in solution for such kind of problems. He packs everything that one needs into a class and puts the sources on GitHub.

If you follow the instruction on the Github, the task with UITextField and Keyboard is easy as a cake!


For use with UITableViewController classes, drop TPKeyboardAvoidingTableView.m and TPKeyboardAvoidingTableView.h into your project, and make your UITableView a TPKeyboardAvoidingTableView in the xib. If you're not using a xib with your controller, I know of no easy way to make its UITableView a custom class: The path of least resistance is to create a xib for it.
For non-UITableViewControllers, drop the TPKeyboardAvoidingScrollView.m and TPKeyboardAvoidingScrollView.h source files into your project, pop a UIScrollView into your view controller's xib, set the scroll view's class toTPKeyboardAvoidingScrollView, and put all your controls within that scroll view. You can also create it programmatically, without using a xib - just use the TPKeyboardAvoidingScrollView as your top-level view.

Well done, Michael!

via ATasty Pixel

HOWTO: UIScrollView scroll to bottom programmatically

The autolayout function of a view controller is very useful. The UI elements can find their position after a rotation automatically. Except for UIScollerview...Orz

The reason is: The Layout in Storyboard is normally designed for portrait, not for landscape. So if an user rotates his iOS devices, the UIScrollView cannot resize its content height automatically. So a programmatical resize is needed. BUT, there is another way: just scroll the UIScrollView to the bottom(or where you want), the content will be presented in landscape correctly like in portait.

Here is the solution: Adding the following code to the view controller where the scroll view is.

-(void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// Scroll to the bottom
CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
[self.scrollView setContentOffset:bottomOffset animated:YES];

via StackOverflow