<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>Matt Writes Code</title>
		<description>I'm Matthew Loberg and I write code.</description>
		<link>http://mlo.io</link>
			
			<item>
				<title>Quick Tip: Protect Important EC2 Instances</title>
				<description>&lt;p&gt;I did something really stupid today. I was doing a load test with &lt;a href=&quot;https://github.com/newsapps/beeswithmachineguns&quot;&gt;Bees With Machine Guns!&lt;/a&gt; that I thought was only going to hit Apache, and not the database. Turns out there is a small database call on the page I was hitting, and caused the database to spike. I tried exiting out of Bees, but it wouldn't. The site started to crash, so I went to terminate the bee instances in the AWS console, but didn't realize I had the production database selected. After hitting terminate, all hell broke loose.&lt;/p&gt;

&lt;p&gt;Luckily we had a slave database running, that we were able to switch to relativly quickly. The EBS disks were still around, so we were able to get our production database back up and running. But what if we didn't have the slave (if you don't, you really should), or the EBS disks were terminated with the instance? We would have been SOL.&lt;/p&gt;

&lt;p&gt;Luckily there is a termination protection feature in EC2 that you can use. Just enable termination protection, and you can't terminate your instance. I did that with the slave database, the replacement database, and a few other &quot;mission critical&quot; instances. Now some dumbass like me can't accidentally delete all your data.&lt;/p&gt;

&lt;p&gt;Turning this on, of course, does not mean you shouldn't be backing up your data. There's no reason you shouldn't be doing that.&lt;/p&gt;
</description>
				<published>Tue Feb 26 00:00:00 -0800 2013</published>
				<link>http://mlo.io/blog/2013/02/26/quick-tip-protect-important-ec2-instances.html</link>
			</item>
			
			<item>
				<title>Installing pcntl On Lion</title>
				<description>&lt;p&gt;I needed the &lt;a href=&quot;http://www.php.net/manual/en/book.pcntl.php&quot;&gt;pcntl&lt;/a&gt; module for a project I'm working on in PHP. By default this module is not installed when you install PHP, so you'll need to compile it. There is a brew package for it, but I couldn't get it to work, and I think it's just as simple to compile it.&lt;/p&gt;

&lt;p&gt;First you'll need to download the PHP source. Run &lt;code&gt;php -v&lt;/code&gt; to get your PHP version and browse the &lt;a href=&quot;http://www.php.net/releases/&quot;&gt;PHP releases page&lt;/a&gt; for your version. In my case it was 5.3.10.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;curl -o php-5.3.10.tar.gz http://us1.php.net/distributions/php-5.3.10.tar.gz
tar xzvf php-5.3.10.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;php-5.3.10/ext/pcntl
phpize
./configure --enable-pcntl
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Some people reported that they got an error while running ./configure. I did not run into this issue, but if you do, you'll need to specify your system architecture.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;CFLAGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;-arch x86_64&amp;#39;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;CXXFLAGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;-arch x86_64&amp;#39;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;LDFLAGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;-arch x86_64&amp;#39;&lt;/span&gt; ./configure --enable-pcntl
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;All that's left to do is compile, install it, and enable it.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;make
make &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;# optional&lt;/span&gt;
sudo make install
sudo &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;extension=pcntl.so&amp;quot;&lt;/span&gt; &amp;gt;&amp;gt; /etc/php.ini
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;If you are using Apache, you will need to restart it to take affect.&lt;/p&gt;
</description>
				<published>Wed Nov 21 00:00:00 -0800 2012</published>
				<link>http://mlo.io/blog/2012/11/21/installing-pcntl-on-lion.html</link>
			</item>
			
			<item>
				<title>Why I Do Side Projects</title>
				<description>&lt;p&gt;I, like every other developer, have side projects. Why work on side projects? I think there are four primary reasons. 1) learn an existing language or tool better, 2) learn a new language or tool, 3) make some extra income, or 4) fill a need you have.&lt;/p&gt;

&lt;p&gt;I have done (or am doing) side projects that cover all of these reasons, but I think the main reason I do a lot of my side projects is because of reason 2, learn a new language or tool.&lt;/p&gt;

&lt;h3&gt;Learn A New Language Or Tool&lt;/h3&gt;

&lt;p&gt;When I learn something new, I'll generally read up on it, maybe buy a book, write a few code samples, but to really solidify what I've learned, I need to write something. For someone new to a language or tool this can be scary. That's why I rely on existing open source projects. If I run into an issue, I can see a real world example of how that was solved.&lt;/p&gt;

&lt;p&gt;When I started writing &lt;a href=&quot;https://github.com/mloberg/Tea-Fueled-Does&quot;&gt;Tea-Fueled Does&lt;/a&gt;, I copied a lot of ideas from other open source frameworks. It helped me out when I was having issues and was able to see how others solved it (and even different ways to solve the same problem). After seeing how the code worked, I was able to refine my framework and it become it's own thing.&lt;/p&gt;

&lt;p&gt;The same thing with &lt;a href=&quot;https://github.com/mloberg/Playr&quot;&gt;Playr&lt;/a&gt;. I was learning Ruby and things just weren't clicking. So I decided I would try to write a clone of &lt;a href=&quot;https://github.com/play/play&quot;&gt;Play&lt;/a&gt;. When I ran into an issue, or didn't know what to do next, I would look at Play's source code and was able to figure it out.&lt;/p&gt;

&lt;p&gt;In both these cases, I never copied and pasted the project. I would have learn nothing that way. I would attempt to get as far as I could without any help, and when I ran into an issue or wanted to see how someone else did it, I would look at the code. Even then did I rarely copied the code verbatim. I would try to do something similar until I found the best solution.&lt;/p&gt;

&lt;h3&gt;Open Source Rocks&lt;/h3&gt;

&lt;p&gt;That's why I appreciate open source projects. They have helped me learn so much, and because of this I post a lot of my code to &lt;a href=&quot;https://github.com/mloberg&quot;&gt;GitHub&lt;/a&gt;. At this moment I have 16 repos, two that are forks, and two that are private (but I intend on making public some day).&lt;/p&gt;

&lt;p&gt;That's the main reason I hack on side projects, to learn something new.&lt;/p&gt;
</description>
				<published>Tue Nov 20 00:00:00 -0800 2012</published>
				<link>http://mlo.io/blog/2012/11/20/why-i-do-side-projects.html</link>
			</item>
			
			<item>
				<title>Introducing OmniBot</title>
				<description>&lt;p&gt;Today I released OmniBot 0.2.1. OmniBot is an IRC chat bot written in NodeJS and CoffeeScript.&lt;/p&gt;

&lt;h4&gt;Some History&lt;/h4&gt;

&lt;p&gt;The company I worked for was using Google Talk (and still do), for chats. We would have launch nights every other Thursday, and need a group chat. We used GTalk for this, but it was a bit lacking. After throwing around the idea of using IRC for this, I setup a server, and tested it out. To this day we still use IRC.&lt;/p&gt;

&lt;p&gt;After I got the server setup, I started working on a chat bot. I had worked with NodeJS a little before, but not enough to really do anything with. So I decided this was a chance to learn Node a little better as well. A couple weeks later I had a chat bot that would say hello when you joined a room and give you the weather conditions. I then built it to be a little more modular and released it as an npm package.&lt;/p&gt;

&lt;h4&gt;The New OmniBot&lt;/h4&gt;

&lt;p&gt;This past week I rewrote OmniBot from the ground up using CoffeeScript. I've used CoffeeScript for other projects before and I think it makes writing JavaScript a lot more simpler.&lt;/p&gt;

&lt;p&gt;I've dropped all planned support for other chat types and have made OmniBot strictly IRC. If you are using another chat service, I would recommend checking out &lt;a href=&quot;http://hubot.github.com/&quot;&gt;Hubot&lt;/a&gt;, GitHub's chat bot.&lt;/p&gt;

&lt;h4&gt;Getting Started&lt;/h4&gt;

&lt;p&gt;If you don't have CoffeeScript installed on your machine, you'll first need to install that.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;npm install -g coffee-script
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Next you'll want to install OmniBot and OmniBot-Modules npm packages.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;npm install omnibot omnibot-modules
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;h5&gt;Writing The Bot&lt;/h5&gt;

&lt;p&gt;OmniBot is the actual chat bot, while OmniBot-Module is a collection of default modules for OmniBot (we'll get into writing our own in another post).&lt;/p&gt;

&lt;p&gt;Now we need to create our script, I've named mine &lt;em&gt;bot.coffee&lt;/em&gt;. We need to require &lt;em&gt;omnibot&lt;/em&gt; and create a new instance of it.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;coffeescript&quot;&gt;&lt;span class=&quot;nv&quot;&gt;Robot = &lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;omnibot&amp;#39;&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;irc =&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;server: &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;irc.example.com&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;channels: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;#bot&amp;#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;bot = &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Robot&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;RobotName&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;irc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The irc variable stores all of the IRC connection details. We'll be connecting to &lt;em&gt;irc.example.com&lt;/em&gt; and the &lt;em&gt;#bot&lt;/em&gt; channel. If you have an IRC server running on a different port, or have a password on your server, you would add those to the irc variable.&lt;/p&gt;

&lt;p&gt;You can run the script by running &lt;code&gt;coffee bot.coffee&lt;/code&gt; in the command line.&lt;/p&gt;

&lt;p&gt;We now have a chat bot, but if we connect, we won't see our chat bot. That's because we need to start the bot before it will connect to the server.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;coffeescript&quot;&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;bot = &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Robot&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;RobotName&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;irc&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;bot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now if we connect, we'll see that our bot is connected, but if we try to interact with it, it won't do anything. That's because we don't have any modules loaded.&lt;/p&gt;

&lt;h5&gt;Loading Modules&lt;/h5&gt;

&lt;p&gt;Modules are ways to hook into OmniBot without modifing any of it's source. It also provides a lot of helpers to make things a bit easier. We'll get more into modules in a future post, what they look like and how to write our own. For now we'll use &lt;em&gt;omnibot-modules&lt;/em&gt;, a collection of modules I have put together to use with OmniBot. There is a method already included that makes loading them easy.&lt;/p&gt;

&lt;p&gt;We can either load the modules before we call start, or pass a callback to start, and load the modules right after it connects. In this case, we want the modules loaded before we start the bot.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;coffeescript&quot;&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;bot = &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Robot&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;RobotName&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;irc&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;modules = &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;join&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;joke&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;weather&amp;#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;bot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;loadModules&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;modules&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;bot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;As you can see, we pass any array of module names to the &lt;code&gt;loadModules&lt;/code&gt; method. You can view a list of the modules on &lt;a href=&quot;http://omnibot.mlo.io/modules/&quot;&gt;OmniBot's website&lt;/a&gt; along with their commands.&lt;/p&gt;

&lt;p&gt;Now if you say &lt;em&gt;RobotName joke&lt;/em&gt;, it will respond with a joke.&lt;/p&gt;

&lt;p&gt;There are some modules that have config options. The weather module is one of these. Using the &lt;code&gt;set&lt;/code&gt; method we can set the config option.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;coffeescript&quot;&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;modules = &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;join&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;joke&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;weather&amp;#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;bot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;weather_zip&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;55555&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;bot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;loadModules&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;modules&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now &lt;em&gt;RobotName weather&lt;/em&gt; will give use the weather for the zip we set.&lt;/p&gt;

&lt;h4&gt;Host Your Own Chat Bot&lt;/h4&gt;

&lt;p&gt;I hope that gets you off the ground with OmniBot. I'll be writing another post about modules and more OmniBot features here soon that should allow you to do even more cool stuff. I'm also actively working on improving and adding new features to OmniBot.&lt;/p&gt;
</description>
				<published>Fri Nov 09 00:00:00 -0800 2012</published>
				<link>http://mlo.io/blog/2012/11/09/introducing-omnibot.html</link>
			</item>
			
			<item>
				<title>Language Specific Indents In Sublime Text 2</title>
				<description>&lt;p&gt;Ask any developer spaces or tabs and you'll get different responses. I was hardcore in the tabs camp until recently. Now I'm trying to use spaces. The biggest issue with using spaces 100% was my text editor. I use Sublime, and tried to set it to use spaces by default, but couldn't seem to get it to work (later I would find out it was a mis-typed option). So every time I would create a new document I would set the tab size (2 for Ruby, 4 for PHP and Python) and covert it to spaces. Half the time I would forget to do this, so I would end up with projects half in spaces and half in tabs. Today I finally got sick of doing this every time, so I set out determined to figure this out once and for all, and I did.&lt;/p&gt;

&lt;p&gt;One of the things I like about Sublime (and vim as well) is you can customize pretty much every thing to your liking. There are default settings in Sublime that you can modify, or you can create user settings that will override the default options (which is the preferred method). There are also syntax or language specific settings. We're going to focus on how to modify the syntax specific settings. There are two methods of doing this.&lt;/p&gt;

&lt;h4&gt;The Hard Way&lt;/h4&gt;

&lt;p&gt;This is how I modified my settings. There is a much easier way to do this, that I found out after I had done it this way.&lt;/p&gt;

&lt;p&gt;Sublime stores all of it's settings and completions in directory structure on disk. On OS X it's located in &lt;em&gt;~/Library/Application Support/Sublime Text 2&lt;/em&gt;. All of the syntax specific settings are in the &lt;em&gt;Packages&lt;/em&gt; directory. If you want to modify the settings for Ruby, you would edit &lt;em&gt;~/Libra/Application Support/Sublime Text 2/Packages/Ruby/Ruby.sublime-settings&lt;/em&gt;. Remember how Sublime has default and user settings? This is the default setting for Ruby, you want to modify the user settings. This is something I realized after the fact. You'll instead want to edit &lt;em&gt;~/Libra/Application Support/Sublime Text 2/Packages/User/Ruby.sublime-settings&lt;/em&gt;.&lt;/p&gt;

&lt;h4&gt;The Easy Way&lt;/h4&gt;

&lt;p&gt;After I had modified the settings manually, I was playing around with Sublime's settings and found a way to edit syntax specific settings right in Sublime (Sublime Text 2 -&gt; Preferences -&gt; Settings - More -&gt; Syntax Specific - User). When you click this, it will open up a settings file for the language you are currently working in. So if you want to edit settings for PHP, you'll have to open a PHP file and click &lt;em&gt;Syntax Specific&lt;/em&gt;.&lt;/p&gt;

&lt;h4&gt;The Settings&lt;/h4&gt;

&lt;p&gt;I've showed you how to modify syntax specific settings, but what's the actual code for using spaces instead of tabs? As you may or may not know, Sublime settings are in JSON format. Unless you've already created a settings file for the language, you'll have to create the structure first, which is just a set of curly braces (&lt;code&gt;{}&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;There are two settings that deal with tabs/spaces. The first is the tabSize (&lt;code&gt;tab_size&lt;/code&gt;) and the second is translateTabsToSpaces (&lt;code&gt;translate_tabs_to_spaces&lt;/code&gt;). Tab size is an integer and deals with, you guessed it, the tab size length. If you are using tabs, this will define how tabs are spaced. The Sublime default is 4. Translate tabs to spaces is a Boolean and defines the use of spaces vs. tabs. If you set it to true, it will use spaces (as defined by tabSize). If it is false (which is the Sublime default), it will use tabs.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;{
    &quot;tab_size&quot;: 2,
    &quot;translate_tabs_to_spaces&quot;: true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;My Ruby settings&lt;/em&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;{
    &quot;tab_size&quot;: 4,
    &quot;translate_tabs_to_spaces&quot;: true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;My PHP and Python settings&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can also set other settings such as the color scheme, whether or not to use spell check or any other Sublime setting.&lt;/p&gt;
</description>
				<published>Thu Aug 23 00:00:00 -0700 2012</published>
				<link>http://mlo.io/blog/2012/08/23/language-specific-indents-sublime.html</link>
			</item>
			
			<item>
				<title>Securing Your Passwords</title>
				<description>&lt;p&gt;Today TutsPlus Premium got hacked. They used a third party plugin that stored passwords in plaintext. This is ironic, because NetTuts+, a sibling company posts about &lt;a href=&quot;http://net.tutsplus.com/tutorials/php/understanding-hash-functions-and-keeping-passwords-safe/&quot;&gt;security&lt;/a&gt; once in a while. It's also very frustrating for users (both present and past) because they have to change their password not only on Tuts+, but other sites as well.&lt;/p&gt;

&lt;p&gt;If you're storing passwords in plaintext, please stop for the sake of your users and your company/product. I'm going to show you that it's easy to implement securing your user's password.&lt;/p&gt;

&lt;h4&gt;An Introduction To bcrypt&lt;/h4&gt;

&lt;p&gt;I personally use &lt;a href=&quot;http://en.wikipedia.org/wiki/Bcrypt&quot;&gt;bcrypt&lt;/a&gt; to hash all my passwords. It's a hash that incorporates a salt (to protect against rainbow attacks) and is adaptive, meaning it can be made slower over time (as computers speed up) to protect against brute-force attacks. This is by far the most recommended hashing function out there because of these features. I'll show you how to implement it in both PHP and Ruby.&lt;/p&gt;

&lt;h4&gt;PHP&lt;/h4&gt;

&lt;p&gt;If you are using PHP 5.2 or earlier, you may not have bcrypt available to you. In these versions it was implemented on the system side rather then in PHP itself (as in 5.3 and later). You can check if it is available on your system.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;if (CRYPT_BLOWFISH == 1) {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    echo &amp;quot;Yes&amp;quot;;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;} else {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    echo &amp;quot;No&amp;quot;;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;To implement, we'll use PHP's &lt;a href=&quot;http://us.php.net/manual/en/function.crypt.php&quot;&gt;crypt&lt;/a&gt; function. This supports different varieties of hash types, and what one will be used is based on the salt.&lt;/p&gt;

&lt;p&gt;Bcrypt's salt starts with '$2a$' followed by a two digit cost, another '$' and 22 characters from './0-9A-Za-z'. The cost parameter relates to how much load it will take to crypt the password. You'll have to find a number (04 to 31) that isn't too slow or too fast on your system. Here are two different ways to generate a bcrypt salt.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;function generate_salt($cost = 12) {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    return &amp;#39;$2a$&amp;#39; . str_pad($cost, 2, &amp;#39;0&amp;#39;, STR_PAD_LEFT) . &amp;#39;$&amp;#39; . substr(sha1(mt_rand()),0,22);&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;x&quot;&gt;function secure_generate_salt($cost = 12) {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    $salt = &amp;#39;$2a$&amp;#39; . str_pad($cost, 2, &amp;#39;0&amp;#39;, STR_PAD_LEFT) . &amp;#39;$&amp;#39;;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    $salt .= substr(str_replace(&amp;#39;+&amp;#39;, &amp;#39;.&amp;#39;, base64_encode(openssl_random_pseudo_bytes(16))), 0, 22);&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    return $salt&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;secure_generate_salt&lt;/code&gt; is a little more secure as it used openssl to generate a random string, but you will need the openssl extension enabled.&lt;/p&gt;

&lt;p&gt;Once you have a salt, hashing your password is simple.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;$salt = secure_generate_salt();&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;$hash = crypt(&amp;#39;password&amp;#39;, $salt);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now you're storing secure passwords, congratulations. But how do we verify if the user's input matches our stored hash?&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;function verify_hash($input, $hash) {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    return crypt($password, $hash) === $hash;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;As simple as that. If you put that together in a class, you can have a really handy tool.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;class Crypter {&lt;/span&gt;

&lt;span class=&quot;x&quot;&gt;    private static $cost = 12;&lt;/span&gt;

&lt;span class=&quot;x&quot;&gt;    public static function generate_salt($cost = null) {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;        if (is_null($cost)) $cost = self::$cost;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;        if ($cost &amp;lt; 4 || $cost &amp;gt; 31) throw new Exception(&amp;#39;Cost must be between 4 and 31&amp;#39;);&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;        $salt = &amp;#39;$2a$&amp;#39; . str_pad($cost, 2, &amp;#39;0&amp;#39;, STR_PAD_LEFT) . &amp;#39;$&amp;#39;;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;        $salt .= substr(str_replace(&amp;#39;+&amp;#39;, &amp;#39;.&amp;#39;, base64_encode(openssl_random_pseudo_bytes(16))), 0, 22);&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;        return $salt&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    }&lt;/span&gt;

&lt;span class=&quot;x&quot;&gt;    public static function hash($input, $cost = null) {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;        return crypt($input, self::generate_salt($cost));&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    }&lt;/span&gt;

&lt;span class=&quot;x&quot;&gt;    public static function verify($input, $hash) {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;        return crypt($input, $hash) === $hash;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    }&lt;/span&gt;

&lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;h4&gt;Ruby&lt;/h4&gt;

&lt;p&gt;Why yes there is a &lt;a href=&quot;http://bcrypt-ruby.rubyforge.org/&quot;&gt;bcrypt gem&lt;/a&gt;, which makes it super simple to implement in your application. Install it with &lt;code&gt;gem install bcrypt-ruby&lt;/code&gt; and require &lt;code&gt;bcrypt&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Generate a hash with &lt;code&gt;BCrypt::Password.create&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;bcrypt&amp;#39;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;BCrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:Password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;password&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# cost defaults to 10, you can manually set the cost&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;BCrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:Password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;password&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:cost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;And verify a password with &lt;code&gt;BCrypt::Password.new&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;bcrypt&amp;#39;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;BCrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:Password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# true if password&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;h4&gt;Forgot Passwords&lt;/h4&gt;

&lt;p&gt;Since you're not storing passwords in plaintext anymore, you won't be able to send passwords in emails if someone forgot theirs. Instead you'll have to build a password reset system. You could either have a temporary link or generate a random password and send it to them or another method.&lt;/p&gt;

&lt;h4&gt;Updating Costs&lt;/h4&gt;

&lt;p&gt;If you find that the costs you've been using are either too fast or too slow you can't just change the cost parameter in the hash. You can instead rehash the password on a successful login using your new cost.&lt;/p&gt;

&lt;h4&gt;So Why Aren't You Using bcrypt?&lt;/h4&gt;

&lt;p&gt;As you can see, bcrypt is both secure and easy to use. You have no good reason to continue storing passwords in plaintext.&lt;/p&gt;
</description>
				<published>Tue Jun 26 00:00:00 -0700 2012</published>
				<link>http://mlo.io/blog/2012/06/26/securing-your-passwords.html</link>
			</item>
			
			<item>
				<title>Parallel Processes In Bash</title>
				<description>&lt;p&gt;I wrote a script to speed up MySQL imports. I'll write more on this later, but for now I want to focus on background and parallel processes in Bash. Part of the script loads tables at the same time, trying to speed up the import. You can have multiple processes in Bash by sending them to the background using the &lt;code&gt;&amp;amp;&lt;/code&gt; character.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;table in TABLES; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;    &lt;/span&gt;import_table &lt;span class=&quot;nv&quot;&gt;$table&lt;/span&gt; &amp;amp;
&lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The above example will send all of your process to the background. If you have a lot of process (assuming the process takes some time and resources), this is going to slow down your system, and potentially crash it. Instead, I wanted to only run 4 commands at the same time. First I tried making a pid for each background process. Then when an table started, it would check for the number of pids. If it was less then the threads specified, it would start one, otherwise it would wait.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;import_table&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;table&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;$1&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[[&lt;/span&gt; &lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;ls *.pid | wc -l | tr -d &lt;span class=&quot;s1&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt; -ge 4 &lt;span class=&quot;o&quot;&gt;]]&lt;/span&gt;; &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;sleep 5; &lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$PPID&lt;/span&gt; &amp;gt; &lt;span class=&quot;nv&quot;&gt;$table&lt;/span&gt;.pid
    &lt;span class=&quot;c&quot;&gt;# import&lt;/span&gt;
    rm &lt;span class=&quot;nv&quot;&gt;$table&lt;/span&gt;.pid
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;table in TABLES; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;    &lt;/span&gt;import_table &lt;span class=&quot;nv&quot;&gt;$table&lt;/span&gt; &amp;amp;
&lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;While this solution did what I wanted, it left a lot of processes still running. I did a little digging and found a solution to fire off another process when one died. By using a named pipe, you can do better parallel processes in Bash, and it's really simple to do.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;mkfifo pipe
&lt;span class=&quot;nb&quot;&gt;exec &lt;/span&gt;3&amp;lt;&amp;gt;pipe
rm -f pipe

&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; sleep 1; &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &amp;gt;&amp;amp;3; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &amp;amp;
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; sleep 2; &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &amp;gt;&amp;amp;3; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &amp;amp;
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; sleep 3; &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &amp;gt;&amp;amp;3; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &amp;amp;
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; sleep 4; &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &amp;gt;&amp;amp;3; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &amp;amp;

&lt;span class=&quot;k&quot;&gt;while &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;read&lt;/span&gt;; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; process_func; &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &amp;gt;&amp;amp;3; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &amp;amp;
&lt;span class=&quot;k&quot;&gt;done&lt;/span&gt; &amp;lt;&amp;amp;3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This script makes a named pipe, assigns it to the 3 descriptor for reads and writes and removes the pipe (it will keep intact until the script is done). I'm then firing up 4 processes, offsetting them so they don't all start at the same time. The while loop will then read every time the pipe is written to (when ever the process is done) and run the loop. This way we only have 4 sub-processes running at a time.&lt;/p&gt;

&lt;p&gt;There are a lot more cool things you can do with named pipes, I would recommend reading up on them.&lt;/p&gt;
</description>
				<published>Wed Jun 13 00:00:00 -0700 2012</published>
				<link>http://mlo.io/blog/2012/06/13/parallel-processes-in-bash.html</link>
			</item>
			
			<item>
				<title>Why You Should Write Tests</title>
				<description>&lt;p&gt;Last week I started writing tests for my &lt;a href=&quot;https://github.com/mloberg/Tea-Fueled-Does&quot;&gt;framework&lt;/a&gt;. I've got to be honest, I rarely write tests for my code. This was the first time I really wrote tests, but I recommend it.&lt;/p&gt;

&lt;h4&gt;It's Easy&lt;/h4&gt;

&lt;p&gt;I was always under the impression that writing tests for code was complex. After writing some tests for &lt;a href=&quot;http://www.phpunit.de/manual/3.6/en/index.html&quot;&gt;PHPUnit&lt;/a&gt;, I was wrong. The class extends &lt;em&gt;PHPUnit_Framework_TestCase&lt;/em&gt; and you've got a bunch of assertions methods. For example take a look at this code I've &lt;a href=&quot;https://github.com/Tea-Fueled-Does/Tests/blob/master/AuthTest.php&quot;&gt;pulled&lt;/a&gt; right from my tests.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?php

    require 'test.bootstrap.php';

    use TFD\Auth;

    class AuthTest extends PHPUnit_Framework_TestCase {

        /**
         * Test Auth::login method.
         */

        public function testLogin() {
            $fingerprint = Auth::login('username', 'secret');
            $this-&amp;gt;assertInternalType('string', $fingerprint);

            return $fingerprint;
        }

        /**
         * Test Auth::valid method.
         * 
         * @depends testLogin
         */

        public function testValid($fingerprint) {
            $this-&amp;gt;assertTrue(Auth::valid($fingerprint, 'username', 'secret'));
        }

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That took me less then ten minutes to write.&lt;/p&gt;

&lt;h4&gt;There's No Guessing&lt;/h4&gt;

&lt;p&gt;When you write tests, you are making sure that something is working how it's suppose to. There's no guessing if it's going to work. You write a test, if it passes, the code works, if it fails, there's something wrong. When you change something you can verify that it still works by running the tests again.&lt;/p&gt;

&lt;h4&gt;It Automates Testing&lt;/h4&gt;

&lt;p&gt;Normally when I write code, I make sure it does what it's supposed to do and then forget about it. For example with Tea-Fueled Does, I would create a route or add something to a view to make sure something's working and then delete it. I would never test it again. With tests you can rerun those tests, and with PHPUnit, you can run all your tests in a single command.&lt;/p&gt;

&lt;h4&gt;It Creates Quality Code&lt;/h4&gt;

&lt;p&gt;How many times have you released something with bugs in it? I've done a couple commits where I find out later, I have a bug in it. Writing tests helps you prevent that.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Test-driven_development&quot;&gt;Test-Driven Development&lt;/a&gt; is also a great development process. You write a test for a new function/method or an improvement and fix the code until it passes. This creates concise code.&lt;/p&gt;

&lt;h4&gt;Getting Started&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;http://www.phpunit.de/manual/3.6/en/index.html&quot;&gt;PHPUnit's docs&lt;/a&gt; are a great place to start. NetTuts's also has an &lt;a href=&quot;http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/&quot;&gt;article&lt;/a&gt; on it SimpleTest, another PHP test suite. And if you need real life examples, check out my &lt;a href=&quot;https://github.com/Tea-Fueled-Does/Tests&quot;&gt;tests for Tea-Fueled Does&lt;/a&gt;.&lt;/p&gt;
</description>
				<published>Sun May 20 00:00:00 -0700 2012</published>
				<link>http://mlo.io/blog/2012/05/20/why-you-should-write-tests.html</link>
			</item>
			
			<item>
				<title>Getting Around CORS in CloudFront</title>
				<description>&lt;p&gt;We ran into an issue at work the other day with CloudFront and S3. We were trying to load assets via Ajax from our CloudFront distribution, but kept getting an &quot;Origin http://example.com is not allowed by Access-Control-Allow-Origin&quot; error. There is a W3 spec called CORS (Cross-Origin Resource Sharing) that prevents retrieving data from another site. To get around this, you would normally set an &quot;Access-Control-Allow-Origin&quot; header, but S3 limits the headers you can set, and that's not one of them.
I'm not the &lt;a href=&quot;http://blog.jacobelder.com/2012/05/3-problems-aws-needs-to-address/&quot;&gt;only one&lt;/a&gt; who finds this problem annoying. Amazon has said there are plans to implement this feature, but they also said that &lt;a href=&quot;https://forums.aws.amazon.com/message.jspa?messageID=160155#160155&quot;&gt;two years ago&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I couldn't wait around for this fix to come about (if it ever does), so I looked at other options; using another CDN, building my own CDN. Then this morning I came across an article on Hacker News called &lt;a href=&quot;http://blog.elastic.io/post/22773181715/how-we-use-amazon-cloudfront-for-dynamically-generated&quot;&gt;How we use Amazon CloudFront for dynamically generated content&lt;/a&gt;. By default, CloudFront's origin server is an S3 bucket, but there is an option for setting a custom origin. This means you can set up your own server to use as a CloudFront origin server. I spun up an EC2 instance with nginx and the &quot;Access-Control-Allow-Origin&quot; header. Then I created a new CloudFront distribution and set the instance as the origin. I reloaded the page, and it loaded the asset.
While there are other issues with CloudFront (SSL with CNAMEs), this makes it more usable.&lt;/p&gt;
</description>
				<published>Thu May 10 00:00:00 -0700 2012</published>
				<link>http://mlo.io/blog/2012/05/10/getting-around-cors-in-cloudfront.html</link>
			</item>
			
			<item>
				<title>Playr - The Ruby Music Manager</title>
				<description>&lt;p&gt;A while back I started to learn Ruby. When I learn something I have to be actively working with it. That's why I started Playr. The goal was to create a webapp that could manage music. After a month I got a basic webapp that you could upload music to and queue up music, and after a little more work, I actually got it to play music.&lt;/p&gt;

&lt;p&gt;I deployed it on the music computer my company at the time was using, and it was received pretty well. After a couple of weeks in production, I realized some bugs in it, and went to work on version 2.&lt;/p&gt;

&lt;p&gt;At first, version 2 was just suppose to fix the process issues Playr dealt with in v1. After diving into the code again, I decided to throw most of it out and start again. To force myself to learn more tools, I used haml, SASS, and CoffeeScript in v2. After some slowing issues (from rendering SASS and CoffeeScript every request), I went to Unicorn and some Rack plugins to render SASS and CoffeeScript assets. But the biggest issue from v1 was still there, processes crashing. In v1 all processes were in a single file in different forks. This was really hard to manage, and often times when one crashed, the rest would crash. I looked into process management tools, and found &lt;a href=&quot;http://godrb.com/&quot;&gt;god&lt;/a&gt;. God is a process monitoring framework. Once I got the webapp (Sinatra), music, and WebSocket processes over to god (and some configuring) the processes became stable and easy to stop and restart. Because adding another process was almost nothing, I added a simple task management process. There are a couple more additions/fixes from v1, but I won't go into them.&lt;/p&gt;

&lt;p&gt;I am so happy with Playr, that I am open-sourcing it today. You can find the code on &lt;a href=&quot;https://github.com/mloberg/Playr&quot;&gt;GitHub&lt;/a&gt;, and a &lt;a href=&quot;https://github.com/mloberg/Playr/wiki&quot;&gt;wiki&lt;/a&gt; to get you going with Playr.&lt;/p&gt;
</description>
				<published>Sat Feb 18 00:00:00 -0800 2012</published>
				<link>http://mlo.io/blog/2012/02/18/playr-the-ruby-music-manager.html</link>
			</item>
			
	</channel>
</rss>