Pocket C.H.I.P. first impressions

Last year, I helped Kickstart C.H.I.P. last year and it just arrived the other day. I opted for the Pocket C.H.I.P version since I’m too lazy to make a casing for it and dig out peripherals when it arrived. Some of my other reasons for getting Pocket C.H.I.P. (besides shiny new candybar/toy) was to show it to friends as the portable and then hook up as a desktop to show off as well. Other reasons was to have as an option for family in the Philippines and get some friends kids into coding.

pocket-chip

First thing I did was hook it up online and updated apt-get. The pencil kickstand idea is pretty damn awesome and useful. bv
chip

After updating, I decided to power down to look at the main guts of it. I knew the actual computer part would be small but am still impressed with how small it is. The no-screws casing is very nice and well put together. I found that the battery is stickied on to the board so changing from portable to “desktop” and reusing the battery isn’t an easy option.

Besides the battery, there are a few other things that hinder going back and forth from pocket to desktop. The first being a sacrifice of resolution. This is because (according to the chip update site) : “A C.H.I.P. that supports DIPs does not support PocketC.H.I.P. and vice versa. C.H.I.P.s can be reflashed to work with either, just not at the same time. Yes, we’re going to fix this.” Also related to this is that there doesn’t seem to be a way to boot between the pocket chip os and chip os. (have to look into this more)

The keyboard is alright. I tested it using terminal and found that vi didn’t work the way I’m use to. I first thought it was a keyboard issue then figured out it is a vim config idea.

This was solved by installing vim-gui-common and vim-runtime.

sudo apt-get install vim-gui-common vim-runtime

I was surprised that there was no browser on the pocketchip os. After some research, I found that people have tried various options and dwb seems to be the best option given the touch screen and resolution. I tried dwb out for a few minutes and it crashed on me. I’ll look into that a bit more sometime.

The latest thing I tried is to run the pocket chip headless. This is possible to do but you have to install the ssh service first. The reason it is not installed is “don’t want uninformed people to get rooted all the time with default user and password while they’re out and about. We’re considering better solutions to this issue.

So you will have to go to the terminal and install it.

sudo apt-get install openssh-server

I changed the default password obviously. I plan on flashing the device into the desktop and playing around with that next.

‘UIViewControllerHierarchyInconsistency’, reason: ‘A view can only be associated with at most one view controller at a time!

So I was working on an iOS app for a client and received this error when trying to launch the app in iOS simulator. I was assured that the repository I was pulling from was the same codebase as the app currently in the store. After googling, I found several stackoverflow questions on this with a lot of text answers and 1 with a very short explanation with a before and after screenshot that didn’t explain much. As you can tell by the blog URL, iOS is currently not my programming strength, so I decided to make a blog post to go slightly deeper into this and compile the bits I learned from debugging this.

First of all, the reason I encountered was due to a change introduced in iOS 6. I forget what it was exactly but that’s why we’re seeing this error message.  What error message? Something that looks like this:

2013-07-12 11:07:52.775 App[3545:c07] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <UIScrollView: 0x89780c0; frame = (0 20; 320 548); autoresize = W+H; gestureRecognizers = <NSArray: 0x8979730>; layer = <CALayer: 0x89782c0>; contentOffset: {0, 0}> is associated with <UIViewController: 0x8979cc0>. Clear this association before associating this view with <RootViewController: 0x753ed50>.'
*** First throw call stack:
(0x172b012 0x1110e7e 0x172adeb 0x481cb9 0x518f7c 0x515440 0x845be 0x840e7 0xaeb58 0x651019 0x1124663 0x172645a 0x64fb1c 0x5147e7 0x514dc8 0x514ff8 0x515232 0x5154da 0x52c8e5 0x52c9cb 0x52cc76 0x52cd71 0x52d89b 0x52edc6 0x52f065 0x52f1a8 0x52f5b9 0x52f257 0x52f1de 0x11bfd 0x15c589 0x15a652 0x15b89a 0x15a60d 0x15a785 0xa7a68 0x1a38911 0x1a37bb3 0x1a75cda 0x16cd8fd 0x1a7635c 0x1a762d5 0x1960250 0x16aef3f 0x16ae96f 0x16d1734 0x16d0f44 0x16d0e1b 0x20657e3 0x2065668 0x433ffc 0x1fdd 0x1f15)
libc++abi.dylib: terminate called throwing an exception

So we, obviously, have the title of this article:

'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time!

followed by the important part:

<UIScrollView: 0x89780c0; frame = (0 20; 320 548); autoresize = W+H; gestureRecognizers = <NSArray: 0x8979730>; layer = <CALayer: 0x89782c0>; contentOffset: {0, 0}> is associated with <UIViewController: 0x8979cc0>. Clear this association before associating this view with <RootViewController: 0x753ed50>.'

This is telling us a few things:

  1. The main issue is in RootViewController
  2. UIScrollView and UIViewController are in some sort of Highland/ThunderDome situation

    Highlander: The Game

    Highlander: The Game (Photo credit: Wikipedia)

So we should open up the problem file:

full view

Hey! Look, there’s the ViewController and something called Scroll View. We’re probably on the right track. It’s right there, under Objects. Let’s take a closer look at that.

 

 

 

 

 

 

issue

 So what iOS 6 is complaining about is we have a view within a view in our view controller (kinda like Inception).
So what do we have to do to solve this? Let’s take the Scroll View child and make it a sibling.
solution
Well now that View Controller is kinda useless, let’s clean that up.
cleanup
Oh yeah, I read something about the File’s Owner Class, so let’s change that too. I’m putting a pic in of this because it’s a change I made and I’m not sure if it actually has anything to do with this but figure I’d rather have too many steps than not enough steps.

file owner classThere you have it. That’s my how I solved this issue. Hope it works for you. Hopefully someday, I can come back to this and give a more thorough explanation but for now, this is all I got.

Enhanced by Zemanta

PHPStorm File Templates Includes Custom Variables

PHPStorm’s File template settings are very versatile. They allow you to not only make a file template, but also allow you to parse out redundant elements (such as licensing) in the template by allowing an includes section. In your File Template, any undefined variable automatically elicits a prompt from PHPStorm.

PHPStorm allows you access to the includes section via the #parse directive. If you’re want To have Custom variables to be filled in correctly via prompt, you will need to have the variable declared in the template.

Example

“chance license.php”

/**
* @package ${Package}
* @author Chance Garcia
* @copyright (C)Copyright ${YEAR} chancegarcia.com
*/

In the above includes example, I’m wanting to have a custom variable named Package. I can only cause PHPStorm to prompt for this value if I include the variable in my template. If I’m already using the variable in the template, then it will fill in when the includes file is parsed.

Example:

<?php
#parse("chance license.php")

class ${Package}_#if(${ExtraClassInfo} != "")${ExtraClassInfo}_#end${NAME}
{

}

In the above template, the ${Package} variable will be given a prompt since it is used in the template and an unknown variable and the parsed “chance license.php” include will be able to use that prompt value.

I am also using another variable to Prompt for extra class name information. Since PHPStorm uses Velocity Template Language (VTL), I am able to use the VTL conditional syntax to insert that information if it is entered and ignore it if it is not. This technique is useful in a situation where you want your include file to have a custom variable value but do not need to display this value in your template.

Example:

<?xml version="1.0"?>
<!--
#if(${Package})#end
#parse("chance license.php")
-->

 

In the above example, we make PHPStorm prompt for the custom value needed for out parsed include file. This gives us our expected include file without printing our custom variable anywhere else in our template.

 

Update: I made a github repo (https://github.com/chancegarcia/phpstorm-templates) of my templates for better examples and in case I lose my settings.

Enhanced by Zemanta

MAMP PRO, PECL, SSH2, and OSX CLI (AKA acronym madness)

Or madness in general. So as you may know, I’ve started using PHPStorm to work locally. I decided to dust off an old SSH2 wrapper I wrote and play with how PHPStorm uses PHPUnit and does refactoring. I knew that I would have to install the extension via PECL and was like, “Oh it can’t be that bad to do it through MAMP PRO” and as you may have guessed, I sealed my own fate for a couple hours. One thing I can say is that, even though I use a convenient app like MAMP PRO to set up my local development environment, I’m glad my sysadmin-fu is up to snuff enough to fly without the conveniences because after this ordeal, I feel like I might as well have made my MAMP stack from scratch with all the hoops I jumped tonight. (I’m pretty sure that last sentence is also one of the worst run-on sentences ever).

The first thing you need to know is that the PECL command is located at the directory

/Applications/MAMP/bin/php/php5.3.6/bin

when I tried to run

sudo ./pecl install -a ssh2 channel://pecl.php.net/ssh2-0.11.3

from that directory, I got the error:

Notice: unserialize(): Error at offset 267 of 1133 bytes in Config.php on line 1050
PHP Notice: unserialize(): Error at offset 267 of 1133 bytes in /Applications/MAMP/bin/php/php5.3.6/lib/php/PEAR/Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.

I found out later that the error is most likely caused by the file

/Applications/MAMP/bin/php/php5.3.6/conf/pear.conf

So if you get an error, try doing

sudo mv /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf.bkp

If you’re still getting the error, you can also the following:

  1. Install Xcode Tools from your Mac OS X DVD or download it from Apple Developer Connection
  2. Download the complete PHP source code from php.net into /Applications/MAMP/bin/php/php5.3.6/
  3. Create an include directory in the the php5.3.6 directory.
  4. Unzip/tar the php source archive and move it to/Applications/MAMP/bin/php/php5.3.6/include/
  5. Rename the php source directory to just php (so then it will look like /Applications/MAMP/bin/php/php5.3.6/include/php)
  6. In Terminal use the following commands to compile the extension:
    cd /Applications/MAMP/bin/php/php5.3.6/include/php
    ./configure

That should allow you to run the PECL command however, you will probably get a complaint about not having libssh installed. So you will have to

  1. go download libssh2 (http://www.libssh2.org/). As much as I like git, I recommend  downloading the latest release tarball instead of cloning the repo. For some reason, I got a version incompatibility error when trying to run the PECL install with the repo version and had to do all these steps over with the tarball release version.
  2. unzip the directory and cd to the upacked directory in the terminal.
  3. run: ./configure; make all install;
    libssh should compile and place the output file in src/*.o
  4. copy all headers from the include folder within the libssh2 directory to
    /usr/local/include/
  5. copy all compiled files (*.o) from the src folder within the libssh2
    directory to /usr/local/lib/

After you’ve successfully ran the the PECL install, it should tell you to  Add the line

extension=ssh2.so

to the Dynamic Extensions area of your php.ini file. I believe both MAMP and MAMP PRO allow you to edit the necessary ini through File>Edit Template.

MAMP edit php.ini

 

Lastly, restart apache. You should be able to see the SSH2 extension when you load a phpinfo() page.

Bonus round:

I’m not sure how I have  PHP CLI working in OSX but if you’ve followed the steps above and try to verify the extension install with through the cli, it won’t show up.

$ php -a
php> phpinfo();

This is because (if you’re also using MAMP PRO) the binaries are different. The good news is that you can make things happy in 3 easy steps

  1. run `sudo ln -s /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so /usr/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so` in the terminal.
  2.  Edit the /etc/php.ini (copy /etc/php.ini.default if /etc/php.ini doesn’t exist)  like you did for the MAMP php.ini(s)
  3. profit.

Note: I still have to install PHPUnit into my current setup so that may or may not elicit another blog post.

Sources:

  • http://smbjorklund.no/how-enable-pecl-uploadprogress-extention-mamp
  • http://php.net/manual/en/ref.ssh2.php
  • http://forum.mamp.info/viewtopic.php?t=13815
Enhanced by Zemanta

Magento Extension GitIgnore Stub

As you may or may not know, I’ve been working with Magento lately. In the past few months, one thing I’ve found that I needed is a stock .gitignore file for when making extensions. Haven’t found one so I made one on github and will also post here for anyone else in need site. I’m still relatively new at working with Magento and in someways git/github so please feel free to critique/streamline.


# replace {company} and {extension} placeholders with your information

# ignore phpstorm files
/.idea

# Ignore all not in app & skin
/*
!/app/
!/js/

# ignore all in js, except module files for this module
/js/*
!/js/{company}/

# Ignore all in app, except code & etc
# Ignore all in app/code except /local/{company}
/app/*
!/app/code/
!/app/etc/
!/app/design/

# Ignore all in app/code/local except {company}
/app/code/core
/app/code/community
/app/code/local/*
!app/code/local/{company}/
# use lines below if you have multiple company extensions
# and want to just commit a specific one
#/app/code/local/{company}/*
#!app/code/local/{company}/{extension}

# Ignore all of app/etc except our specific module files
/app/etc/*
!/app/etc/modules/
/app/etc/modules/*
!/app/etc/modules/{company}_{package}.xml

#Ignore all of app/design except for our files
/app/design/*
!app/design/frontend/
!app/design/adminhtml/
/app/design/frontend/*
!/app/design/frontend/base/
/app/design/frontend/base/default/etc/
/app/design/frontend/base/default/template/*
!/app/design/frontend/base/default/template/{extension}/
/app/design/frontend/base/default/layout/*
!/app/design/frontend/base/default/layout/{extension}/*
/app/design/adminhtml/*
!/app/design/adminhtml/default/
/app/design/adminhtml/default/find/
/app/design/adminhtml/default/default/etc/
/app/design/adminhtml/default/default/locale/
/app/design/adminhtml/default/default/template/*
!/app/design/adminhtml/default/default/template/{extension}/
/app/design/adminhtml/default/default/layout/*
!/app/design/adminhtml/default/default/layout/{extension}/*

Enhanced by Zemanta