All posts by Sam

Mahi Mahi with Peppers

mahi mahi with peppersMahi Mahi:

Add salt, pepper, some garlic.

Add lime juice (a good amount) and tequila.

Add to pan with oil (olive or coconut).

Cook about 5 minutes per side on medium-high.


Salt, Pepper, Garlic, Ginger.

Add to wok with oil (olive or coconut).

Cook about 5-7 minutes on high.

EZ Shrimp

Take coconut oil (about a spoonful),  and heat in a wok until it’s liquefied.  Then add as much shrimp as you want.  Next, add generous amounts of salt, cayenne pepper, garlic powder (or fresh garlic if you’re not lazy), and whatever else looks good (I use Kirkland Signature Organic No-Salt Seasoning).  Heat on high for about 5-10 minutes, until shrimp have cooked through and have shrunk and shriveled. 




Setting up a new Rackspace Cloud Server with Debian 6,, and PHP/MySQL

Another instructional blog post as I try to figure out something.

Configuring a website with is much different than setting one up with a shared hosting service such as Dreamhost or GoDaddy.  I could write more about this, but it’s not really productive.

Anyways, here are the steps I went through:

1. Buy a domain.

I chose, for their cheap prices and no-bullshit/non-shady website (e.g. GoDaddy).  For $8.25/month (after coupon code), you get a .com domain.

2. Configure Google Apps

With, this is very simple, there’s a button for it.  After that, follow Google’s very detailed instructions.  I chose this option instead of configuring mail on my own server because it’s simpler, and a very pretty interface.  Plus, all the people working with me on the site already have gmail.

3. Set up a Cloud Server Account

Pretty simple, not many options to choose.  At first, all you need will be a cloud server.

4. Set up your server on

I went with a Debian 6.0 server with 512MB of RAM after about 10 minutes of internet research.  I have some experience with CentOS, Ubuntu, and Fedora, but the internet said “Debian” so I went with that.

5. Set up DNS on

First, delete the “A” DNS records on  These can be found under “Domain Management” » “DNS Record Management.”  Next, add a new “A” record with “*” in the Record Host field and your Rackspace IP in the Record Answer field.  Add another one with a blank Record Host field and the same IP.

6. Log in to your server as root, install everything

Using the provided root password from Rackspace, open up a terminal (on Windows use PuTTY).  Enter
#apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql
At this point, your DNS information will take a little while to propagate across the internet.  However, if you type your url into your address bar, you should get a page that says “It works!” (As of Debian 6).
Missing data…
Next add the following to your .htaccess for compression and www-removal.  Make sure to change “” to your domain.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Making dynamic SQL queries from Javascript with PHP

Impossible? No!

Just add some AJAX to your <head> section:
<script type="text/javascript">
function request(query){
if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
if (xmlhttp.readyState==4 && xmlhttp.status==200){
//it worked.
alert(xmlhttp.responseText); //this is the output of your query.php file
//whatever happens when it doesn't work
alert('Query did not work');

and create the new page query.php with the following content, replacing the default values where necessary:

$dbhost = '#REPLACE THIS#';
$dbuser = '#REPLACE THIS#';
$dbpass = '#REPLACE THIS#';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
$dbname = '#REPLACE THIS#';
$result = mysql_query($query);
//now use mysql_fetch_assoc($result) or something similar to get the returned result if applicable.
//if you echo a value, the javascript ajax will receive it

Using this code, you can make whatever kind of SQL queries you want from other sections of your site.

Warning: Unless you sanitize your database inputs you leave yourself open to some huge vulnerabilities.

Fixing Facebook’s PHP SDK logout

If you request the “offline_access” permission when using the Facebook PHP SDK (and sometimes even without it), it makes the default logout functionality not work very well.  To fix this, here’s what worked for me:

  1. Change your logout url:
    $logoutUrl = $facebook->getLogoutUrl(array( 'next' => ($fbconfig['baseurl'].'logout.php') ));
  2. On your logout.php page, add the following code:
    setcookie('fbs_'.$facebook->getAppId(), '', time()-100, '/', '');
    header('Location: /');

This should correctly logout your users.