<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>folksonomy</title>
	
	<link>http://www.folksonomy.org</link>
	<description>for the well rounded Internet entrepreneur</description>
	<lastBuildDate>Tue, 10 Nov 2009 01:15:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/folksonomy" type="application/rss+xml" /><feedburner:emailServiceId>folksonomy</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>The Disk You Inserted Was Not Readable by this Computer</title>
		<link>http://feedproxy.google.com/~r/folksonomy/~3/cQaPcv0mZ6A/</link>
		<comments>http://www.folksonomy.org/2009/11/09/the-disk-you-inserted-was-not-readable-by-this-computer/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 01:15:42 +0000</pubDate>
		<dc:creator>Michael Zhang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[boot]]></category>
		<category><![CDATA[bootsector]]></category>
		<category><![CDATA[corrupted]]></category>
		<category><![CDATA[corruption]]></category>
		<category><![CDATA[diskwarrior]]></category>
		<category><![CDATA[drive]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[externalharddrive]]></category>
		<category><![CDATA[readable]]></category>
		<category><![CDATA[recover]]></category>
		<category><![CDATA[testdisk]]></category>

		<guid isPermaLink="false">http://www.folksonomy.org/?p=372</guid>
		<description><![CDATA[This post comes at the end of a day&#8217;s worth of technical troubleshooting after I ran into a pretty devastating problem today. I&#8217;ll start from the beginning:
My fellow youth group staff and I use a program called CovenantEyes for Internet accountability. It&#8217;s a terrific program that works very well, except for one annoying issue on [...]]]></description>
			<content:encoded><![CDATA[<p>This post comes at the end of a day&#8217;s worth of technical troubleshooting after I ran into a pretty devastating problem today. I&#8217;ll start from the beginning:</p>
<p>My fellow youth group staff and I use a program called CovenantEyes for Internet accountability. It&#8217;s a terrific program that works very well, except for one annoying issue on my MacBook Pro: It regularly causes kernel panics, which means my screen grays out and a message appears, telling me that I have to reboot my computer. I can&#8217;t backup what I&#8217;m working on or anything.</p>
<p>Anyhow, while I had my 500GB external harddrive plugged in and mounted today, CovenantEyes caused a kernel panic. After rebooting my computer, I discovered that I couldn&#8217;t access the drive. When I plugged in the drive in, an error would pop up saying, &#8220;<strong>The disk you inserted was not readable by this computer</strong>&#8220;, and gave me the options <strong>Initialize</strong>, <strong>Ignore</strong>, and <strong>Eject</strong>.</p>
<p>When I clicked Initialize, the Disk Utility popped up, but all the repair/recovery options were grayed out. There was nothing I could do. The computer could detect the drive, but could not repair it.</p>
<p><img src="http://www.folksonomy.org/assets/2009/11/disk_insertion.png" alt="disk_insertion" title="disk_insertion" width="400" height="146" class="aligncenter size-full wp-image-375" /></p>
<p>I suspected that the drive had gotten corrupted, even though I wasn&#8217;t using it at all at the time of the kernel panic. This problem never happened to me back when I used a PC, even though I pulled out USBs left and right without &#8220;safely stopping&#8221; the drives.</p>
<p>After poking around on the Internet, everyone seemed to recommend a program called DiskWarrior. They claimed that it almost always helped rebuild hard drives even when they&#8217;re unmountable.</p>
<p>With seemingly no other options, I shelled out $110 and purchased a copy of DiskWarrior. After all, I have a lifetimes worth of memories stored on this hard drive (I have most of it backed up on DVDs, but haven&#8217;t done so in the past half year).</p>
<p>When I opened up DiskWarrior, I was shocked to see that there was nothing it could do. The program displayed an error saying that the drive wasn&#8217;t formatted for Macs, so there was no way it could rebuild it.</p>
<p>At this point I realized that the disk wasn&#8217;t a HFS (Mac&#8217;s file system) formatted disk, but was instead formatted as FAT32. Thus, I had no choice but to wait a few hours until my roommate got home, so I could use his Windows XP laptop to attempt a recovery.</p>
<p>Once I was on his computer, I plugged in the drive and received the following error, &#8220;<strong>Drive E: is not formatted.</strong>&#8220;, and prompted me on whether to format it or not. Obviously I chose not to.</p>
<p>After poking around a bit more on the Internet, I saw that a lot of people mentioned a utility called TestDisk, which is free and available for most (if not all) operating systems. It&#8217;s extremely lightweight, and doesn&#8217;t even require an installation.</p>
<p>Here are the steps for what to do:</p>
<ol>
<li>Choose a logging method (I chose <strong>No Log</strong>)
<li>Select the drive you&#8217;re trying to fix (If your drive doesn&#8217;t show up, it&#8217;s likely that your problem is different)
<li>Select the partition type (It will default to what it thinks the drive is. Most likely it&#8217;s right)
<li>Select <strong>Advanced</strong>
</ol>
<p>Now at this step, my screen looked something like this:</p>
<p><img src="http://www.folksonomy.org/assets/2009/11/repair-2.jpg" alt="repair (2)" title="repair (2)" width="621" height="339" class="aligncenter size-full wp-image-377" /></p>
<p>Notice how it tells you the status of your main boot sector and your backup boot sector. In my case, it said &#8220;<strong>Bad</strong>&#8221; under the main one and &#8220;<strong>Good</strong>&#8221; under the backup one. If this is the case for you as well, all you need to do is select &#8220;<strong>[Backup BS]</strong>&#8220;. What this does is recover the main boot sector using the backup one.</p>
<p>This &#8220;fix&#8221; literally takes less than a second (there&#8217;s a confirmation page). It then takes you back to the previous page and shows &#8220;<strong>Good</strong>&#8221; under both boot sectors.</p>
<p>Suddenly, I was able to access my external hard drive again, and everything was as good as new.</p>
<p>Wasted $110 on DiskWarrior for Mac, but at least it still has some usefulness and I learned a lot about disks along the way.</p>
<p>Hopefully this is helpful if anyone runs into the same problem I did.</p>
<hr />
<p>There&#8217;s quite a lot that&#8217;s good about Macs and Mac OSX. However, I still feel like Windows wins in big ways. For example, DiskWarrior costs $99 and there isn&#8217;t even a demo to test whether it will actually fix your problem. TestDisk is free, and doesn&#8217;t even require an install (though it IS available for Mac too&#8230;).</p>
<p>I think Mac is WAY too proprietary. Next comes Windows. Then comes Linux. Haha.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.folksonomy.org/2009/11/09/the-disk-you-inserted-was-not-readable-by-this-computer/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		<feedburner:origLink>http://www.folksonomy.org/2009/11/09/the-disk-you-inserted-was-not-readable-by-this-computer/</feedburner:origLink></item>
		<item>
		<title>Getting the Text Between HTML Tags in PHP</title>
		<link>http://feedproxy.google.com/~r/folksonomy/~3/aU72JV1IV04/</link>
		<comments>http://www.folksonomy.org/2009/10/08/getting-the-text-between-html-tags-in-php/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 01:28:45 +0000</pubDate>
		<dc:creator>Michael Zhang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[extract]]></category>
		<category><![CDATA[extracting]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://www.folksonomy.org/?p=364</guid>
		<description><![CDATA[Suppose you&#8217;re automatically parsing a webpage, and you come across the following kind of thing:
blah blah
some starting text
some useful content
some ending text
blah blah
We want to parse out the useful content from among the non-useful stuff, and we know there&#8217;s some starting text and some ending text that wraps the useful content.
A better example:
I like chicken
&#60;div [...]]]></description>
			<content:encoded><![CDATA[<p>Suppose you&#8217;re automatically parsing a webpage, and you come across the following kind of thing:</p>
<pre class="syntax-highlight:html">blah blah
some starting text
some useful content
some ending text
blah blah</pre>
<p>We want to parse out the useful content from among the non-useful stuff, and we know there&#8217;s some starting text and some ending text that wraps the useful content.</p>
<p>A better example:</p>
<pre class="syntax-highlight:html">I like chicken
&lt;div class=&quot;dog&quot; style=&quot;border: 0px&quot;&gt;
     I don&#039;t like to eat fish
&lt;/div&gt;
&lt;div class=&quot;fish&quot;&gt;
I like to eat pork
&lt;/div&gt;</pre>
<p>How can we obtain just the text between the divs if we know the exact code that is immediately before and immediately after? </p>
<p>Here&#8217;s a PHP function you can use to accomplish this. It only uses the <strong>split()</strong> function:</p>
<pre class="syntax-highlight:php">&lt;?php
function get_stuff_between($string, $start, $end){
	$content = split($start, $string);
	$content = split($end, $content[1]);
	return $content[0];
}
?&gt;</pre>
<p>If we have the example HTML code stored in the string <strong>$content</strong>, then we can obtain the text we want by calling the function like this:</p>
<pre class="syntax-highlight:php">get_stuff_between($content, &#039;&lt;div class=&quot;dog&quot; style=&quot;border: 0px&quot;&gt;&#039;, &#039;&lt;/div&gt;
&lt;div class=&quot;fish&quot;&gt;&#039;);</pre>
<p>This returns the string</p>
<p><strong>I don&#8217;t like to eat fish</strong></p>
<p>Note that this requires the start and end strings be unique in the document, though it&#8217;s often pretty common for there to be such unique strings immediately before and after the content you want to parse.</p>
<p>The practical application for something like this is if you&#8217;re automatically parsing many HTML documents, and you&#8217;d like to extract only a portion of each document that&#8217;s neatly delimited by invariant tags.</p>
<p>There&#8217;s probably more flexible ways of doing this using preg_grep or preg_match_all, but I found this way to be easy and sufficient for what I needed to do today.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.folksonomy.org/2009/10/08/getting-the-text-between-html-tags-in-php/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		<feedburner:origLink>http://www.folksonomy.org/2009/10/08/getting-the-text-between-html-tags-in-php/</feedburner:origLink></item>
		<item>
		<title>Scramblizer – Scrambling Your Text to Confuse Your Friends</title>
		<link>http://feedproxy.google.com/~r/folksonomy/~3/oR8GMMiFJuc/</link>
		<comments>http://www.folksonomy.org/2009/10/06/scramblizer-scrambling-your-text-to-confuse-your-friends/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 05:38:17 +0000</pubDate>
		<dc:creator>Michael Zhang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[sandbox]]></category>
		<category><![CDATA[scramble]]></category>
		<category><![CDATA[scramblizer]]></category>

		<guid isPermaLink="false">http://www.folksonomy.org/?p=353</guid>
		<description><![CDATA[Was chatting with some youth groupers this evening when one of them started typing in text that was upside down. When we asked how did he it, he linked us to this page.
I tried fooling around with the app a little, and decided to confuse the youth groupers even more by only flipping every other [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://folksonomy.org/sandbox/scramblizer/"><img src="http://www.folksonomy.org/assets/2009/10/scramblizer.jpg" alt="scramblizer" title="scramblizer" width="250" height="54" class="alignleft size-full wp-image-356" /></a>Was chatting with some youth groupers this evening when one of them started typing in text that was upside down. When we asked how did he it, he linked us to <a href="http://www.sevenwires.com/play/UpsideDownLetters.html">this page</a>.</p>
<p>I tried fooling around with the app a little, and decided to confuse the youth groupers even more by only flipping every other word. This paragraph would end up looking like this:</p>
<blockquote><p>i pǝıɹʇ fooling punoɹɐ with ǝɥʇ app ɐ little, puɐ decided oʇ confuse ǝɥʇ youth sɹǝdnoɹƃ even ǝɹoɯ by ʎןuo flipping ʎɹǝʌǝ other ˙pɹoʍ this ɥdɐɹƃɐɹɐd would puǝ up ƃuıʞooן like :sıɥʇ</p></blockquote>
<p>Haha.</p>
<p>So anyhow. I decided to quickly make another &#8220;sandbox project&#8221; that allows you to flip every other word like this. It&#8217;s called <a href="http://folksonomy.org/sandbox/scramblizer/">scramblizer</a>. Completely useless, but might be fun for playing a trick on your friends.</p>
<p>Maybe if there&#8217;s other interesting transformations I can add it to the app in the future.</p>
<p><a href="http://folksonomy.org/sandbox/scramblizer/"><img src="http://www.folksonomy.org/assets/2009/10/scramblescreen.jpg" alt="scramblescreen" title="scramblescreen" width="500" height="408" class="aligncenter size-full wp-image-358" /></a></p>
<hr />
<p><strong>Update on 10/7/09:</strong> Just added options for choosing how you&#8217;d like your words scrambled. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.folksonomy.org/2009/10/06/scramblizer-scrambling-your-text-to-confuse-your-friends/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.folksonomy.org/2009/10/06/scramblizer-scrambling-your-text-to-confuse-your-friends/</feedburner:origLink></item>
		<item>
		<title>Invalid Authenticity Token Error in Rails</title>
		<link>http://feedproxy.google.com/~r/folksonomy/~3/au3YJL5lheg/</link>
		<comments>http://www.folksonomy.org/2009/09/19/invalid-authenticity-token-error-in-rails/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 21:29:47 +0000</pubDate>
		<dc:creator>Michael Zhang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">http://www.folksonomy.org/?p=348</guid>
		<description><![CDATA[Got the following error today when trying to submit a form in Ruby on Rails:
ActionController::InvalidAuthenticityToken
The solution turned out to be as easy as inserting

into my form.
[via Nabble]
]]></description>
			<content:encoded><![CDATA[<p>Got the following error today when trying to submit a form in Ruby on Rails:</p>
<blockquote><p>ActionController::InvalidAuthenticityToken</p></blockquote>
<p>The solution turned out to be as easy as inserting</p>
<p><strong><%= token_tag %></strong></p>
<p>into my form.</p>
<p>[via <a href="http://www.nabble.com/ActionController::InvalidAuthenticityToken-in-LoginController-td14861110.html">Nabble</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.folksonomy.org/2009/09/19/invalid-authenticity-token-error-in-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.folksonomy.org/2009/09/19/invalid-authenticity-token-error-in-rails/</feedburner:origLink></item>
		<item>
		<title>Twitter’s New Link Tracking is No Good</title>
		<link>http://feedproxy.google.com/~r/folksonomy/~3/tLd4otu1wck/</link>
		<comments>http://www.folksonomy.org/2009/09/04/twitters-new-link-tracking-is-no-good/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 16:42:57 +0000</pubDate>
		<dc:creator>Michael Zhang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[change]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[tracking]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://www.folksonomy.org/?p=343</guid>
		<description><![CDATA[Twitter changed how links work recently, so now when you click a link the first thing that actually loads is something like:
http://twitter.com/link_click_count?url=STUFF
I don&#8217;t like it.
First off, it&#8217;s messier. Instead of clicking through normal links now we&#8217;re getting redirected for internal links. That&#8217;s weird.
Second, it puts another level of failure and slowness between users and the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.folksonomy.org/assets/2009/09/twitter_logo_header.png" alt="Twitter" title="Twitter" width="155" height="36" class="alignleft size-full wp-image-346" />Twitter changed how links work recently, so now when you click a link the first thing that actually loads is something like:</p>
<p><strong>http://twitter.com/link_click_count?url=STUFF</strong></p>
<p>I don&#8217;t like it.</p>
<p>First off, it&#8217;s messier. Instead of clicking through normal links now we&#8217;re getting redirected for internal links. That&#8217;s weird.</p>
<p>Second, it puts another level of failure and slowness between users and the places they&#8217;re trying to reach via the links. It looks like the redirection/tracking is only happening for internal links, so if twitter is down then the link would probably be down anyway, but I feel like things are a little slower anyway with the intermediate step.</p>
<p>Hmm&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.folksonomy.org/2009/09/04/twitters-new-link-tracking-is-no-good/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.folksonomy.org/2009/09/04/twitters-new-link-tracking-is-no-good/</feedburner:origLink></item>
		<item>
		<title>Spam, Noise, and the Utility of eBay</title>
		<link>http://feedproxy.google.com/~r/folksonomy/~3/MlscK9s-bdQ/</link>
		<comments>http://www.folksonomy.org/2009/09/02/spam-noise-and-the-utility-of-ebay/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 06:11:11 +0000</pubDate>
		<dc:creator>Michael Zhang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[auction]]></category>
		<category><![CDATA[craigslist]]></category>
		<category><![CDATA[ebay]]></category>
		<category><![CDATA[noise]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.folksonomy.org/?p=340</guid>
		<description><![CDATA[I think of the the big reasons I&#8217;ve used eBay less and less over the years is because of how much noise there is now in the service.
In the early days when Yahoo Auctions and eBay were both fighting for the online auction market, online auctions were great in that it was easy to find [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.folksonomy.org/assets/2009/09/logoEbay_x45.gif.png" alt="eBay" title="eBay" width="110" height="45" class="alignleft size-full wp-image-341" />I think of the the big reasons I&#8217;ve used eBay less and less over the years is because of how much noise there is now in the service.</p>
<p>In the early days when Yahoo Auctions and eBay were both fighting for the online auction market, online auctions were great in that it was easy to find something that another person was personally putting up for sale.</p>
<p>Nowadays, eBay is teeming with online retailers and people who build businesses around selling things on the service. Instead of nice, orderly listings from human sellers, every page I look at is mostly filled with duplicate listings of imitation products. There&#8217;s just too much noise.</p>
<p>Craigslist is much more useful (in my opinion) in that the noise is dealt with by the community. Imagine if you could mark auctions in eBay as spam or duplicates.</p>
<p>I have no idea if there&#8217;s any way for eBay to regain its reputation in my eyes. Unless it figures out a way to, I don&#8217;t think I&#8217;m going to be visiting very often.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.folksonomy.org/2009/09/02/spam-noise-and-the-utility-of-ebay/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		<feedburner:origLink>http://www.folksonomy.org/2009/09/02/spam-noise-and-the-utility-of-ebay/</feedburner:origLink></item>
		<item>
		<title>Working with Hex Colors in PHP</title>
		<link>http://feedproxy.google.com/~r/folksonomy/~3/DGPTVaXPVBs/</link>
		<comments>http://www.folksonomy.org/2009/09/02/working-with-hex-colors-in-php/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 18:56:25 +0000</pubDate>
		<dc:creator>Michael Zhang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[hexcolor]]></category>
		<category><![CDATA[hexcolors]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webcolor]]></category>
		<category><![CDATA[webcolors]]></category>

		<guid isPermaLink="false">http://www.folksonomy.org/?p=324</guid>
		<description><![CDATA[I was tinkering with a devotion schedule application this morning, and needed to have an automatically handled font color so that a series of lines would be a gradient. 
Here&#8217;s how to work with automatic gradients (or colors in general) in PHP.
First off, we&#8217;re working with hex. The functions you&#8217;ll find useful are hexdec() and [...]]]></description>
			<content:encoded><![CDATA[<p>I was tinkering with a devotion schedule application this morning, and needed to have an automatically handled font color so that a series of lines would be a gradient. </p>
<p>Here&#8217;s how to work with automatic gradients (or colors in general) in PHP.</p>
<p>First off, we&#8217;re working with hex. The functions you&#8217;ll find useful are <strong>hexdec()</strong> and <strong>dechex()</strong>. hexdec takes a hex number and converts it to decimal, while dechex does the opposite.</p>
<p>In hex, black is #000000, or 00 00 00. These three bytes represent the values for red, green, and blue (RGB) respectively. White is #ffffff, or ff ff ff. Gray colors are any combination in between, as long as the bytes for red, green, and blue are equal. (i.e. d6d6d6, 8e8e8e, 4b4b4b, etc&#8230;)</p>
<p>Thus, to lighten a black, all you need to do is add some value equally to each of the three bytes. (i.e. if you add the hex value 7f to each, you&#8217;ll end up with 7f7f7f, a middle gray.)</p>
<p>Let&#8217;s move on to some code examples&#8230;</p>
<p>I&#8217;ve found it to be useful to represent hex triplets using arrays. This way, you can always <strong>implode()</strong> to obtain the string version. Here&#8217;s how to represent black (#000000).</p>
<pre class="syntax-highlight:php">$color = array(&quot;00&quot;, &quot;00&quot;, &quot;00&quot;);</pre>
<p>If you wanted to use it somewhere, you could just implode it:</p>
<pre class="syntax-highlight:php">&lt;?php
$black = implode($color);
echo &quot;&lt;font style=&#039;color: #{$black}&#039;&gt;Hello this is black font&lt;/font&gt;&quot;;
?&gt;</pre>
<p>Here&#8217;s how you can easily add an equal amount to each value, creating a gray:</p>
<pre class="syntax-highlight:php">for($i = 0; $i &lt; count($color); $i++) {
     $color[$i] = dechex(hexdec($color[$i]) + hexdec(&quot;7f&quot;));
}</pre>
<p>Here&#8217;s an example where we continue to add the value 19 for each div over 6 divs, creating a gradient of divs:</p>
<pre class="syntax-highlight:php">for($c = 0; $c &lt; 6; $c++) {

   $color = array(&quot;00&quot;, &quot;00&quot;, &quot;00&quot;);

   for($i = 0; $i &lt; count($color); $i++) {
      $color[$i] = dechex(hexdec($color[$i]) + hexdec(&quot;19&quot; * $c));
   }

   $color = implode($color);

   echo &quot;&lt;div style=&#039;color: #fff; width: 100px; height: 100px; float: left;
background-color: #{$color};&#039;&gt;{$color}&lt;/div&gt;&quot;;

}
</pre>
<p>Here is what it looks like in action:</p>
<div style='color: #fff; width: 100px; height: 100px; float: left; background-color: #000;'>000</div>
<div style='color: #fff; width: 100px; height: 100px; float: left; background-color: #191919;'>191919</div>
<div style='color: #fff; width: 100px; height: 100px; float: left; background-color: #383838;'>383838</div>
<div style='color: #fff; width: 100px; height: 100px; float: left; background-color: #575757;'>575757</div>
<div style='color: #fff; width: 100px; height: 100px; float: left; background-color: #767676;'>767676</div>
<div style='color: #fff; width: 100px; height: 100px; float: left; background-color: #959595;'>959595</div>
<div style="clear: both; height:1px;font-size:5px; line-height: 1px;">&nbsp;</div>
<p>Neat huh? For dynamic design templates where colors need to be automatically generated based on a user selected base value, you can use this technique to create lighter and darker versions of the user selected color to make the design a little more dynamic.</p>
<p>It could take a little extra hacking though, since universally applying the same algorithm to all user selected colors will create bugs for corner cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.folksonomy.org/2009/09/02/working-with-hex-colors-in-php/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		<feedburner:origLink>http://www.folksonomy.org/2009/09/02/working-with-hex-colors-in-php/</feedburner:origLink></item>
		<item>
		<title>Header Location Redirect Not Working in PHP?</title>
		<link>http://feedproxy.google.com/~r/folksonomy/~3/IpyGDFS0lO0/</link>
		<comments>http://www.folksonomy.org/2009/08/31/header-location-redirect-not-working-in-php/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 07:39:58 +0000</pubDate>
		<dc:creator>Michael Zhang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[annoyance]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[issue]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://www.folksonomy.org/?p=319</guid>
		<description><![CDATA[Ran into a bug this evening when I was trying to redirect to a different page in PHP. I was trying to do the following:
if(blah blah blah) {

   echo &#34;some text here&#34;;

   header(&#34;Location: http://www.example.com/&#34;);
}
The problem was that it wasn&#8217;t doing anything, even when the if condition was satisfied. It was printing [...]]]></description>
			<content:encoded><![CDATA[<p>Ran into a bug this evening when I was trying to redirect to a different page in PHP. I was trying to do the following:</p>
<pre class="syntax-highlight:php">if(blah blah blah) {

   echo &quot;some text here&quot;;

   header(&quot;Location: http://www.example.com/&quot;);
}</pre>
<p>The problem was that it wasn&#8217;t doing anything, even when the if condition was satisfied. It was printing out what ever I was echoing, but wasn&#8217;t redirecting.</p>
<p>Finally found out the problem after a bit of tinkering. In fact, it&#8217;s something I&#8217;ve learned a few times already in the past but keep forgetting.</p>
<p>If you read the documentation for header() carefully, you&#8217;ll find that it says:</p>
<blockquote><p>Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file. </p></blockquote>
<p>This means that your header has to be executed before ANY output from the PHP file hits the browser. In my case, I was echoing &#8220;some text here&#8221; to the browser before trying to execute the header function, causing the redirect not to work.</p>
<p>Removing the echo will fix the problem. Some people come across this problem in an even more annoying case, where they&#8217;re not even echoing anything. For example, if you copy and paste the following into a PHP file, it will not work:</p>
<pre class="syntax-highlight:php"> &lt;?php

header(&quot;Location: http://www.example.com/&quot;);

?&gt;</pre>
<p>Why won&#8217;t it work, even though you&#8217;re not echoing anything? <span class='highlighted'>Because there&#8217;s a single space before the &lt;?php declaration.</span> Annoying huh?</p>
<p>Hopefully you&#8217;ll read this warning before you ever run into this problem and tear out your hair.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.folksonomy.org/2009/08/31/header-location-redirect-not-working-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.folksonomy.org/2009/08/31/header-location-redirect-not-working-in-php/</feedburner:origLink></item>
		<item>
		<title>Fatal error: Call to undefined function: file_put_contents()</title>
		<link>http://feedproxy.google.com/~r/folksonomy/~3/_KNAemDvh2k/</link>
		<comments>http://www.folksonomy.org/2009/08/31/fatal-error-call-to-undefined-function-file_put_contents/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 22:09:25 +0000</pubDate>
		<dc:creator>Michael Zhang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[file_put_contents]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.folksonomy.org/?p=317</guid>
		<description><![CDATA[Two functions that I&#8217;ve found invaluable recently have been file_get_contents() and file_put_contents(). When used along with serialize(), these have allowed me to maintain very simple &#8220;databases&#8221; using files in the directory, rather than having to store data in specially made MySQL tables.
One of the interesting things I discovered when trying to use these functions on [...]]]></description>
			<content:encoded><![CDATA[<p>Two functions that I&#8217;ve found invaluable recently have been <strong>file_get_contents()</strong> and <strong>file_put_contents()</strong>. When used along with <strong>serialize()</strong>, these have allowed me to maintain very simple &#8220;databases&#8221; using files in the directory, rather than having to store data in specially made MySQL tables.</p>
<p>One of the interesting things I discovered when trying to use these functions on a different machine today, is that file_get_contents is supported after PHP 4.3.0, while file_put_contents is only supported in PHP 5.</p>
<p>If your system doesn&#8217;t support file_put_contents, you&#8217;ll probably run into the following error message:</p>
<blockquote><p>Fatal error: Call to undefined function: file_put_contents()</p></blockquote>
<p>All you need to do to make sure your code can be run on older versions of PHP is to include the following code:</p>
<pre class="syntax-highlight:php">&lt;?php
  if(!function_exists(&#039;file_put_contents&#039;)) {
    function file_put_contents($filename, $data, $file_append = false) {
      $fp = fopen($filename, (!$file_append ? &#039;w+&#039; : &#039;a+&#039;));
        if(!$fp) {
          trigger_error(&#039;file_put_contents cannot write in file.&#039;, E_USER_ERROR);
          return;
        }
      fputs($fp, $data);
      fclose($fp);
    }
  }
?&gt;</pre>
<p>This checks to see if the file_put_contents function exists, and uses a custom declaration of the function if it doesn&#8217;t.</p>
<p>Voila!</p>
<p>[via <a href="http://drupal.org/node/90713">drupal</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.folksonomy.org/2009/08/31/fatal-error-call-to-undefined-function-file_put_contents/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		<feedburner:origLink>http://www.folksonomy.org/2009/08/31/fatal-error-call-to-undefined-function-file_put_contents/</feedburner:origLink></item>
		<item>
		<title>Target of a DDoS? No Offense…</title>
		<link>http://feedproxy.google.com/~r/folksonomy/~3/IlFxqcFcyp0/</link>
		<comments>http://www.folksonomy.org/2009/08/27/target-of-a-ddos-no-offense/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 18:58:45 +0000</pubDate>
		<dc:creator>Michael Zhang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ddos]]></category>
		<category><![CDATA[ddosattack]]></category>
		<category><![CDATA[denialofservice]]></category>
		<category><![CDATA[interesting]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[thought]]></category>

		<guid isPermaLink="false">http://www.folksonomy.org/?p=315</guid>
		<description><![CDATA[Taking a graduate course on network security right now, and reading a paper on inferring DDoS activity on the Internet. One of the things I&#8217;ve learned is how innocent third-parties are often involved in DDoS attacks.
Basically, one method for launching a DDoS involves reflecting packets off a third-party and towards the victim. The packet is [...]]]></description>
			<content:encoded><![CDATA[<p>Taking a graduate course on network security right now, and reading a paper on inferring DDoS activity on the Internet. One of the things I&#8217;ve learned is how innocent third-parties are often involved in DDoS attacks.</p>
<p>Basically, one method for launching a DDoS involves reflecting packets off a third-party and towards the victim. The packet is sent as if it were coming from the victim, so the third-party server responds to the packet by sending a response packet to the victim. If the third-party is hit hard enough by this reflective attack, it itself might be brought down. An attack rate of only 500 packets per second is enough to overwhelm a server.</p>
<p>Collateral damage is an ugly thing.</p>
<p>I&#8217;m wondering whether any of the DDoS attacks we&#8217;ve experienced at <a href="http://photoblog.com">Photoblog</a> over the years have been reflective attacks. This is also why you shouldn&#8217;t take offense if you&#8217;re ever brought down at a DDoS. It doesn&#8217;t always mean someone is intentionally attacking you. It could just mean you were the random IP selected when the attacker chose random IPs across the IP address space.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.folksonomy.org/2009/08/27/target-of-a-ddos-no-offense/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		<feedburner:origLink>http://www.folksonomy.org/2009/08/27/target-of-a-ddos-no-offense/</feedburner:origLink></item>
	</channel>
</rss>
