<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>random thoughts and rumblings by csspixel</title>
 <link href="http://csspixel.com/atom.xml" rel="self"/>
 <link href="http://csspixel.com/"/>
 <updated>2010-03-06T01:41:52-05:00</updated>
 <id>http://csspixel.com/</id>
 <author>
   <name>csspixel</name>
   <email>contact@csspixel.com</email>
 </author>
 
 
   <entry>
     <title>Web Development With Sinatra</title>
     <link href="http://csspixel.com//2010/03/05/web-development-with-sinatra.html"/>
     <updated>2010-03-05T00:00:00-05:00</updated>
     <id>http://csspixel.com/2010/03/05/web-development-with-sinatra</id>
     <content type="html">&lt;h1&gt;&lt;a href=&quot;/2010/03/05/web-development-with-sinatra.html&quot;&gt;Web Development With Sinatra&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;A lot of people jumped on the Rails band wagon and started using Ruby with it. I was never fan of large frameworks that force you to do things certain way. I love to have freedom to do things my way, even if it is not the best way. It is more fun for sure :-).&lt;/p&gt;
&lt;p&gt;Thats how I found &lt;a href=&quot;http://www.sinatrarb.com&quot;&gt;Sinatra&lt;/a&gt;, a &lt;span class=&quot;caps&quot;&gt;DSL&lt;/span&gt; for creating web apps in Ruby.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/sinatra.gif&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This &lt;a href=&quot;http://www.sinatrarb.com/intro.html&quot;&gt;intro&lt;/a&gt; page shows really nice quick examples to get you going. There is also a &lt;a href=&quot;http://www.sinatrarb.com/book.html&quot;&gt;book&lt;/a&gt; with more detailed instructions. Promising &lt;a href=&quot;http://ididitmyway.heroku.com/&quot;&gt;blog&lt;/a&gt; with tutorials for beginners. Get &lt;a href=&quot;http://rubylearning.com/blog/2009/06/29/20-rubyists-using-sinatra-do-you/&quot;&gt;inspired&lt;/a&gt; before you dive in.&lt;/p&gt;
&lt;p&gt;So instead of telling you how to create yet another hello world web app :-), I would like to touch on a few things that were not clear to me when I started using Sinatra and Ruby.&lt;/p&gt;
&lt;h2&gt;Setting up project structure&lt;/h2&gt;
&lt;p&gt;Sinatra based web app fits in a single file. This is great for a quick hello world app. For anything more serious, I like to create the following folder structure:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/sinatra_folder.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;To get everything loaded properly for the above example, write something like this in your app.rb:&lt;/p&gt;
&lt;pre&gt;
require 'rubygems'
require 'sinatra'
require 'helpers/sinatra'
require 'config/database'
require 'model/somemodel'

&lt;/pre&gt;
&lt;p&gt;This is not set in stone. For example, you can stick all your &lt;span class=&quot;caps&quot;&gt;ORM&lt;/span&gt; models in the main file, but things might get messy later on.&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;tmp&lt;/b&gt; folder is used to reload your app once in production if using Passenger. Simply create an empty restart.txt file inside of it and refresh your app in the browser.&lt;/p&gt;
&lt;p&gt;For the views I use erb templates as I like to write html. It looks like a lot of people prefer Haml and Sass. Check out both, you might like them.&lt;/p&gt;
&lt;p&gt;I prefer &lt;a href=&quot;http://datamapper.org/&quot;&gt;DataMapper&lt;/a&gt; as &lt;span class=&quot;caps&quot;&gt;ORM&lt;/span&gt; for my Sinatra based apps. There is also &lt;a href=&quot;http://sequel.rubyforge.org/&quot;&gt;Sequel&lt;/a&gt;. You can also use ActiveRecord, especially if you are familiar with Rails. For a key-value DB I would recommend &lt;a href=&quot;http://code.google.com/p/redis/&quot;&gt;Redis&lt;/a&gt;. Very small, damn fast and quite fun to work with.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;If you are using TextMate, check out &lt;a href=&quot;http://github.com/rstacruz/sparkup&quot;&gt;Sparkup&lt;/a&gt; bundle to speed up your html coding.&lt;/i&gt;&lt;/p&gt;
&lt;h2&gt;Use Rerun when developing locally&lt;/h2&gt;
&lt;p&gt;At the beginning I was always using &lt;b&gt;Shotgun&lt;/b&gt; gem to automatically reload the app when making changes. The problem is that Shotgun reloads your app on every request (it forks your app, kills it then loads it again). This takes a long time and your web app feels really slow. Instead I use &lt;a href=&quot;http://github.com/alexch/rerun&quot;&gt;Rerun&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To install:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;sudo gem install rerun&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To use:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;rerun ruby app.rb&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It monitors the file system and when there are changes, it restarts it. Works great!&lt;/p&gt;
&lt;h2&gt;Deployment&lt;/h2&gt;
&lt;p&gt;Please stay away from &lt;a href=&quot;http://csspixel.com/2010/01/29/shared-hosting-stinks.html&quot;&gt;crappy shared web hosts&lt;/a&gt;. If you are short on money, use &lt;a href=&quot;http://heroku.com/&quot;&gt;Heroku&lt;/a&gt;. They are great and offer a free service with limited resources. More than plenty for your toy apps while learning Sinatra.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://blog.heroku.com/archives/2009/3/5/32_deploy_merb_sinatra_or_any_rack_app_to_heroku/&quot;&gt;Instructions to deploy Sinatra on Heroku&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you have $20/month to spend on hosting, and feel like setting up everything on your own, get a &lt;span class=&quot;caps&quot;&gt;VPS&lt;/span&gt; from either &lt;a href=&quot;http://slicehost.com&quot;&gt;Slicehost&lt;/a&gt; or &lt;a href=&quot;http://www.linode.com/&quot;&gt;Linode&lt;/a&gt;. They are both great companies with no bullshit attached. I am personally running Ubuntu server with Apache and &lt;a href=&quot;http://www.modrails.com/&quot;&gt;Phusion Passenger&lt;/a&gt; to run my Sinatra apps. Passenger works for Apache and Nginx, your choice. Keep in mind that Nginx is much lighter and usually better choice for a small &lt;span class=&quot;caps&quot;&gt;VPS&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;To setup Passenger on ubuntu/debian add following repo to your software sources:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;deb http://apt.brightbox.net hardy main&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;For Apache:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;apt-get install libapache2-mod-passenger&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;For Nginx&lt;/p&gt;
&lt;p&gt;&lt;code&gt;apt-get install nginx-brightbox&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Once you push your Sinatra app to your &lt;span class=&quot;caps&quot;&gt;VPS&lt;/span&gt; either via git, scp or whatever method you like, create a config.ru file inside your app folder with the following:&lt;/p&gt;
&lt;pre&gt;
require 'app'
run Sinatra::Application


&lt;/pre&gt;
&lt;p&gt;Change &lt;b&gt;app&lt;/b&gt; with the name of your Sinatra app source file. Now simply point your web server document root to the folder of your app and you are good to go.&lt;/p&gt;
&lt;h2&gt;Authentication&lt;/h2&gt;
&lt;p&gt;For a simple http auth, check out the &lt;a href=&quot;http://www.sinatrarb.com/faq.html#auth&quot;&gt;Sinatra book&lt;/a&gt;. If you need an authentication that is backed by a database, I would recommend to check out this &lt;a href=&quot;http://github.com/daddz/sinatra-dm-login&quot;&gt;code&lt;/a&gt;. It is a very simple DataMapper based authentication. It should give you a good idea how to get things going. For a third party authentication look at &lt;a href=&quot;http://blog.saush.com/2009/04/25/third-party-user-authentication-with-ruby-in-a-just-few-lines-of-code/&quot;&gt;this&lt;/a&gt; post.&lt;/p&gt;
&lt;h2&gt;Where to get help&lt;/h2&gt;
&lt;p&gt;If you would like to post a question, check out &lt;a href=&quot;http://groups.google.com/group/sinatrarb&quot;&gt;Google groups&lt;/a&gt;.&lt;br /&gt;
For a quick help over &lt;span class=&quot;caps&quot;&gt;IRC&lt;/span&gt; there is #sinatra channel at Freenode. It is not that active though.&lt;/p&gt;</content>
   </entry>
 
   <entry>
     <title>Shared Hosting Stinks</title>
     <link href="http://csspixel.com//2010/01/29/shared-hosting-stinks.html"/>
     <updated>2010-01-29T00:00:00-05:00</updated>
     <id>http://csspixel.com/2010/01/29/shared-hosting-stinks</id>
     <content type="html">&lt;h1&gt;&lt;a href=&quot;/2010/01/29/shared-hosting-stinks.html&quot;&gt;Shared Hosting Stinks&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Mention &amp;#8220;shared web hosting&amp;#8221; and I get quite negative thoughts flying through my head.&lt;/p&gt;
&lt;p&gt;It has been a while since I&amp;#8217;ve been using &lt;a href=&quot;http://slicehost.com&quot;&gt;Slicehost&lt;/a&gt; for my personal sites and projects. It has been an awesome experience. I have one slice running with a common &lt;span class=&quot;caps&quot;&gt;LAMP&lt;/span&gt; stack that is running like a horse for over a year now. Comparing to traditional &lt;span class=&quot;caps&quot;&gt;VPS&lt;/span&gt; hosting or shared hosts, this is just perfect. The problem is that this setup works for me or anyone who is willing to setup everything on their own. Not so much for regular folks.&lt;/p&gt;
&lt;p&gt;So far I have been trying to setup my clients on popular shared web hosts such as &lt;a href=&quot;http://hostgator.com&quot;&gt;this one.&lt;/a&gt; The reason for that is my unwillingness to be a sysadmin on a 24&amp;#215;7 duty. If their website goes down at 2am, let someone else worry about it. Lately I am getting really aggravated with majority of companies that I am dealing with.&lt;/p&gt;
&lt;h2&gt;Poor Customer Service&lt;/h2&gt;
&lt;p&gt;Every company loves to brag how their customer service is great. Big headlines with flashy text screaming &amp;#8220;24&amp;#215;7 best support&amp;#8221;. Yeah right, lie! The reps that you get on the phone are mostly clueless and it takes ages to get someone who actually knows their shit and cares about your problem in the first place. Is it so hard to find people who are interested in web hosting to work for you? I always have a feeling that I am talking to a car mechanic. There is plenty of geeks out there who love this job, you know.&lt;/p&gt;
&lt;h2&gt;Slow Slow Slow&lt;/h2&gt;
&lt;p&gt;Find me a company that is not overselling and is still in business. Please, if you stick 1200 customers on a single server, shit will be slow! Few lemmings will execute their lame php nuke site that will make hell for everyone else. And when that happens, go look up above paragraph, as it will take you ages to prove that it is not your imagination that things are slow.&lt;/p&gt;
&lt;h2&gt;cPanel Baby!&lt;/h2&gt;
&lt;p&gt;Yep, everyone knows that one. The ugliest and most bloated piece of software on this planet. This applies to &lt;span class=&quot;caps&quot;&gt;WHM&lt;/span&gt; as well. We are in 2010, hosting industry has been around forever. Why is it so hard to make a decent control panel? Occasionally a host or two will have a custom solution that doesn&amp;#8217;t stink just as bad. Take a look at panel from Slicehost. Minimalist, fast, to the point. If I need an escort service, I will not look for it on my web hosting control panel.&lt;/p&gt;
&lt;h2&gt;What Can Be Done&lt;/h2&gt;
&lt;p&gt;There needs to be a &amp;#8220;Slicehost&amp;#8221; for shared web hosting. Top notch customer service that knows their shit, quick and easy way to sign up (please don&amp;#8217;t make me fill out four pages of shit to get $10 account). Give me an ability to move to a different server if I wan to. Give me a full control over &lt;span class=&quot;caps&quot;&gt;DNS&lt;/span&gt;. Give me a nice and fast control panel so I can make quick changes for my clients. Be honest! If there are problems with the server, don&amp;#8217;t make up lame excuses. Having a pretty website and a good marketing team is not enough.&lt;/p&gt;
&lt;p&gt;Another problem is finding a decent host with so many of them out there. Popular hosting review websites are biased and dirty. No trust there. Reading for hours through &lt;span class=&quot;caps&quot;&gt;WHT&lt;/span&gt; forums is really not that great. People complain about bad and good companies. Filtering all that noise can be time consuming.&lt;/p&gt;</content>
   </entry>
 
   <entry>
     <title>CentOS & Active Directory authentication</title>
     <link href="http://csspixel.com//2010/01/20/centos-directory-authentication.html"/>
     <updated>2010-01-20T00:00:00-05:00</updated>
     <id>http://csspixel.com/2010/01/20/centos-directory-authentication</id>
     <content type="html">&lt;h1&gt;&lt;a href=&quot;/2010/01/20/centos-directory-authentication.html&quot;&gt;CentOS &amp;amp; Active Directory authentication&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Recently I had a need to integrate centos server with active directory authentication. One way is to use samba and spend two nights hacking various config files. Simple way is to use &lt;a href=&quot;http://www.likewise.com/&quot;&gt;Likewise Open&lt;/a&gt;. To use likewise open on centos, download the rpm from the website and install it as root.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;# sh ./LikewiseIdentityServiceOpen-5.2.0.6031-linux-i386-rpm.sh&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To join to our windows domain, use domainjoin-cli utility&lt;/p&gt;
&lt;p&gt;&lt;code&gt;# /opt/likewise/bin/domainjoin-cli join DOMAIN DOMAINUSER&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now we can login to the server with our AD account in the form of DOMAINusername If you do not like to type your domain name every time, modify lsassd.conf&lt;/p&gt;
&lt;p&gt;&lt;code&gt;assume-default-domain = yes&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Restart lsassd service&lt;/p&gt;
&lt;p&gt;&lt;code&gt;# /etc/init.d/lsassd restart&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Thats it, five minutes and our server is authenticating with AD.&lt;/p&gt;</content>
   </entry>
 
 
</feed>
