{"id":2240,"date":"2014-05-21T15:29:59","date_gmt":"2014-05-21T15:29:59","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=2240"},"modified":"2014-05-21T15:29:59","modified_gmt":"2014-05-21T15:29:59","slug":"week-8","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/week-8\/","title":{"rendered":"Linux, SQL and a scoop of yogurt in Week #8"},"content":{"rendered":"<h2>Find of the Week<\/h2>\n<h3>Project Parfait<\/h3>\n<p>I&#8217;m a big yogurt fan, so there&#8217;s a decent chance I came across this while Googling recipes. Either way, it&#8217;s an incredible tool.<\/p>\n<p>Supported only in Chrome at time of writing, this little app will allow you to upload a PSD, then slice and dice it for you, returning CSS, colors, fonts, etc. It&#8217;ll even pick apart individual layers or objects and export CSS rules to create them on the web.<\/p>\n<p>I&#8217;m not sure I&#8217;ll use it for every project, but it definitely takes me once step closer to a less platform dependent development machine.<\/p>\n<p><a href=\"https:\/\/projectparfait.adobe.com\">https:\/\/projectparfait.adobe.com<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Linux<\/h2>\n<h3>Time Zones<\/h3>\n<p>For a while, I had a server that for one reason or another, would restart every couple of months. No problem, it always happened at night, downtime was minimal and all services came back up.<\/p>\n<p>A couple days after each restart, I&#8217;d get an email from one of my clients to the effect of, &#8220;It&#8217;s weird, all of a sudden the time on our orders is one hour off.&#8221;<\/p>\n<p>&#8220;That is weird&#8221;, I&#8217;d reply, and immediately I knew that the server time zone was set improperly. So, I&#8217;d do the usual move my timezone file over to the \/etc\/localtime and voila, it was fixed.<\/p>\n<p>I manage a few servers, so I clearly couldn&#8217;t remember that this same server was having the time zone reset every couple months. It finally hit me that it was something in a server config file.<\/p>\n<p>A simple update to <em>\/etc\/sysconfig\/clock<\/em> and I&#8217;m good to go!<\/p>\n<p>Oh, that update was to set the <strong><em>ZONE=<\/em><\/strong> parameter\u00a0in the clock config file to the proper time zone.<\/p>\n<h3><\/h3>\n<h3>Secure Images not Working in some Email Clients<\/h3>\n<p>I had a really stupid and probably not-so-common issue with SSL certificates this week. I had installed a very basic Positive SSL certificate on one of my domains.<\/p>\n<p>Everything checked out, except, when I viewed an email in Mozilla Thunderbird, it would not load the secure images from the server. \u00a0Any image at https:\/\/ simply wouldn&#8217;t load.<\/p>\n<p>It ends up that Thunderbird didn&#8217;t like the order that I placed the SSL certificate chain files in!<\/p>\n<p>This <a href=\"http:\/\/www.unrelatedshit.com\/2011\/10\/21\/positivessl-not-working-with-android\/\">post<\/a> brought the issue to light for me.<\/p>\n<p>&nbsp;<\/p>\n<h2>SQL<\/h2>\n<h3>Getting the total row count when a limit is used<\/h3>\n<p>This is a really handy tip I learned this week. Typically when I want to return the number of matched rows when a LIMIT is used, I&#8217;ll do one of two things:<\/p>\n<ul>\n<li>Get the entire result set, then use my scripting language to get the count and return the limited results<\/li>\n<li>Run two queries (one to get the count, and another to get the limited result set).<\/li>\n<\/ul>\n<p>Neither is really desirable. The first returns a complete resultset which could include thousands of rows. The second requires you to duplicate your WHERE condition, which could be complex, on the query to get the count.<\/p>\n<p>It turns out that MySQL has an option called <code>SQL_CALC_FOUND_ROWS<\/code>\u00a0and it&#8217;s definitely worth reading two paragraphs of info to find out what it does!<\/p>\n<p><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/information-functions.html#function_found-rows\">http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/information-functions.html#function_found-rows<\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Inserting and Authorizing in a single query<\/h3>\n<p>A couple days ago I was putting my usual validation in place on a site, verifying that a user had ownership of an object before modifying it. Traditionally, I would run a query to see if the user had an editor role on an object, fail if they didn&#8217;t and proceed to run the insert or update query afterwards if the authorization passed.<\/p>\n<p>It hit me that this could be done in a single query, saving a round trip to the database:<\/p>\n<pre class=\"prettyprint\"><code>INSERT INTO list_account (l_id, a_id)\r\nSELECT      1 as sl_id, 9 as sa_id\r\nFROM        list\r\nWHERE EXISTS (SELECT 1 FROM list WHERE l_id = 1 AND user_id = 6)\r\n AND  EXISTS (SELECT 1 FROM account_user \r\n              WHERE account_id = 9 AND owner_user_id = 5)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I lost some time this week wrestling with SSL and server time zones. But I also picked up a few handy SQL tips that are worth sharing.<\/p>\n","protected":false},"author":1,"featured_media":2192,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[276],"tags":[283,141,89,278],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/2240"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=2240"}],"version-history":[{"count":10,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/2240\/revisions"}],"predecessor-version":[{"id":2251,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/2240\/revisions\/2251"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media\/2192"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=2240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=2240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=2240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}