<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Giedrius Majauskas blog &#187; Programming</title>
	<atom:link href="http://www.majauskas.com/category/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.majauskas.com</link>
	<description></description>
	<lastBuildDate>Thu, 29 Jul 2010 08:34:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to reduce pdf with embedded flash file size</title>
		<link>http://www.majauskas.com/how-to-reduce-pdf-with-embedded-flash-file-size</link>
		<comments>http://www.majauskas.com/how-to-reduce-pdf-with-embedded-flash-file-size#comments</comments>
		<pubDate>Wed, 21 Apr 2010 09:25:43 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=305</guid>
		<description><![CDATA[Embedding flash into pdf files have many uses: enriching PDF&#8217;s with animation, playing movies, handling forms or creating games. However, there is a huge problem with some flash files embedded: pdf file size. If one embed a (lets say) 200kb flash file into same-sized pdf file, you can get 4-6mb pdf file. This is way [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fhow-to-reduce-pdf-with-embedded-flash-file-size"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fhow-to-reduce-pdf-with-embedded-flash-file-size&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>Embedding flash into pdf files have many uses: enriching PDF&#8217;s with animation, playing movies, handling forms or creating games. However, there is a huge problem with some flash files embedded: pdf file size.</p>
<p>If one embed a (lets say) 200kb flash file into same-sized pdf file, you can get 4-6mb pdf file. This is way too much: it is like 10 times more than it should be there.  And this is quite typical result for more complex flashes, like ones with animation or requesting something from remote servers.</p>
<p>The problem might be related to custom flash player used to play flash files from within PDF. The PDFs with Embedded flash work even if there is no Flash player preinstalled on PC.  It might be that these flashes are pre-compiled in PDF. So, heavily animated multi-page flashes could reach sizes of 50-60m, which are not appealing to download.</p>
<p>However, there is an approach to reduce the size of the PDF, and it is not that hard. Adobe Acrobat pre-compiles the embedded  into page flash only, and not ones that are loaded, no matter if they are embedded in PDF itself or stored on the web. The loader flash does not takes too much space, also it can be the same for many pages (if flashes are similar in size).</p>
<p>There are 2 drawblacks  of this approach:</p>
<p>You cannot pass custom parameters for the loaded flashes, or at least we could not find a way.  So each loaded flash has to be compiled separately even if the difference between them is small.</p>
<p>You will have to add screenshots/thumbnails of initial flash sequence to each loader insertion, as starting frame for loader is blank.</p>
<p>And thanks for Aidas for finding this solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/how-to-reduce-pdf-with-embedded-flash-file-size/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How I am hiring programmers for long-term work</title>
		<link>http://www.majauskas.com/how-i-am-hiring-programmers-for-long-term-work</link>
		<comments>http://www.majauskas.com/how-i-am-hiring-programmers-for-long-term-work#comments</comments>
		<pubDate>Wed, 14 Apr 2010 20:25:21 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[hiring]]></category>
		<category><![CDATA[programmers]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=302</guid>
		<description><![CDATA[I am responsible for hiring process both in my own company and in the company I am working with now. And the biggest headache is to pick a right staff for positions that requires lots of training. For example, programmers. The problem with web programmers is that either they are young, solo workers, really bad [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fhow-i-am-hiring-programmers-for-long-term-work"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fhow-i-am-hiring-programmers-for-long-term-work&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>I am responsible for hiring process both in my own company and in the company I am working with now. And the biggest headache is to pick a right staff for positions that requires lots of training. For example, programmers.</p>
<p>The problem with web programmers is that either they are young, solo workers, really bad or really expensive.  However, there are guys that stand out from the general crowd which you have to find.</p>
<p>Typically, a programmer gets interested in programming and computers quite young. Many programmers know they destiny before they finish school. The best of them start coding something before university as well. In my opinion, university gives very little to improve basic programmer skills, but some knowledge might be useful in long shot. I have seen some good ones that have never studied computer science or programming at all.</p>
<p>The best way to determine how a programmer will perform is giving him a task that he never did before. For example, grabbing something from other page, creating something with exotic library or something along these lines. The reasoning beyond that is quite simple:</p>
<p>First, you can see if they are capable of finding solution. If a programmer gives up, he will not learn any new tricks on his own. Searching can give a lot of answers.</p>
<p>Second, you can see how you can communicate with that guy. If it takes time to explain problem, then you will have same issue in the future as well. One should pick a programmer one can work with, no matter how good other choices are.</p>
<p>Third  reason is that you can see his code. Coding web does not provides excuses to use unreadable code, though many freelancer folks / solo workers code for speed rather than quality. I am not talking about comments, but about simple things like variable naming or clear code structure.</p>
<p>There are also couple good questions you should ask and listen. Personally, I do not like programmers that do not try new things like frameworks or cms&#8217;es that speed up coding. They have to be curious and willing to learn.</p>
<p>Additionally, one should listen when they are speaking about former jobs &#8211; what they liked, learned or disliked. This is good to determine personal motives and if you can make them happy in your team.</p>
<p>Lastly, I always ask about most interesting project: one that is most difficult or interesting.</p>
<p>The final consideration is not only if the person is right for the job, but if you can provide a job that is right for that guy.</p>
<p>I have made hiring mistakes in the past. I wish I could tell if I can work with a guy from first meeting. Though life would not be as interesting then.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/how-i-am-hiring-programmers-for-long-term-work/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Never forget how your script will be hosted when programming for web</title>
		<link>http://www.majauskas.com/never-forget-how-your-script-will-be-hosted-when-programming-for-web</link>
		<comments>http://www.majauskas.com/never-forget-how-your-script-will-be-hosted-when-programming-for-web#comments</comments>
		<pubDate>Thu, 21 Jan 2010 16:19:45 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[concurrency]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=263</guid>
		<description><![CDATA[This week I had a really interesting problem to tackle: one simple script of mine behaved not as expected. And it took me couple hours of analysis for a simple ~30 line script to find the cause. The script on itself its quite simple one – we have 2 numbers and 2 dates, one of [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fnever-forget-how-your-script-will-be-hosted-when-programming-for-web"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fnever-forget-how-your-script-will-be-hosted-when-programming-for-web&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>This week I had a really interesting problem to tackle: one simple script of mine behaved not as expected. And it took me couple hours of analysis for a simple ~30 line script to find the cause.</p>
<p>The script on itself its quite simple one – we have 2 numbers and 2 dates, one of them is in the past, another is in the future. We need to calculate current value from current date and 4 other values. To complicate the problem, we have to randomize things a bit by adding something (always positive value compared to last one) up to the current value so we do not get a straight line from starting point to the finish. There are some other conditions that impact calculation.</p>
<p>Ending coordinates are constant during whole execution of the script. Starting coordinates would be constant if we had no randomization as well. So, we store starting coordinates in separate .php file that is loaded in main script. Then new values are calculated, checked if they are not out of bounds and written down as new starting values to the same config file.</p>
<p>Testing provided no problem with the script, however in work environment sometimes counter went back in time. And no one could find the issue. The added value was always positive. The configuration file was saved.  There was single configuration file used and no other programs overwrote it. Everything seemed ok and script worked incorrectly sometimes.</p>
<p>The problem was server load and disk space. During high loads on server, script execution was not atomic as expected, and file writes were slow too. So when 2 scripts executed at the same time, include file might be empty. Thus script would recalculate next value without having the data about previous “randomness” and it would be smaller than it should be.</p>
<p>The moral is that I should have expected similar problems. It is easy to forget concurrent environment of the web when programming or analyzing simple scripts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/never-forget-how-your-script-will-be-hosted-when-programming-for-web/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Phplists: is there something better for large newsletters?</title>
		<link>http://www.majauskas.com/phplists-is-there-something-better-for-large-newsletters</link>
		<comments>http://www.majauskas.com/phplists-is-there-something-better-for-large-newsletters#comments</comments>
		<pubDate>Fri, 15 Jan 2010 14:44:01 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=259</guid>
		<description><![CDATA[I have to distribute a mailing list of circa 150 000 email clients and wondered what alternatives I have to in-house system. This has lead to some research of various options for mailing customers. First there are 3 types of software I might use: web-based services, server based newsletter/mass mailing applications and PC software. web-based [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fphplists-is-there-something-better-for-large-newsletters"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fphplists-is-there-something-better-for-large-newsletters&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>I have to distribute a mailing list of circa 150 000 email clients and wondered what alternatives I have to in-house system. This has lead to some research of various options for mailing customers.</p>
<p>First there are 3 types of software I might use:   web-based services, server based newsletter/mass mailing applications and PC software.</p>
<p>web-based mass mailing services are quite expensive for bigger lists. For example, icontact.com offers plans costing $699.00 for 100 000 users per month. <a href="http://www.aweber.com/?339331">Aweber.com </a>is about the same (at least for smaller plans). It would be a good choice for a smaller permanent list.</p>
<p>Also I can’t tell how well web-based services  would perform under my constraints. I need Lithuanian encoding, handling weird email addresses of One.lt – popular Lithuanian social network with emails that uses its own email engine. And it has its own spams filter as well.</p>
<p>Another choice would be installable php scripts that would offer mass-mailing or newsletter handling. A clear choice would be phplists – a free php script for that. It looked very promising at first, however I met couple problems. First, it is not as user friendly as you would expect from distributed php software. I had to change lots of things in php scripts manually, even disabling test mode or changing encoding. That is not acceptable. Second, its import scripts suck. I have not managed to import mailing list properly even after I removed couple checks. Overall, its interface is lacking and I would not recommend this software for no-techie.</p>
<p>I have tested PC software as well, for example SendBlaster. It was quite promising except the way how it handles international encodings. I have received empty letter in my spam box.</p>
<p>So, the question remains open : should I try to make something working from phplists, search for its alternatives or use our in-house mailing system.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/phplists-is-there-something-better-for-large-newsletters/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An elegant solution to clean up html comments from wordpress themes</title>
		<link>http://www.majauskas.com/an-elegant-solution-to-clean-up-html-comments-from-wordpress-themes</link>
		<comments>http://www.majauskas.com/an-elegant-solution-to-clean-up-html-comments-from-wordpress-themes#comments</comments>
		<pubDate>Wed, 30 Dec 2009 10:36:17 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=252</guid>
		<description><![CDATA[Typically, all popular wordpress themes come with html comments to mark endings of div block. This is required for theme developers as it is much easier to see where particular block ends. However, I do not like leaving code like that in production site. Although some claim that HTML comments have no effect in SEO, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fan-elegant-solution-to-clean-up-html-comments-from-wordpress-themes"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fan-elegant-solution-to-clean-up-html-comments-from-wordpress-themes&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>Typically, all popular wordpress themes come with html comments to mark endings of div block. This is required for theme developers as it is much easier to see where particular block ends.</p>
<p>However, I do not like leaving code like that in production site. Although some claim that HTML comments have no effect in SEO, it might have effect in keyword discovery process. Additionally, they might have effect for various security plugins, that filter and block content containing bad words.  Third, I think it is bad to leave debug information in production sites.</p>
<p>The biggest problem of these is that WordPress theme frameworks like Hybrid uses these as well. So you will have to clean up frameworks source each time you upgrade your framework. That is not the best approach.</p>
<p>However, You can implement this by creating couple filters in your childs (or custom) theme  functions.php file:<br />
<code><br />
function custom_callback($buffer) {</code></p>
<p><code>$buffer=preg_replace('/&lt;!--(.*)--&gt;/Ui',' ',$buffer);</code></p>
<p><code>return $buffer;</p>
<p>}</p>
<p>function custom_buffer_start() { ob_start("custom_callback"); }</p>
<p>function custom_buffer_end() { ob_end_flush(); }</p>
<p>if (is_user_logged_in() ) {</p>
<p>} else {</p>
<p>add_action('wp_head', 'custom_buffer_start');</p>
<p>add_action('wp_footer', 'custom_buffer_end');</p>
<p></code></p>
<p><code>}<br />
</code><br />
This will clean the code from comments when user is not logged in (for search engines and visitors).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/an-elegant-solution-to-clean-up-html-comments-from-wordpress-themes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do you really need that powerful cms for simple projects?</title>
		<link>http://www.majauskas.com/do-you-really-need-that-powerful-cms-for-simple-projects</link>
		<comments>http://www.majauskas.com/do-you-really-need-that-powerful-cms-for-simple-projects#comments</comments>
		<pubDate>Wed, 09 Dec 2009 22:41:11 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=247</guid>
		<description><![CDATA[Last month I took over support of one project that inspired this post. It is a website with couple static pages, news and galleries that was created with Joomla. The problem was that site owners could not support it. They are not computer savvy and the internal structure of admin panel is way too complex [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fdo-you-really-need-that-powerful-cms-for-simple-projects"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fdo-you-really-need-that-powerful-cms-for-simple-projects&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>Last month I took over support of one project that inspired this post. It is a website with couple static pages, news and galleries that was created with Joomla. The problem was that site owners could not support it. They are not computer savvy and the internal structure of admin panel is way too complex for them to understand.</p>
<p>Funny enough, I would have gone to completely opposite direction with that site design. Based on site requirements, I would install WordPress and code additional functionality. WordPress handles many things better than Joomla:</p>
<ul>
<li>Image upload and resize to sane sizes</li>
<li>Article/news organization</li>
<li>Simpler admin interface</li>
</ul>
<p>And a lot of clients do not need anything more – they do not want to resize media prior uploading, or searching for missing plugins to do that resize on upload time. Also, content and organization is tragic in Joomla, and it is really difficult to comprehend for person that does not work with such systems daily.</p>
<p>Now Joomla has its own uses and I would not create complex sites on wordpress. However, how often developers think about customer needs instead of their development speed and “Power” of the application? Many of us want to show off with powerful options, lots of customizability as we cannot brag about nice code inside to the customer.  Often it is not what customer needs.</p>
<p>Thus it is important to write down requirements of project before putting everything on most powerful CMS you know. Think what user wants to see and make it easy for user to navigate through admin panel to do the tasks he needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/do-you-really-need-that-powerful-cms-for-simple-projects/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking scissors wordpress plugin: resize based on image ratio</title>
		<link>http://www.majauskas.com/hacking-scissors-wordpress-plugin-resize-based-on-image-ratio</link>
		<comments>http://www.majauskas.com/hacking-scissors-wordpress-plugin-resize-based-on-image-ratio#comments</comments>
		<pubDate>Wed, 11 Nov 2009 21:07:00 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=236</guid>
		<description><![CDATA[Recently, I had simple but interesting problem on wordpress where I could not find ready automatic solution: thumbnail generation based on image ratio. I use wordpress as CMS for image-heavy site. For example, I want that 3 sized images: For landscape pictures I need 202&#215;133 thumbnails For square (or alike) images I need 156&#215;142 thumbnails [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fhacking-scissors-wordpress-plugin-resize-based-on-image-ratio"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fhacking-scissors-wordpress-plugin-resize-based-on-image-ratio&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>Recently, I had simple but interesting problem on wordpress where I could not find ready automatic solution: thumbnail generation based on image ratio. I use wordpress as CMS for image-heavy site.</p>
<p>For example, I want that 3 sized images:</p>
<ol>
<li><span style="background-color: #ffffff; ">For landscape pictures I need 202&#215;133 thumbnails</span></li>
<li><span style="background-color: #ffffff; ">For square (or alike) images I need 156&#215;142 thumbnails</span></li>
<li><span style="background-color: #ffffff; ">For portrait images  I need 120&#215;162 thumbnails</span></li>
</ol>
<p>The exact size of thumbnails matters, as I want to put these images in nice picture frames, with no spacing around. So obviously, I need a cropper that should work automatically.</p>
<p>WordPress itself does not provide that function. Thus I started looking for plugin as basis for such cropper.  I have chosen <a href="http://wordpress.org/extend/plugins/scissors/">scissors</a> – a very nice wordpress plugin I can recommend for others.  It allows user to control resizing and cropping images on upload, also it provides additional options for resizing/cropping images automatically.</p>
<p>However, how to make this plugin crop images depending on ratio automatically? Well, we need to hack into its source.</p>
<p>All modifications done are in scissors.php, scissors_resize_auto($metadata) function. We work with medium image size, as scissors does not work with thumbnails itself (we could implement this as well).</p>
<p><strong>Step 1. Configuration.</strong></p>
<p>We need to configure scissors to use adaptive image resize for medium sized images, or it will not pass through the function. Obviously, we can’t use inputs to define image size for all 3 cases without more serious coding, so we stop configuring there and hack into source.</p>
<p><strong>Step 2. Determining image ratio.</strong></p>
<p>Image ratio can be calculated at this:  $ratio = $srcW/$srcH; , where $srcW is width and $srcH is height of original image. If $ratio is bigger than 1, image is landscape,  in other case it is portrait. For this case we assume that ratio between 1 and 1.3 means square image, though we could use other steps.<br />
<code><br />
if ($size=='medium') {<br />
if ($ratio&gt;1.3) {<br />
$maxW=202;<br />
$maxH=133;<br />
} else if ($ratio&gt;=1){<br />
$maxW=156;<br />
$maxH=142;<br />
} else {<br />
$maxW=120;<br />
$maxH=162;<br />
}<br />
$dstH=$maxH;<br />
$dstW=$maxW;<br />
…..<br />
</code><br />
So, we now have the image size to use and the image would be resized to exact size required. However, the image would be screwed when original image ratio would not match resized image ratio. We need to crop image as well as resize it.</p>
<p><strong>Step 3. Croping the image to proper ratio.</strong></p>
<p>Luckily, imagecopyresampled that is used to resize image can crop it during same operation as well. For this, we need to calculate area we need to crop in original image. First, let us initialize some variables:</p>
<p><code><br />
$startx=0;<br />
$starty=0;<br />
$endy=$srcH;<br />
$endx=$srcW;<br />
</code></p>
<p>Then,</p>
<p><code><br />
if ($dstW/$dstH&lt;$ratio) {<br />
$endx=round($srcH*$dstW/$dstH);<br />
$startx=round(($srcW-$endx)/2);<br />
} else {<br />
$endy=round($srcW*$dstH/$dstW);<br />
$starty=round(($srcH-$endy)/2);<br />
}<br />
</code><br />
The only thing left is changing imagecopyresampled request to</p>
<p><code><br />
imagecopyresampled($dst, $src, 0, 0, $startx, $starty, $dstW, $dstH, $endx, $endy)<br />
</code><br />
Which crops required area from center of original image and resizes it.</p>
<p>That’s it. The end product is still in development and will be launched this week.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/hacking-scissors-wordpress-plugin-resize-based-on-image-ratio/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>11 tips on sending emails from web applications</title>
		<link>http://www.majauskas.com/11-tips-on-sending-emails-from-web-applications</link>
		<comments>http://www.majauskas.com/11-tips-on-sending-emails-from-web-applications#comments</comments>
		<pubDate>Mon, 02 Nov 2009 20:29:16 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SEM]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=234</guid>
		<description><![CDATA[Email marketing is still useful for list builders and keeping in touch with your consumers. However, quite often communication is lost in the email Spam box and not read by recipient. How to solve this problem? Here are some tips. Your server and domain First thing I would check is the spammy IP list. Is [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2F11-tips-on-sending-emails-from-web-applications"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2F11-tips-on-sending-emails-from-web-applications&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<div>Email marketing is still useful for list builders and keeping in touch with your consumers. However, quite often communication is lost in the email Spam box and not read by recipient. How to solve this problem? Here are some tips.</div>
<ol>
<li>Your server and domain
<ol>
<li>First thing I would check is the spammy IP list. Is your IP address blacklisted? It happens, especially on shared hosting. Good place to start searching is http://www.mxtoolbox.com/blacklists.aspx  . I would use a dedicated IP if I plan to do mass mailing.</li>
<li>Do your IP address resolves back and how? If it has IP address in reverse domain address, they think it is a DSL – assigned IP and not a hosting one, so it is assumed that this is SPAM. If IP resolves back to your domain, it is a good sign.</li>
<li>SPF record is highly advisable. Not all incoming mail servers use SPF record; however it never hurts to have one.</li>
</ol>
</li>
<li>Your email message headers. Forging headers is bad idea. Your headers should be informative and correct, including message ID.  It is important how you write your email address there as well, you should always use real name with email address where possible.  Same is applicable for recipient email address as well. Prove that you know them.</li>
<li>Avoid spam words or keep their density low. The message should have enough text; however it should not be too big. Also, avoid excessive capitalization and spacing.</li>
<li>You should include information why they are getting this message, also your contact information, as well unsubscribe information (if applicable). You do not have to write that your message is not spam – only spammers do that.</li>
<li>You should use well-formed html if you have to use it. No hidden text, tracking images or similar – they are usually blocked by anti-spam programs. Also you should include text version of email.</li>
<li>Avoid using spam – mailers. The anti-spam programs know  about them and how to recognize most of them. This is quite sure way to be flagged as spam.</li>
<li>Monitor your returning email box. See what messages got undelivered and bounced back. See if it is your problem or the recipient problem.</li>
<li>Upon registration, ask your visitors to add your email to their address book and use same email for communication with them. Address book is the best way to pass spam filters.</li>
<li>Some mail servers do not like too many emails from single sender at any point. Try to space out the sending of your newsletters.</li>
<li>Avoid sending too many messages to people that can&#8217;t read them &#8211; full message boxes, blocked, etc.</li>
<li>Check your web application if it can&#8217;t be used to send spam for real. This might be a case for &#8220;send to a friend&#8221; forms or similar which allow information input. This is quite serious security issue as you might get blacklisted.</li>
</ol>
<p>Overall, the most important factor is monitoring back all information you get back from emails you send, especially the &#8220;negative&#8221; one : bounced emails, sending errors and similar. There are lots of information in bounced messages that you should read and evaluate.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/11-tips-on-sending-emails-from-web-applications/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stop cursing PHP for your faults</title>
		<link>http://www.majauskas.com/stop-cursing-php-for-your-faults</link>
		<comments>http://www.majauskas.com/stop-cursing-php-for-your-faults#comments</comments>
		<pubDate>Thu, 03 Sep 2009 16:10:17 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[software quality]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=224</guid>
		<description><![CDATA[I have read a tweet about PHP programming today that made me furious. “Handling complex logic in PHP is like doing the LSATs after shock therapy” What is wrong with this statement? It moves responsibility from coder to the coding language and that is completely wrong in this case. Firstly, PHP has syntax similar to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fstop-cursing-php-for-your-faults"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fstop-cursing-php-for-your-faults&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>I have read a tweet about PHP programming today that made me furious.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">“Handling complex logic in PHP is like doing the LSATs after shock therapy”</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">What is wrong with this statement? It moves responsibility from coder to the coding language and that is completely wrong in this case.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Firstly, PHP has syntax similar to C, which is used to code programs much more complex than most of websites. Almost all control statements are similar or same.  Although there are differences, I doubt anyone would argue that there is a significant lack of logic control statements in PHP than in C. Although PHP lacks specific PC programming libraries, it has very little to do with implementing logic of application.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">So, what might cause such statements?</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">The top reason for problems handling logic is bad quality of the code (software quality measures how well software is designed (quality of design), and how well the software conforms to that design (quality of conformance), although there are several different definitions). PHP, similarly to C, is a very flexible language. And you need to and think work to produce good, quality code.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thus, what is code quality characteristics related to implementing logic in PHP?</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1.<span style="white-space: pre;"> </span>Separation of concerns. You should not handle logic, input, output, database, exceptions in single big file. Implement these as functions, or use libraries and frameworks. There is no excuse to not use a PHP framework nowadays, except when modifying old application source. And yes, I made such mistakes myself in the past.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2.<span style="white-space: pre;"> </span>Avoid logic shortcuts, like die(), exit() and break (in cycles, not in switch) statements if you can. They make code much harder to comprehend in the long run. Perfect function or method has a single return statement as well.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">3.<span style="white-space: pre;"> </span>Use right model of computation to process information gathered. Logic will look nasty in all the languages as long as you have no foundation how to handle it. And the worst is, these programming models are already here for decades, like FSMs. Simply, they are used in software programming, but not so in web programming.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">4.<span style="white-space: pre;"> </span>Comments, documentation, sane names of variables and no hacking. One of the reasons for bad code is “quick fixes”, when quick, undocumented fixes are applied to program code that no one understands later on. Even worse, they are applied to the system/framework core without any documenting sometimes. That might leave you stuck with un-updated version of some framework for long time.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">5.<span style="white-space: pre;"> </span>It is better to comply with framework programming model than implement couple different models in single system. If you are using hook and plugin based framework as wordpress, stick to it, and know its features, internal logic and limitations.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">If you will know these 5 things, all you will have to curse is your code or framework/cms you are using. But not the PHP.</div>
<p>“Handling complex logic in PHP is like doing the LSATs after shock therapy”</p>
<p>What is wrong with this statement? It moves responsibility from coder to the coding language and that is completely wrong in this case.</p>
<p>Firstly, PHP has syntax similar to C, which is used to code programs much more complex than most of websites. Almost all control statements are similar or same.  Although there are differences, I doubt anyone would argue that there is a significant lack of logic control statements in PHP than in C. Although PHP lacks specific PC programming libraries, it has very little to do with implementing logic of application.</p>
<p>So, what might cause such statements?</p>
<p>The top reason for problems handling logic is bad quality of the code (<a href="http://en.wikipedia.org/wiki/Software_quality">software quality measures how well software is designed (quality of design), and how well the software conforms to that design (quality of conformance)</a>). PHP, similarly to C, is a very flexible language. And you need to and think work to produce good, quality code.</p>
<p>Thus, what is code quality characteristics related to implementing logic in PHP?</p>
<ol>
<li>Separation of concerns. You should not handle logic, input, output, database, exceptions in single big file. Implement these as functions, or use libraries and frameworks. There is no excuse to not use a PHP framework nowadays, except when modifying old application source. And yes, I made such mistakes myself in the past.</li>
<li>Avoid logic shortcuts, like die(), exit() and break (in cycles, not in switch) statements if you can. They make code much harder to comprehend in the long run. Perfect function or method has a single return statement as well.</li>
<li>Use right model of computation to process information gathered. Logic will look nasty in all the languages as long as you have no foundation how to handle it. And the worst is, these programming models are already here for decades, like FSMs. Simply, they are used in software programming, but not so in web programming.</li>
<li>Comments, documentation, sane names of variables and no hacking. One of the reasons for bad code is “quick fixes”, when quick, undocumented fixes are applied to program code that no one understands later on. Even worse, they are applied to the system/framework core without any documenting sometimes. That might leave you stuck with un-updated version of some framework for long time.</li>
<li>It is better to comply with framework programming model than implement couple different models in single system. If you are using hook and plugin based framework as wordpress, stick to it, and know its features, internal logic and limitations.</li>
</ol>
<p>If you will know these 5 things, all you will have to curse is your code or framework/cms you are using. But not the PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/stop-cursing-php-for-your-faults/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Programmer mindset: 5 traits of programmers that have a chance to become good ones</title>
		<link>http://www.majauskas.com/programmer-mindset-5-traits-of-programmers-that-have-a-chance-to-become-good-ones</link>
		<comments>http://www.majauskas.com/programmer-mindset-5-traits-of-programmers-that-have-a-chance-to-become-good-ones#comments</comments>
		<pubDate>Tue, 01 Sep 2009 16:10:32 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=219</guid>
		<description><![CDATA[Sometime we get a new inexperienced guy in a company as a programmer. Typically, we test them beforehand; however they are rarely perfect when started. Sometimes they are very new to programming or have bad habits from previous programming jobs. Thus it is my goal to help them to improve. And sometimes it gets really [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fprogrammer-mindset-5-traits-of-programmers-that-have-a-chance-to-become-good-ones"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fprogrammer-mindset-5-traits-of-programmers-that-have-a-chance-to-become-good-ones&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Sometime we get a new inexperienced guy in a company as a programmer. Typically, we test them beforehand; however they are rarely perfect when started. Sometimes they are very new to programming or have bad habits from previous programming jobs. Thus it is my goal to help them to improve. And sometimes it gets really hard to integrate the guy into company. However there are some criteria that allow recognizing people with potential on becoming programmers and ones that are better left behind.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1.<span style="white-space: pre;"> </span>Persistence and knowing how to learn. Even more, urge to try and learn new things. I love programmers that know how to look for information on a problem.  Everyone can do a task they learned, but the best programmers know where to look for an answer and never give up without a good reason. The best way is to give a task they have no experience in and look how they are trying to solve it. If a person gives up prior googling for an answer, he will not be a programmer.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2.<span style="white-space: pre;"> </span>Ability to integrate various things he learned in different environment. Few programmers learned MVC or frameworks at universities here. However, they have learned FSMs or some other paradigms that can be successfully applied in web development as well. Few try it though <img src='http://www.majauskas.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (Note: knowing more than one programming paradigm is a bonus).</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">3.<span style="white-space: pre;"> </span>Ability to create a concise logical algorithm for solving a problem. You can be entry level web programmer without that, but that’s it.  Ability to draw these using some popular schematics like UML state diagram is a bonus.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">4.<span style="white-space: pre;"> </span>Ability to debug code of other person. A programmer is unable to learn if he can’t dive into code of someone else and understand how it works. Sooner or later you will have to implement a similar algorithm where you will not be able to use that code as it is. This is closely related to ability to create algorithm.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">5.<span style="white-space: pre;"> </span>Ability to write code other people understands. I loved one programmer that wrote nice functions for everything while coding a trivial task in PHP. Also, he commented a lot. Sadly, his interest was not web programming.</div>
<p>Sometime we get a new inexperienced guy in a company as a programmer. Typically, we test them beforehand; however they are rarely perfect when started. Sometimes they are very new to programming or have bad habits from previous programming jobs. Thus it is my goal to help them to improve. And sometimes it gets really hard to integrate the guy into company. However there are some criteria that allow recognizing people with potential on becoming programmers and ones that are better left behind.</p>
<ol>
<li>Persistence and knowing how to learn. Even more, urge to try and learn new things. I love programmers that know how to look for information on a problem.  Everyone can do a task they learned, but the best programmers know where to look for an answer and never give up without a good reason. The best way is to give a task they have no experience in and look how they are trying to solve it. If a person gives up prior googling for an answer, he will not be a programmer.</li>
<li>Ability to integrate various things he learned in different environment. Few programmers learned MVC or frameworks at universities here. However, they have learned FSMs or some other paradigms that can be successfully applied in web development as well. Few try it though <img src='http://www.majauskas.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (Note: knowing more than one programming paradigm is a bonus).</li>
<li>Ability to create a concise logical algorithm for solving a problem. You can be entry level web programmer without that, but that’s it.  Ability to draw these using some popular schematics like UML state diagram is a bonus.</li>
<li>Ability to debug code of other person. A programmer is unable to learn if he can’t dive into code of someone else and understand how it works. Sooner or later you will have to implement a similar algorithm where you will not be able to use that code as it is. This is closely related to ability to create algorithm.</li>
<li>Ability to write code other people understands. I loved one programmer that wrote nice functions for everything while coding a trivial task in PHP. Also, he commented a lot. Sadly, his interest was not web programming.</li>
</ol>
<div>Your thoughts ?</div>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/programmer-mindset-5-traits-of-programmers-that-have-a-chance-to-become-good-ones/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Designing site for Russian speakers? Keep subdomain count low or design for performance</title>
		<link>http://www.majauskas.com/designing-site-for-russian-speakers-keep-subdomain-count-low-or-design-for-performance</link>
		<comments>http://www.majauskas.com/designing-site-for-russian-speakers-keep-subdomain-count-low-or-design-for-performance#comments</comments>
		<pubDate>Mon, 24 Aug 2009 19:25:39 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SEM]]></category>
		<category><![CDATA[yandex]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=206</guid>
		<description><![CDATA[There is couple of reasons to develop site distributed under multiple subdomains, e.g. subdomain1.domain.com, subdoman2.domain.com, etc. Each subdomain might be a distinguishable mini-site, which offers better separation of topics and even protects main site rankings to some extent. However, subdomain approach has one issue that needs to be solved. That is each subdomain is treated [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fdesigning-site-for-russian-speakers-keep-subdomain-count-low-or-design-for-performance"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fdesigning-site-for-russian-speakers-keep-subdomain-count-low-or-design-for-performance&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">There is couple of reasons to develop site distributed under multiple subdomains, e.g. subdomain1.domain.com, subdoman2.domain.com, etc. Each subdomain might be a distinguishable mini-site, which offers better separation of topics and even protects main site rankings to some extent.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">However, subdomain approach has one issue that needs to be solved. That is each subdomain is treated as separate site by some search engine spiders. This leads to insane amounts of concurrent hits. The worst offender is yandex – a Russian search engine whose spider scan list is probably alphabet based. Thus many of your minisites get scanned at the same time for content.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">This might not be a problem if each of your minisites are hosted separately and not on the same server. Also, this would not be a problem if your subdomains are simplistic. In other cases you have to rely on your page caching and server capacity.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">There is a crawl delay option that yandex listens to. However, this option can be set in robots.txt only. And robots.txt is subdomain-based. Thus it works for single subdomain only.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">I have decided to totally block yandex from indexing one of my sites once. Luckily, this site can live from visitors from Russia, as it is geared towards different location. But now I doubt I would do a heavily multi-domain (300+ subdomains) site knowing that I will have to use yandex traffic as well.</div>
<p>There is couple of reasons to develop site distributed under multiple subdomains, e.g. subdomain1.domain.com, subdoman2.domain.com, etc. Each subdomain might be a distinguishable mini-site, which offers better separation of topics and even protects main site rankings to some extent.</p>
<p>However, subdomain approach has one issue that needs to be solved. That is each subdomain is treated as separate site by some search engine spiders. This leads to insane amounts of concurrent hits. The worst offender is yandex – a Russian search engine whose spider scan list is probably alphabet based. Thus many of your minisites get scanned at the same time for content.</p>
<p>This might not be a problem if each of your minisites are hosted separately and not on the same server. Also, this would not be a problem if your subdomains are simplistic. In other cases you have to rely on your page caching and server capacity.</p>
<p>There is a crawl delay option that yandex listens to. However, this option can be set in robots.txt only. And robots.txt is subdomain-based. Thus it works for single subdomain only.</p>
<p>I have decided to totally block yandex from indexing one of my sites once. Luckily, this site can live from visitors from Russia, as it is geared towards different location. But now I doubt I would do a heavily multi-domain (300+ subdomains) site knowing that I will have to use yandex traffic as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/designing-site-for-russian-speakers-keep-subdomain-count-low-or-design-for-performance/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>7 tips on web programming code analysis</title>
		<link>http://www.majauskas.com/7-tips-on-web-programming-code-analysis</link>
		<comments>http://www.majauskas.com/7-tips-on-web-programming-code-analysis#comments</comments>
		<pubDate>Sat, 22 Aug 2009 16:00:51 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[analysis]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=204</guid>
		<description><![CDATA[Quite often I am hired to perform modifications in other web projects done by someone else.  This might be an unmaintained website bought ages ago, or when programmers mess up. It is tough to analyze your own code after couple of years from creation. It is much harder to analyze code of someone else. There [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2F7-tips-on-web-programming-code-analysis"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2F7-tips-on-web-programming-code-analysis&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Quite often I am hired to perform modifications in other web projects done by someone else.  This might be an unmaintained website bought ages ago, or when programmers mess up. It is tough to analyze your own code after couple of years from creation. It is much harder to analyze code of someone else. There are so many different programming styles. And most often the code is documented poorly. So, how to do it properly and save the time?</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1.<span style="white-space: pre;"> </span>Gather all documentation of code if it is available. What framework or library was used? Was a CMS used? If so, you are in luck as these are more or less documented. Not always, though. If the basis used is branded as “software”, the documentation is typically lacking. It is assumed that you don’t need to modify ready to go software.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2.<span style="white-space: pre;"> </span>Try to map code on some known framework/pattern/approach. If there is clear separation from business logic, database tables and visual representation, you can try to approach the code using MVC. If there is separation between data processing and representation, then it is template based approach. Maybe the system is hook based? This will help to understand how programmers think. Worst kind of code is when business logic calls representation logic which calls some different business logic and so on. Then it might be a mess, especially if you can’t get why programmers decided to do so. Usually there is a different separation taking place between first and second layers of business logic, though sometimes this can be called “quick hack to output specific info” only.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">3.<span style="white-space: pre;"> </span>Try to identify file deployment structure and write it down. Where are configuration files, templates, classes located? What is structure based on?</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">4.<span style="white-space: pre;"> </span>Draw a basic request scheme on paper. What files/modules the request passes till result is send to the user? This will help you to better understand the software.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">5.<span style="white-space: pre;"> </span>Identify places you need to make modifications. The best help is simply stopping execution in various places of file and seeing what data you have at these places. Die(), echo and print_r are the best friends.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">6.<span style="white-space: pre;"> </span>Stick to commenting out old code and commenting changes you make. Make it easy to undo your changes, and make it easy to understand what you have done.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">7.<span style="white-space: pre;"> </span>Last, but not least, test everything.</div>
<p>Quite often I am hired to perform modifications in other web projects done by someone else.  This might be an unmaintained website bought ages ago, or when programmers mess up. It is tough to analyze your own code after couple of years from creation. It is much harder to analyze code of someone else. There are so many different programming styles. And most often the code is documented poorly. So, how to do it properly and save the time?</p>
<ol>
<li>Gather all documentation of code if it is available. What framework or library was used? Was a CMS used? If so, you are in luck as these are more or less documented. Not always, though. If the basis used is branded as “software”, the documentation is typically lacking. It is assumed that you don’t need to modify ready to go software.</li>
<li>Try to map code on some known framework/pattern/approach. If there is clear separation from business logic, database tables and visual representation, you can try to approach the code using MVC. If there is separation between data processing and representation, then it is template based approach. Maybe the system is hook based? This will help to understand how programmers think. Worst kind of code is when business logic calls representation logic which calls some different business logic and so on. Then it might be a mess, especially if you can’t get why programmers decided to do so. Usually there is a different separation taking place between first and second layers of business logic, though sometimes this can be called “quick hack to output specific info” only.</li>
<li>Try to identify file deployment structure and write it down. Where are configuration files, templates, classes located? What is structure based on?</li>
<li>Draw a basic request scheme on paper. What files/modules the request passes till result is send to the user? This will help you to better understand the software.</li>
<li>Identify places you need to make modifications. The best help is simply stopping execution in various places of file and seeing what data you have at these places. Die(), echo and print_r are the best friends.</li>
<li>Stick to commenting out old code and commenting changes you make. Make it easy to undo your changes, and make it easy to understand what you have done.</li>
<li>Last, but not least, test everything.</li>
</ol>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/7-tips-on-web-programming-code-analysis/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make really unsafe session management (that is still used today)</title>
		<link>http://www.majauskas.com/how-to-make-really-unsafe-session-management-that-is-still-used-today</link>
		<comments>http://www.majauskas.com/how-to-make-really-unsafe-session-management-that-is-still-used-today#comments</comments>
		<pubDate>Sun, 16 Aug 2009 16:00:15 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=193</guid>
		<description><![CDATA[Today I want to talk about really unproductive topic – that is how to code poorly. Or, more exactly, I am going to pick on my unfavorite  piece of social site again, that is Boonex. We will talk about how one should not implement user sessions and how to do it better. Boonex uses unencrypted [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fhow-to-make-really-unsafe-session-management-that-is-still-used-today"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fhow-to-make-really-unsafe-session-management-that-is-still-used-today&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Today I want to talk about really unproductive topic – that is how to code poorly. Or, more exactly, I am going to pick on my unfavorite  piece of social site again, that is Boonex. We will talk about how one should not implement user sessions and how to do it better.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Boonex uses unencrypted cookies to store session data, that is member ID and hashed member password. Each request Boonex checks database for memberID and password combination. This is to ensure that the person would be logged off the system if password is changed by someone else.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thus, what is the problem with this approach?</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Well, what about making hashed passwords save on PC user logs in? These passwords remain available till user explicitly logs out.  And the hash used is a simple md5 hash which is fast one-way function. You cannot reverse it, but it is susceptible for dictionary or brute force attacks. There are databases for such md5 strings as well.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">You could partly solve that problem by using a seed with the hashed password. However, it would make the password guessing game more complex but not impossible. Also, you do not need the password for being logged in, just the cookies. And it is quite simple to change values in them with Firefox.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Another problem we had is with effectiveness of this password checking. It is one of multiple requests that are done on each page load. Even when they are fast, they affected boonex performance, which is quite bad anyways. But caching this information makes a security hole open:  ID could be changed and your system could be compromised.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">It is much safer to save session information on server side.  PHP native session management is much better than what boonex has to offer, thus you should switch to it in the code (I have demo version of boonex  7 on August, it still has this problem).   It is quite some work, but it is worth it. Or, even better, look for some other social network script.</div>
<p>Today I want to talk about really unproductive topic – that is how to code poorly. Or, more exactly, I am going to pick on <a href="http://www.majauskas.com/boonex-bad-programming-example">my unfavorite  piece of social site again, that is Boonex</a>. We will talk about how one should not implement user sessions and how to do it better.<img class="size-thumbnail wp-image-197 alignright" title="boonex" src="http://www.majauskas.com/wp-content/uploads/2009/08/boonex-150x150.jpg" alt="boonex" width="150" height="150" /></p>
<p>Boonex uses unencrypted cookies to store session data, that is member ID and hashed member password. Each request Boonex checks database for memberID and password combination. This is to ensure that the person would be logged off the system if password is changed by someone else.</p>
<p>Thus, what is the problem with this approach?</p>
<p>Well, what about making hashed passwords save on PC user logs in? These passwords remain available till user explicitly logs out.  And the hash used is a simple md5 hash which is fast one-way function. You cannot reverse it, but it is susceptible for dictionary or brute force attacks. There are databases for such md5 strings as well.</p>
<p>You could partly solve that problem by using a seed with the hashed password. However, it would make the password guessing game more complex but not impossible. Also, you do not need the password for being logged in, just the cookies. And it is quite simple to change values in them with Firefox.</p>
<p>Another problem we had is with effectiveness of this password checking. It is one of multiple requests that are done on each page load. Even when they are fast, they affected boonex performance, which is quite bad anyways. But caching this information makes a security hole open:  ID could be changed and your system could be compromised.</p>
<p>It is much safer to save session information on server side.  PHP native session management is much better than what boonex has to offer, thus you should switch to it in the code (I have demo version of boonex  7 on August, it still has this problem).   It is quite some work, but it is worth it. Or, even better, look for some other social network script.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/how-to-make-really-unsafe-session-management-that-is-still-used-today/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When Google analytics is not enough: monitoring bad links</title>
		<link>http://www.majauskas.com/when-google-analytics-is-not-enough-monitoring-bad-links</link>
		<comments>http://www.majauskas.com/when-google-analytics-is-not-enough-monitoring-bad-links#comments</comments>
		<pubDate>Mon, 10 Aug 2009 17:00:01 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SEM]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[awstats]]></category>
		<category><![CDATA[google analytics]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=187</guid>
		<description><![CDATA[Google analytics does good job at monitoring pages visited, but what about pages that are not found on your server and thus never displayed? You can get these pages by moving the content around, having errors in your links, getting malformed links from various webmasters (often they are caused by bad software on their side [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fwhen-google-analytics-is-not-enough-monitoring-bad-links"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fwhen-google-analytics-is-not-enough-monitoring-bad-links&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>Google analytics does good job at monitoring pages visited, but what about pages that are not found on your server and thus never displayed? You can get these pages by moving the content around, having errors in your links, getting malformed links from various webmasters (often they are caused by bad software on their side or miscommunication) or for other reasons. Even a soft like wordpress does not check comment links, which might generate 404 errors (page not found).  How to detect such links? Well, you have 3 choices, each of them have their own drawbacks.</p>
<p>1.	<a href="http://www.google.com/webmasters">Google webmaster tools</a>. Adding your site to google webmaster tools is good idea, and there you will get information about links not found. It is most simple way, but worst as well. This is because Google detects the links that are linked and indexed. However, there might be plenty other links that need to be taken care of. For example, advertisement campaigns use non-followed (often javascript) links.</p>
<p>2.	Log analysis. That is the best method if you have access to log files and you can process them. I prefer using <a href="http://www.awstats.org/">Awstats</a> for that, however you can do it by hand for smaller sites on apache, as errors are logged to separate file as well. The single problem with manual analysis is that error log has less information than common log. There is no referrer link mentioned in the error log. However, this can be solved by using grep to scan access log for 404 error codes as well. The drawback is that some CMS processes all requests and do not generate error codes successfully. This means that you will not see such errors in logs even if they exist.</p>
<p>3.	If you can’t access error logs, the best way of action is to use custom error pages and create a log from them. You have to log both referrer path and request uri for best result.  This approach can be implemented in many of the abovementioned CMS’es too.</p>
<p>So, what to do with bad links? This depends on what causes these links. If it is an advertisement campaign or a referrer site, you will have to create a redirect from bad link to the appropriate good one. In cases this is a malformed comment link, I would just delete it from database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/when-google-analytics-is-not-enough-monitoring-bad-links/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>10 Tips how to save a day on a sudden traffic spike</title>
		<link>http://www.majauskas.com/10-tips-how-to-save-a-day-on-a-sudden-traffic-spike</link>
		<comments>http://www.majauskas.com/10-tips-how-to-save-a-day-on-a-sudden-traffic-spike#comments</comments>
		<pubDate>Thu, 06 Aug 2009 17:00:22 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[traffic]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=182</guid>
		<description><![CDATA[A traffic spike might be a joy for marketing department after successful advertising placement or a viral campaign. However, you will not be able to use up that traffic if your website is not loading properly. And that is quite common: no one likes to pay for more hardware than it is necessary during “normal [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2F10-tips-how-to-save-a-day-on-a-sudden-traffic-spike"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2F10-tips-how-to-save-a-day-on-a-sudden-traffic-spike&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">A traffic spike might be a joy for marketing department after successful advertising placement or a viral campaign. However, you will not be able to use up that traffic if your website is not loading properly. And that is quite common: no one likes to pay for more hardware than it is necessary during “normal operation”. I have seen major local news sites shutting down during such spikes, and had experienced such spikes myself as well. And it is up to whole IT team to solve the issue as fast as possible. So, what to do?</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1.<span style="white-space: pre;"> </span>Identify what causes server problems and what one can do to improve. Typical bottlenecks are disk access, database query amount, http and mysql process limits, and memory amount available for all the processes.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2.<span style="white-space: pre;"> </span>Check what pages are hit heavily. This can be done by examining http server logs, or (at worst case) setting Google analytics date to current day.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">3.<span style="white-space: pre;"> </span>Check if caching works as intended. Check if mysql cache is turned on (This is fast one, and quite important), and if enough memory is assigned to mysql cache.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">4.<span style="white-space: pre;"> </span>If it is possible, upgrade today. VDS upgrades can be done instantaneous. That is one of reasons I have started to love them. In other cases, it is not so fast, but you might get more memory installed quite quickly.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">5.<span style="white-space: pre;"> </span>Tune the http process children amount. You do not want to have more of them than fit into memory, remaining from system processes and mysql. Swapping these processes is a really bad idea. This might need to be repeated if memory amount changes.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">6.<span style="white-space: pre;"> </span>After doing easy stuff, time for more complex ones. You might have to implement easy version of page caching on heavily hit pages if this is feasible. If you code with PHP, this might be done with output buffer module.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">7.<span style="white-space: pre;"> </span>Done easy caching but still no improvement? If the problem is database, time to dig into database queries. Turn database logging on for minute or two, then revert for version without logging. Also, it is worth checking slow queries with slow query log setting at mysql. You have to identify a) Slow queries b) queries that repeat multiple times during the page load c) queries that return same information for majority of pages (for example, some static block like recent articles).  First type of queries should be rewritten if possible. Second type of queries should be eliminated by reusing the information. Third type of queries means that fragment of pages needs pre-cached elements.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">8.<span style="white-space: pre;"> </span>As long as you look at the queries, check if there are multiple versions of the same queries. Rewrite them to look the same. Mysql can not cache queries if they are written differently (even when only case differs).</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">9.<span style="white-space: pre;"> </span>Also, you might want to turn some things off during peak times. Like page view counter (in worst case), some cron jobs.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">10.<span style="white-space: pre;"> </span>Disk still heavily in use? Check if you can reduce how many http child processes are required to display the page. Move some elements to sprites. Or move images to different webserver if possible. Use single css file instead of multiple. And so on.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Anything else? Please comment bellow.</div>
<p>A traffic spike might be a joy for marketing department after successful advertising placement or a viral campaign. However, you will not be able to use up that traffic if your website is not loading properly. And that is quite common: no one likes to pay for more hardware than it is necessary during “normal operation”. I have seen major local news sites shutting down during such spikes, and had experienced such spikes myself as well. And it is up to whole IT team to solve the issue as fast as possible. So, what to do?</p>
<ol>
<li>Identify what causes server problems and what one can do to improve. Typical bottlenecks are disk access, database query amount, http and mysql process limits, and memory amount available for all the processes.</li>
<li>Check what pages are hit heavily. This can be done by examining http server logs, or (at worst case) setting Google analytics date to current day. There are log analytic software, but you will probably see with the naked eye what pages occur most often. &#8220;grep&#8221; might help in this case too, by excluding images from your search.</li>
<li>Check if caching works as intended. <a href="http://www.techiecorner.com/45/turn-on-mysql-query-cache-to-speed-up-mysql-query-performance/" target="_blank">Check if mysql cache is turned on </a>(This is fast one, and quite important), and if enough memory is assigned to mysql cache. Mysql caching is switched off by default.</li>
<li>If it is possible, upgrade today. VDS upgrades can be done instantaneous. That is one of reasons I have started to love them. In other cases, it is not so fast, but you might get more memory installed quite quickly.</li>
<li>Tune the http process children amount (if you use Apache). You do not want to have more of them than fit into memory, remaining from system processes and mysql. Swapping these processes is a really bad idea. This might need to be adjusted if memory amount changes.</li>
<li>After doing easy stuff, time for more complex ones. You might have to implement easy version of page caching on heavily hit pages if this is feasible. If you code with PHP, this might be done with <a href="http://us2.php.net/manual/en/book.outcontrol.php">output buffer control</a> module.</li>
<li>Done easy caching but still no improvement? If the problem is database, time to dig into database queries. <a href="http://dev.mysql.com/doc/refman/5.1/en/query-log.html" target="_blank">Turn database logging on</a> for minute or two, then revert for version without logging. Also, it is worth checking slow queries with <a href="http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html" target="_blank">slow query log</a> at mysql. You have to identify a) Slow queries b) queries that repeat multiple times during the page load c) queries that return same information for majority of pages (for example, some static block like recent articles).  First type of queries should be rewritten if possible. Second type of queries should be eliminated by reusing the information. Third type of queries means that fragment of pages needs pre-cached elements.</li>
<li>As long as you look at the queries, check if there are multiple versions of the same queries. Rewrite them to look the same. Mysql can not cache queries if they are written differently (even when only case differs).</li>
<li>Also, you might want to turn some things off during peak times. Like page view counter (in worst case), some cron jobs.</li>
<li>Disk still heavily in use? Check if you can reduce how many http child processes are required to display the page. Move some elements to sprites. Or move images to different webserver if possible. Use single css file instead of multiple. And so on. It is worth considering using lighttpd for showing images instead of apache.</li>
</ol>
<p>Overall, it is better to be prepared for traffic spike than be surprised by it. However, in lot of cases even on dire server loads there are things, that can be done so users would not notice any downtime and marketing campaign would not go in vain.</p>
<p>Anything else? Please comment bellow.</p>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/10-tips-how-to-save-a-day-on-a-sudden-traffic-spike/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 things to look at when comparing php frameworks</title>
		<link>http://www.majauskas.com/things-to-look-at-when-comparing-php-frameworks</link>
		<comments>http://www.majauskas.com/things-to-look-at-when-comparing-php-frameworks#comments</comments>
		<pubDate>Thu, 11 Jun 2009 15:38:13 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=152</guid>
		<description><![CDATA[I had read a post at sitepoints about 16 php 5 frameworks. I will not argue the fact that frameworks are good and you should use one. What saddens me is that the key points of comparison are omitted in the post. So, how to compare different php 5 frameworks? Let us see. 1. Paradigms [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fthings-to-look-at-when-comparing-php-frameworks"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fthings-to-look-at-when-comparing-php-frameworks&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>I had read a post at <a href="http://www.sitepoint.com/blogs/2009/06/09/16-php-frameworks/">sitepoints about 16 php 5 frameworks</a>. I will not argue the fact that frameworks are good and you should use one. What saddens me is that the key points of comparison are omitted in the post.</p>
<p>So, how to compare different php 5 frameworks? Let us see.</p>
<p>1.	Paradigms used. Although MVC is mainstream now, it is not a single paradigm in php development. There are frameworks that are event based only. Additionally, there are different paradigms for different application layers, for example <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> for database (model) layer, pretty well supported in php cake.  Zend does not have module layer at all, you need to use your own database access, as example.</p>
<p>2.	Modularity and reusability of framework. Although MVC provides modularity on controller- basis, additional modularity is required to re-use code between applications. This is important for developing bigger project that share modules.</p>
<p>3.	Php version support.  Some frameworks require specific versions of php5. This means that you have limited options for hosting.</p>
<p>4.	Shared hosting support. You might need that before project kicks in. Some frameworks behave weirdly on shared hosting, as they need specific setup.</p>
<p>5.	Proof of concept and maturity. Have you seen applications developed with the framework? Is framework developer community active or dormant? I would shun a framework without some real-world example sites.</p>
<p>Have something to add? Comment bellow!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/things-to-look-at-when-comparing-php-frameworks/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
