<?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>Geekality &#187; Tutorial</title>
	<atom:link href="http://www.geekality.net/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.geekality.net</link>
	<description>With a hint of Social Ineptitude</description>
	<lastBuildDate>Thu, 26 Aug 2010 17:44:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP: Generating transparent PNG fillers</title>
		<link>http://www.geekality.net/2010/06/13/php-generating-transparent-png-fillers/</link>
		<comments>http://www.geekality.net/2010/06/13/php-generating-transparent-png-fillers/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 13:45:38 +0000</pubDate>
		<dc:creator>Torleif</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[GD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.geekality.net/?p=1003</guid>
		<description><![CDATA[So, I was fooling around the other day with an HTML table and wanted to make the odd rows slightly darker. Figured I could use for example an 80% transparent black PNG to do that (or could have just assigned &#8230; <a href="http://www.geekality.net/2010/06/13/php-generating-transparent-png-fillers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So, I was fooling around the other day with an HTML table and wanted to make the odd rows slightly darker. Figured I could use for example an 80% transparent black PNG to do that (or could have just assigned a darker color, but where&#8217;s the fun in that?). Either way, ended up making a little something that I thought I could share just for the fun of it. I learned a few things, so maybe someone else can too <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':)' title=':)' class='wp-smiley smiley-1' /> </p>
<p>So, here&#8217;s how to make a small transparent PNG filler image on-the-fly using PHP <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':)' title=':)' class='wp-smiley smiley-1' /> </p>
<p><span id="more-1003"></span></p>
<p>I called the script <em>fill.php</em>, and the first line looks like this:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>This starts the php script and sets the content-type to image/png which means the web browser will that we are an image and not an html file which usually is the default.</p>
<p>Next up we get the parameters from the user:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span> <span style="color: #339933;">+</span> <span style="color: #990000;">array</span><br />
<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'r'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'g'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Here I create an array with default values and merge it with the <code class="codecolorer php default"><span class="php"><span style="color: #000088;">$_GET</span></span></code> array so that values from the user will override the default values. This means we are sure we have all the values we need and that the user only have to specify the ones he want to.</p>
<p>The r, g and b values should be a number between 0 and 255 and the alpha value should be between 0 and 127. So, next up we need to make sure that that is the case so we don&#8217;t use some other bogus we might have gotten:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #990000;">array_walk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$item</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$item</span> <span style="color: #339933;">=</span> <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'a'</span> ? <span style="color: #cc66cc;">127</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>This goes through each parameter and makes sure it is a number between 0 and 255 (or 127 for the alpha).</p>
<p>Since we have what we need now, we can start with creating our image:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$img</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cannot Initialize new GD image stream'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>We also need to set a flag that we want to use full alpha channel information (as opposed to single-color transparency) in this image:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #990000;">imagesavealpha</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>We are now ready to fill our image with the color we are asked for:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocatealpha</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$p</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$p</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'g'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$p</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$p</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">imagefill</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$color</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>And finally output the result and destroy the image resource we have been working with:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>And that&#8217;s actually all there is to it!</p>
<p>The complete code looks like this:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">// Replace default parameters with user input</span><br />
<span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span> <span style="color: #339933;">+</span> <span style="color: #990000;">array</span><br />
<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'r'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'g'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Make sure they are within limits</span><br />
<span style="color: #666666; font-style: italic;">// (colors: 0-255, alpha: 0-127)</span><br />
<span style="color: #990000;">array_walk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$val</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'a'</span> ? <span style="color: #cc66cc;">127</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
<br />
<span style="color: #666666; font-style: italic;">// Create image</span><br />
<span style="color: #000088;">$img</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cannot Initialize new GD image stream'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Use full alpha channel information</span><br />
<span style="color: #990000;">imagesavealpha</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Fill image</span><br />
<span style="color: #000088;">$color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocatealpha</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$p</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$p</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'g'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$p</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$p</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">imagefill</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$color</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">// Output result</span><br />
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>If you want to check out a working demo version of this, you can test out my little testing tool I created while having fun with this at <a href="http://tools.geekality.net/filling-factory/">tools.geekality.net/filling-factory</a></p>
<p>Let me know what you think! And as usual, please let me know if you see something that is wrong or could be improved or anything like that  <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':)' title=':)' class='wp-smiley smiley-1' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekality.net/2010/06/13/php-generating-transparent-png-fillers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to reset the MySql root account</title>
		<link>http://www.geekality.net/2008/12/27/how-to-reset-the-mysql-root-account/</link>
		<comments>http://www.geekality.net/2008/12/27/how-to-reset-the-mysql-root-account/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 16:38:24 +0000</pubDate>
		<dc:creator>Torleif</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.geekality.net/?p=55</guid>
		<description><![CDATA[I just managed to mess up the MySQL root account. Not a smart idea. After some MySQL manual reading and some serious Google-Fu, I figured out how to fix it. Stop the mysql server Add the following to the my.cnf &#8230; <a href="http://www.geekality.net/2008/12/27/how-to-reset-the-mysql-root-account/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just managed to mess up the MySQL root account. Not a smart idea. After some MySQL manual reading and some serious Google-Fu, I figured out how to fix it.</p>
<ol>
<li>Stop the mysql server</li>
<li>Add the following to the my.cnf file
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>mysqld<span style="">&#93;</span></span><br />
skip-grant-tables</div></div>
</li>
<li>Start the mysql server</li>
<li>Start a mysql client and run the following query
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">INTO</span> mysql<span style="color: #66cc66;">.</span>user <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'localhost'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'root'</span><span style="color: #66cc66;">,</span>PASSWORD<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'blah'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;</div></div>
</li>
<li>Quit the mysql client</li>
<li>Stop the mysql server</li>
<li>Remove what we added to my.cnf in step 2</li>
<li>Restart the mysql server</li>
</ol>
<p>Tadaa.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekality.net/2008/12/27/how-to-reset-the-mysql-root-account/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use assembly embedded resources</title>
		<link>http://www.geekality.net/2008/12/27/how-to-use-assembly-embedded-resources/</link>
		<comments>http://www.geekality.net/2008/12/27/how-to-use-assembly-embedded-resources/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 16:13:16 +0000</pubDate>
		<dc:creator>Torleif</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Embedded Resources]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.geekality.net/?p=62</guid>
		<description><![CDATA[After some digging around, I found that it actually wasn&#8217;t that difficult at all. Getting it in Putting something in an assembly as an embedded resource is pretty easy. At least if you are using Visual Studio. Just add the &#8230; <a href="http://www.geekality.net/2008/12/27/how-to-use-assembly-embedded-resources/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After some digging around, I found that it actually wasn&#8217;t that difficult at all.</p>
<h2>Getting it in</h2>
<p>Putting something in an assembly as an embedded resource is pretty easy. At least if you are using Visual Studio. Just add the file to your project, click on it, and then under Properties set Build Action to Embedded Resource. And thats it!</p>
<h2>Getting it out</h2>
<p>Lets say we want an image called <em>hello.png</em> in a folder called <em>Wopdidoo</em> as a Stream.</p>
<p>If we are executing code in the same assembly, we can do as follows:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Assembly assembly <span style="color: #008000;">=</span> Assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetExecutingAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
Stream imageStream <span style="color: #008000;">=</span> assembly<br />
&nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0000FF;">GetManifestResourceStream</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;DefaultNameSpaceOfAssembly.Wopdidoo.hello.png&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>If you are not executing code in the same assembly you just have to get that assembly reference in a different way. I often use <code class="codecolorer csharp default"><span class="csharp">Assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span></span></code>, where T is some type you know exists in the same assembly as the file you want. The rest is the same.</p>
<p>As far as I know, you use the stream as any other stream. Not sure if it is writable though? Probably not&#8230; let me know if you have some brilliant clues on that matter <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':)' title=':)' class='wp-smiley smiley-1' /> </p>
<p> <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':?:' title=':?:' class='wp-smiley smiley-23' /> Remember to Dispose it when you are done.</p>
<h2>Finding it</h2>
<p>I sometimes find it a bit difficult to figure out that string which identifies the resource. I then often use the following code to &#8220;find&#8221; it:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> s <span style="color: #0600FF; font-weight: bold;">in</span> assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetManifestResourceNames</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Debug</span><span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>s<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>It basically just scans through all the resource names and prints them out to the debug console <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':)' title=':)' class='wp-smiley smiley-1' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekality.net/2008/12/27/how-to-use-assembly-embedded-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
