Kindle Preview Crashes on Mac OS X Yosemite

Kindle Preview.app

Kindle Preview.app

I’m pretty sure this applies to any recent version of Mac OS X, but this glitch has currently hit me and I’m on Yosemite. What happened was that I downloaded the Kindle Preview tool, because I’m working on an eBook, who isn’t right? Well, the Kindle Preview tool kept crashing when I tried to fire it up.

It turns out that Kindle Previewer requires Java version 1.6, and Yosemite is on version 1.8. The fix is pretty simple.

Step 1 :: Download Java for OS X 2015-001. Close all of your Java applications (I just closed everything), and install it.

Step 2 :: Using the command-line, open up /Applications/Kindle Previewer.app/Contents/MacOS/Launcher with vi or something similar. You can do this via the GUI as well. Right-click Kindle Preview.app -> Show Package Contents and drill down until you see Launcher. Open Launcher with some sort of text editing tool.

Step 3 :: Add the following line right below “#!/bin/sh”

export JAVA_HOME=/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

I’ve seen some folks recommending the below line instead. But that’s not where Apple installed the Java 1.6 JDK on my Yosemite machine, so I’m not sure where that instruction came from, but your machine might have it installed there.

export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

Step 4 :: Open Kindle Preview and it should be rocking now.

Typing the Wrong Timezone in php.ini Creates Strange Issues

I’m not that type of programmer who remembers all of the mundane details associated with a given language. I rely heavily on the language documentation to get through my day. I just don’t have the bandwidth, or the desire to store in my brain, for instance, PHP’s timezone values.

Even though I’ve been using one timezone exclusively for the past six years, and even when I look it up, I still get it wrong. I live on the east coast so my timezone should be America/New_York.

I always forget whether it’s supposed to have the underscore or not. So today, I looked it up, yep, it needs the underscore and so I typed in American/New_York as the timezone in my php.ini and rebooted my server.

What happened? Now I’m getting these strange 500 errors, but nothing is showing up in my PHP or Apache error logs. It must be that damn timezone. Yep, I typed American/New_York instead of America/New_York. I fixed it, rebooted my web server and I was back in business.

But it’s worth noting that if you change your timezone in PHP, and if you mess up and type the timezone incorrectly, you will get some strange errors. Whenever I’ve done it wrong, none the errors appear to be related to the timezone being wrong.

For my own reference, here are the America timezones for PHP.
America/Adak
America/Anchorage
America/Anguilla
America/Antigua
America/Araguaina
America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/ComodRivadavia
America/Argentina/Cordoba
America/Argentina/Jujuy
America/Argentina/La_Rioja
America/Argentina/Mendoza
America/Argentina/Rio_Gallegos
America/Argentina/Salta
America/Argentina/San_Juan
America/Argentina/San_Luis
America/Argentina/Tucuman
America/Argentina/Ushuaia
America/Aruba
America/Asuncion
America/Atikokan
America/Atka
America/Bahia
America/Bahia_Banderas
America/Barbados
America/Belem
America/Belize
America/Blanc-Sablon
America/Boa_Vista
America/Bogota
America/Boise
America/Buenos_Aires
America/Cambridge_Bay
America/Campo_Grande
America/Cancun
America/Caracas
America/Catamarca
America/Cayenne America/Cayman
America/Chicago
America/Chihuahua
America/Coral_Harbour
America/Cordoba
America/Costa_Rica
America/Creston
America/Cuiaba
America/Curacao
America/Danmarkshavn
America/Dawson
America/Dawson_Creek
America/Denver
America/Detroit
America/Dominica
America/Edmonton
America/Eirunepe
America/El_Salvador
America/Ensenada
America/Fort_Nelson
America/Fort_Wayne
America/Fortaleza
America/Glace_Bay
America/Godthab
America/Goose_Bay
America/Grand_Turk
America/Grenada
America/Guadeloupe
America/Guatemala
America/Guayaquil
America/Guyana
America/Halifax
America/Havana
America/Hermosillo
America/Indiana/Indianapolis
America/Indiana/Knox
America/Indiana/Marengo
America/Indiana/Petersburg
America/Indiana/Tell_City
America/Indiana/Vevay
America/Indiana/Vincennes
America/Indiana/Winamac
America/Indianapolis
America/Inuvik
America/Iqaluit
America/Jamaica
America/Jujuy
America/Juneau
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Knox_IN
America/Kralendijk
America/La_Paz
America/Lima
America/Los_Angeles
America/Louisville
America/Lower_Princes
America/Maceio
America/Managua
America/Manaus
America/Marigot
America/Martinique
America/Matamoros
America/Mazatlan
America/Mendoza
America/Menominee
America/Merida
America/Metlakatla
America/Mexico_City
America/Miquelon
America/Moncton
America/Monterrey
America/Montevideo
America/Montreal
America/Montserrat
America/Nassau
America/New_York
America/Nipigon
America/Nome
America/Noronha
America/North_Dakota/Beulah
America/North_Dakota/Center
America/North_Dakota/New_Salem
America/Ojinaga America/Panama
America/Pangnirtung
America/Paramaribo
America/Phoenix
America/Port-au-Prince
America/Port_of_Spain
America/Porto_Acre
America/Porto_Velho
America/Puerto_Rico
America/Rainy_River
America/Rankin_Inlet
America/Recife
America/Regina
America/Resolute
America/Rio_Branco
America/Rosario
America/Santa_Isabel
America/Santarem
America/Santiago
America/Santo_Domingo
America/Sao_Paulo
America/Scoresbysund
America/Shiprock
America/Sitka
America/St_Barthelemy
America/St_Johns
America/St_Kitts
America/St_Lucia
America/St_Thomas
America/St_Vincent
America/Swift_Current
America/Tegucigalpa
America/Thule
America/Thunder_Bay
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Virgin
America/Whitehorse
America/Winnipeg
America/Yakutat
America/Yellowknife

Symfony Display HTML5 Date Picker

Sexy Business Woman Cleavage
While there are many reasons to use Symfony, the form builder is yet another. It’s yet to limit what I want to do, and adds a ton of value.

To enable the HTML5 date picker form widget, just do this.

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('birthday', 'date', array(
                'widget'=>'single_text',
                'format'=>'yyyy-MM-dd'
            ))
        ;
    }

The key is to set the format to “yyyy-MM-dd.” This is in accordance with RFC 3339.

Enable MySQL General Logging Using MAMP

Norah O'Donnell non sequitur

Norah O’Donnell non sequitur


Any Mac web developers out there right now still fiddling around with the version of PHP that Apple ships on every Mac needs to stop right now.

I’ve been there. When OSX first came out I tried to make Apple’s PHP and Apache to work. I did get it to work, but it was a total pain in the ass to keep working. I quickly realized that MAMP was the way to go. It adheres to the Apple slogan, “It just works.”

By default MAMP’s MySQL server is not configured to log all queries. I only MAMP for web development, so I’ll take the performance hit and enable general logging.

It’s pretty easy to do.

Open up /Applications/MAMP/conf/my.cnf and add the following section.

[mysqld]
general_log = 1
general_log_file = /Applications/MAMP/logs/mysql.log

Save that file and restart MAMP services.

PHP 5.6 SoapClient verify_peer With Self-Signed Certificate

Norah O'Donnell non sequitur

Norah O’Donnell non sequitur


By default, PHP 5.6 has verify_peer enabled for openssl connections. So if you use the SoapClient to connect via SSL to a soap server, you’ll likely see “Could not connect to host” connection failures.

To fix this, you need to generate some certificates on the server running your PHP applications and making the Soap calls.

You will need create a self-signed certificate, if you don’t already have one.

I’m running Ubuntu, so I followed these instructions.

What you’re doing is creating your own internal certificate authority and then generating a new certificate that you’ll link to in your php.ini.

On my server, I created a file in /etc/php5/apache2/conf.d/30-openssl.ini and put this in it.

[openssl]
openssl.cafile=/etc/ssl/certs/ca-certificates.crt

Symfony Form Variables Reference

Here are the Symfony form variables. I’m posting it here because I find I often need to look at it and it’s easily to find here than in the Symfony documentation.

Variable Usage form The current FormView instance. id The id HTML attribute to be rendered. name The name of the field (e.g. title) – but not the name HTML attribute, which is full_name. full_name The name HTML attribute to be rendered. errors An array of any errors attached to this specific field (e.g. form.title.errors). Note that you can’t use form.errors to determine if a form is valid, since this only returns “global” errors: some individual fields may have errors. Instead, use the valid option. submitted Returns true or false depending on whether the whole form is submitted valid Returns true or false depending on whether the whole form is valid. value The value that will be used when rendering (commonly the value HTML attribute). read_only If true, readonly=”readonly” is added to the field. disabled If true, disabled=”disabled” is added to the field. required If true, a required attribute is added to the field to activate HTML5 validation. Additionally, a required class is added to the label. max_length Adds a maxlength HTML attribute to the element. (deprecated as of 2.5, to be removed in 3.0, use attr[“maxlength”] instead) pattern Adds a pattern HTML attribute to the element. (deprecated as of 2.5, to be removed in 3.0, use attr[“pattern”] instead) label The string label that will be rendered. multipart If true, form_enctype will render enctype=”multipart/form-data”. This only applies to the root form element. attr A key-value array that will be rendered as HTML attributes on the field. label_attr A key-value array that will be rendered as HTML attributes on the label. compound Whether or not a field is actually a holder for a group of children fields (for example, a choice field, which is actually a group of checkboxes. block_prefixes An array of all the names of the parent types. translation_domain The domain of the translations for this form. cache_key A unique key which is used for caching. data The normalized data of the type. method The method of the current form (POST, GET, etc.). action The action of the current form.

Symfony Render Form Elements By Hand without Losing CSRF

If you’re like me and you render your form widgets by hand with Symfony, read this.

I had a situation where at various places in my application I used a different number of form widgets of a particular form. Sometimes I used just a button, sometimes I used other widgets.

The problem I had to solve was that {{ form_end }} renders all of the previously non-rendered form widgets. That’s not what I want so I did this.

{{ form_end(form, {'render_rest': false}) }}

That “worked,” but it breaks Symfony’s built-in cross-site request forgery capability. Essentially the csrf hidden token element wasn’t being rendered. Fortunately, it was an easy fix, just render the csrf by hand like the other form widgets.

{{ form_widget(form._token) }}

Voila! Now csrf is working again.

Don’t name your mixins wrong

If you’re not using Sass, you don’t need to read this article. What you need to do is to stop writing CSS right now and learn about Sass. If you are among the anointed into the Sass community, here’s something you shouldn’t do.

Don’t name your mixin files the same as your scss. I working redoing my basic Sass structure for a Symfony application I’m building to take better advantage of the power of mixins. What I ended up with was ‘_main.scss’ and ‘main.scss.’ The import was in main.scss. Even though these two files can exist on the file system fine, my Sass compiler didn’t like it.

I use Scout. At first I noticed that Scout stopped detecting changes in my scss files. I fired up Koala to see if it would work and it logged an error that it didn’t know which file to import main.scss or _main.scss. Scout didn’t tell me that, but once I renamed _main.scss to _base.scss, Scout started working as it should.

I don’t care for Koala, but I haven’t used it much. It did help me today.

Symfony Twig Concat String

Concatenating a string using Twig is pretty simple, if you know what you’re doing.

In my first instance in Twig string concatenation, I wanted to dynamically load some assets based on the route parameters.

With my solution, I ended doing something like this to load a stylesheet, for instance.

<link rel="stylesheet" type="text/css" media="all" href="{{ asset('bundles/hack3r3dradio/css/' ~ player ~ '.css') }}" />

I’m populating that player variable in my controller. The tilde is the concatenation character in Twig. In PHP it’s a period. In Javascript it’s a plus-sign. In Twig it’s a tilde.