This is the second post in my series on the Kohana php framework. For more, see:
Part 1: Getting started with the Kohana php framework
One of the simplest, and most basic security precautions that you can take is to move your application’s files into a non-public area of your webhost. Having your applications code and configs sitting there in your document root is just never a good idea. An attacker could very easily gain access to the source code of your application, as well as configuration. Next thing you know, there’s empty beer cans all over your apartment and the silverware’s missing. In general, this applies to any kind of web based application, but I’m going to be dealing specifically with Kohana, as part of my series on Getting Started with Kohana.
This is the first in a series of posts on installing and using the Kohana PHP framework. For more in the series, see:
Part 2: Moving Kohana out of the docroot
Kohana is an open source, object oriented, MVC framework that originated as a fork of the CodeIgniter project.
For a long time, I’ve been a big fan of CodeIgniter, the PHP framework. I’m still a big fan. CodeIgniter is lightweight, fast, and has a short learning curve. The problem is that it’s dead in the water, see http://ellislab.com/blog/entry/ellislab-seeking-new-owner-for-codeigniter. After looking around at some other options, I’ve started putting Kohana through it’s paces. Kohana was originally a fork of CodeIgniter, although later versions have been rewritten from the ground up. So, first off the bat, there’s that shared ancestry, which should mean that a lot of my CodeIgniter knowledge will be directly translatable to the Kohana world. Kohana also keeps that commitment to being fast and lightweight. That’s important to me. A framework is a development tool. It should enable me to get something up and running quickly, but it shouldn’t be so heavy that it gets in the way. Kohana looks like a good option, so I’m going to take a look at what it takes to get something up and running.
In a recent post, I looked into powerline, a bash status line utility. Powerline looks pretty cool, and I really wanted to run it, but try as I might, I just couldn’t get it working with my set up. Specifically, it doesn’t work really well with tmux. If you spend as much time on the command line as I do, them tmux is indispensable for serious work. That’s another post, but what I really want to talk about is how I emulated some of Powerline’s features using just the native tmux configuration. In addition, there’s a great Vim plugin, airline, which is sort of a vim only powerline. Using the combination of tmux and vim-airline gives me a status line that I’m really happy with.
In my day job, I deal with a lot of perl. After really taking the time to learn it, and working with it in a production environment, I really have a new respect for perl. But that’s a topic for another day. The other day, someone presented me with a perl coding challenge, and it took me a while to come up with the answer. Granted, I’m not really a perl guru, so I’m not too concerned, but I wanted to talk about and document how I solved the problem. The challenge can be simplified a little bit, and restated almost like a homework problem:
Given 2 arrays, find the union, intersection and difference.
See, here’s the thing. Most every other high level language makes this pretty trivial. PHP has the built in functions
array_diff, in Ruby, you can just do something like
ary1 & ary2 or
ary1 - ary2, etc… Perl’s arrays suck eggs. I’m serious, arrays in perl are virtually useless… Well, that’s too strong. Array’s in perl are emenintly useful, they’re just kind of dumb. In order to do most serious processing in perl, you wind up turning things into hashes. And that’s basically what you have to do to get the array intersection, difference and union. Here’s a little script that does the job.
Probably the most popular post in the history of this blog is “Populate DropDowns with jQuery and Codeigniter”. In that post, I gave a quick overview of how to set up a dropdown or select box that depends on the value selected in another form element. That post was never really intended to be a complete “How To”, but it’s been such a popular post that I wanted to revisit the idea, and write up a more complete discussion of this technique.
What I’m going to do here is to create and populate an HTML select element using values that are dependent on a selection in another HTML input. In this case, I’m using two select elements, but you could adapt the technique for any kind of input. For example, let’s say you have a form that displays data for a zip code. Now, there are a LOT of zip codes in the US, and you probably don’t want to make your users scroll through such a long list to choose the value they’re interested in. So, you add another HTML select element that allows the user to choose the specific state that contains the zip code. So, initially, the zip code select element is blank, or set to some default value. Then once the user chooses a state, the zip code element is populated with all of the zip codes for that state. Nice, huh?