Design

I read an interesting comment with a very cool quote recently:

“Most people make the mistake of thinking design is what it looks like. People think it’s this veneer — that the designers are handed this box and told, ‘Make it look good!’ That’s not what we think design is. It’s not just what it looks like and feels like. Design is how it works.” — Steve Jobs

Having done some design work recently, I must say this is very true. It’s so important that the entire user experience be thought through, not just how to make the design look pretty with gradients and drop shadows (although this is important too)…

Posted in Web Design | 1 Comment

PHP interactive shell

Today I discovered something cool: a PHP interactive shell, sort of like python/ruby’s. Users were telling me about a weird error in one of the apps i work on that I tracked down to resulting in a PHP warning “Message: strstr() [function.strstr]: Empty delimiter.” I suspected it was because I was calling strstr() with an empty string for the second parameter. I couldn’t be sure though until I wrote some throw away code. Instead of writing the code though I did a quick Google search and found this awesome PHP interactive shell. Just install and call

php-shell.sh

from the terminal. It’s pretty easy to use, and right away I was able to tell that the strstr() error was in fact because the second parameter was empty.

Posted in Uncategorized | Leave a comment

In Progress: news page parser

Edit: I’ve since given up this project – news sites differ way too much to accurately screen scrape them all with one class.

I’m currently working on an application that needs to parse new articles and pull out author/publisher/date info directly from the article page. Unfortunately not everyone uses micro formats or some semantic way to describe articles. So to remedy this problem I’m in the progress of making a class that parses news articles and pulls the relevant info out. It’s a work in progress, but hopefully as I complete it it will be useful to some.

It’s grabable from here: http://gist.github.com/129479

Posted in Uncategorized | 2 Comments

Open new windows in Safari as tabs

Just reblogging a useful tip – open new windows as tabs in safari.

1. Quit Safari
2. Open terminal and run “defaults write com.apple.Safari TargetedClicksCreateTabs -bool true”
3. Reopen Safari.

I can confirm the works in Safari 4.0 Beta with Leopard. Hope it’s useful!

Posted in Uncategorized | Leave a comment

Simplifying floats with PHP

The other day I was writing some code for a website, and I ended up with a floating point number in the form .5, 1, 1.5, etc. (it changed depending on what the user selected) I ran into a problem when I wanted to display it as a fraction, so I wrote this simple class that converts any float to a fraction.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Simplifies decimals into fractions.
*/
class Fraction
{
  public static function convert_float($float)
  {
    $float = (string) $float;
    $float = explode('.', $float);
    $whole = (int) $float[0];
    $float = (int) $float[1];
 
    return Fraction::simplify($float, 100, $whole);
  }
 
  public static function simplify($num, $denom, $mixed=false)
  {
    if ($num >= $denom) $max = $num;
    else $max = $denom;
 
    if ($mixed !== false)
    {
      if ($num >= $denom)
      {
        // calcuate the whole number
        $whole = $num / $denom;
        $whole = (string) $whole;
        $whole = explode('.', $whole);
        $whole = (int) $whole[0];
        $whole = $whole + $mixed;
 
        // reset the numerator
        $num = $num % $denom;
      }
    }
 
    for ($i=2; $i < $max; $i++) { 
      while ( ($num % $i == 0) && ($denom % $i == 0) )
      {
        $num = $num / $i;
        $denom = $denom / $i;
      }
    }
 
    $ret = array('num' => $num, 'denom' => $denom);
    if ($mixed)
      $ret['whole'] = $whole;
    return $ret;
  }
}

To use it just do something like this:

1
2
$res = Fraction::convert_float(54.25);
echo $res['whole'] . ' ' . $res['num'] . '/' . $res['denom'] . '<br>';

And of course you can always simplify fractions as well:

1
2
$res = Fraction::simplify(25, 30);
echo $res['num'] . '/' . $res['denom'] . '<br>';
Posted in PHP | Leave a comment

CRUD in Codeigniter

So a while back I started using MVC PHP framework called Code Igniter. The framework is really pretty basic, and unlike cake or rails, it doesn’t automatically do much for you in the models. So to make CRUD stuff easier, I created a basic parent model that does all the work. You can get it from gist.

To use it all you have to do is put the file in your libraries folder and then do something like this in your model:

1
2
3
4
5
6
7
8
 <?php
  class Something_model extends MY_Model {
  	function __construct()
  	{
  		parent::MY_Model();
  		$this->default_table = 'some_table';
  	}
  }

And then you’ll have access to things like “$this->Something_model->get_all()” all for free right in your controller. :)

Again, you can grab it from gist.

Posted in Codeigniter, PHP | 1 Comment

Disqus Comments with Jekyll

EDIT: I’m now on Wordpress. :)

So I just started this blog using the jekyll blog engine hosted over github. It worked out very nice, and I loved the flexibility. After setting it up tho, I realized it’d be nice to have comments on my blog. So here is a short little tutorial on how I set up my blog to use disqus.

It’s actually really simple to do, and I wouldn’t even bother writing a post about it except that I want to try out my shiny new blog engine… All you have to do is go and sign up for a disqus account. Then follow the tutorial for adding it, but just use the generic code. Paste snippet #1 in your post template file (layouts/post.html) so people will be able to see your comments. Then just add in snippet #2 right before the main layout (layouts/default.html), and you should be in business.

I haven’t really got into using the disqus api or ruby gems that are provided, but I’ll update if I get around to it. For now enjoy some sick comment awesomeness. ;)

Posted in GIT | Leave a comment