Crawlicious | tools for web business

Archive for May 2009

May/09

26

perfection

I read a great quote by a commenter to the zenhabits.net site.

Perfection is attained not when there is no longer anything to add, but when there is no longer anything to take away — Antoine de Saint Exupéry, Pilot, Poet and Author of the book “The Little Prince”

Hide

May/09

25

Wordpress Hooks Resource

I found a great resource on wordpress hooks

http://wphooks.flatearth.org/

Thanks flat earth people!

Hide

This is in response to an earlier post about making GET work in Codeigniter

Basically I need GET in CodeIgniter, but I didn’t really want to apply the patch that I found on the Internet. I wanted a very simple solution, and I like the hook idea a lot better, so I followed the pattern from the second link, but it was by no means complete. Here is how I did it.

Enable hooks in system/application/config/config.php

$config['enable_hooks'] = TRUE;

Added a “pre_system” hook array into system/application/config/hooks.php

$hook['pre_system'] = array(
    'class'    => '',
    'function' => 'allow_query_string',
    'filename' => 'allow_query_string.php',
    'filepath' => 'hooks',
    'params'   => array()
);

Added a hook file system/application/hooks/allow_query_string.php
with the following contents

function allow_query_string() {
    if (strlen($_SERVER['QUERY_STRING']) > 0) {
        $temp = @array();
        parse_str($_SERVER['QUERY_STRING'], $temp);
        if (array_key_exists('token', $temp)) {
            $_POST['token'] = $temp['token'];
            $_SERVER['QUERY_STRING'] = "";
            $_SERVER['REDIRECT_QUERY_STRING'] = "";
            $_GET = @array();
            $loc = strpos($_SERVER['REQUEST_URI'], '?');
            if ($loc > -1) {
                $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $loc);
            }
        }
    }
}

notes: your get parameters will appear in the $_POST array, it is very important that you keep that input safe by xss_clean’ing it

$this->input->xss_clean($_POST['token']);

In the allow_query_string.php you will notice that I am specific to ONLY allow the GET arg ‘token’ because that is all that I need right now. Later I may need to modify that, or eliminate it all together.

Hide

May/09

18

database resource

Here is a fantastic resource about how to (from postgresql sql) get the metadata of the current database. alberton. I am going to use this to dynamically set the maxlength field on my html fields, so that the fields don’t allow too much data into the system. I know that this is not going to help in an intended attack, but it keeps normal users from seeing strange behavior.

No tags Hide

May/09

15

laptopmemory

I have wanted to upgrade my laptop to 2Gig of memory for a long time now. It is kind of a pain to have to turn off firefox to start up VirtualBox. If I don’t, my computer goes in to la la land (swapping to disk)… Well, the other day I was sad to have to be turning off my music (shutting down Pandora in firefox) and so I thought, hey, I will just check to see how much memory is going for these days. Boy was I shocked. First off, Dell (my laptop manufacturer) was the cheapest, that is amazing. The second surprise was that for 2Gig, shipping, handling, etc etc, the total cost was $38! That is absolutely shocking… Too bad my laptop can’t handle more than that, or I would have grabbed 4 sticks.

I will let you know, running with 2Gig is quite cushy, I am currently running both firefox AND VirtualBox, and there is still 94M available ;-) .

Make it a happy day!

Eric

Hide

So, yesterday my boss had some unusual weirdness with a bash shell script that he was writing and together we were able to figure out what was going on. Here is a boiled down example of it.

He wanted to test that a file didn’t exist, and if so, perform some action. He wanted to use the ‘-a’ conditional test directive. Here is a little example.

if [ -a 'afile' ]; then echo "exists" ; else echo "not exists"; fi

when the file exists, it prints ‘exists’, and when it doesn’t exist, it prints ‘not exists’.

So far so good. Well, lets just switch things around a bit. He wanted the first condition to be the negative sense so we use the ! (bang) to not the results of ‘-a’.

if [ ! -a 'afile' ]; then echo "not exists"; else echo "exists"; fi

Well, this always prints ‘not exists’ regardless of the existence of the file. Now switch the operator to ‘-e’ (which is the operator that I use usually).

if [ ! -e 'afile' ]; then echo "not exists"; else echo "exists"; fi

Now things work as expected…

If you look up the man page for bash, you will see why my boss wanted to use ‘-a’, it is listed there as …

-a file
True if file exists.

And -e has an identical entry.

But, if you look up the man page for test, then you will see a different story.

EXPRESSION1 -a EXPRESSION2
both EXPRESSION1 and EXPRESSION2 are true

So, the question is, why is the ‘-a’ being processed by test instead of the shell? It is because in the if clause we are using ‘[' to initiate the test. '[' is actually the 'test' command (try running man [, or which [ ). Basically test was being asked if '!' is true and 'afile' is true, and they weren't.

So, use '-e' to eliminate that confusion, because '-e' means equal in both bash and test. Also, you could phrase it this way...

if ! [ -a 'afile' ]; then echo "not exists"; else echo "exists"; fi

i.e. put the bang outside of the test command.

There are many other ways that you could write this, but as you can see, for the sake of eliminating confusion, you should always prefer to use '-e' over '-a' when shell scripting.

Hide

May/09

11

url shortener

When you are writing a blog entry, or posting a Twitter update, or a Facebook status change, you may need to include a url. Normally I would just put the url in and call it good. But I have finally found a very important reason to use a url shortener. Url Shorteners are not new, they have been around for quite a while and I have tried them once or twice, but mostly ignored them. Now that I am interested in knowing more about how people respond to my posts, I have found that the bit.ly url shortener is most valuable. You can log in and trend how many people have used the url over time. Yes, Yes, I know, I should probably have my metrics tracking set up on my blog and all that, but I don’t. Furthermore, if I did, I would still not know how many people got there from which link that I released. If I want to track which is getting more exposure, Facebook, or Twitter, then I can create 2 links to the same place and then see which one gets more clicks. So, my new approach to linking is to first go to http://bit.ly (make a free account if you don’t have one yet), and paste in my long url, bit.ly will give me a nice little short one (one that fits better in facebook and twitter). As my post becomes more popular, I can see that people are clicking on it from bit.ly’s site. So, in the future you may want to also use a service like this. It sure makes things easier to track and it is easier on everyone’s eyes too.

, , Hide

May/09

8

Vim Macros

Vim Macros

I love vim macros, they are so very useful. How do you make and run a macro in vim? Here is a simple one to delete lines that have the word ‘test’ in them.

First off, this is all going to happen from right in the editor, while in command mode, not really on the command line, but right from within the editor screen like you would a search. If you are in edit mode like insert or overwrite, simply hit escape.

First off, as you build this macro, you will be actually doing an edit to your file. That is because a macro simply records an action for later replay. So this wouldn’t make sense if you only had one line with the word test in it.

qh <- this starts recording (and will dump the macro in to the h buffer)
/test <- this searches for lines with the word test
dd <- this deletes the line
k <- this moves up a line (in case the next line had the word test in it also)
q <- this stops recording

Now you want to run the macro in the ‘h’ buffer. To do this, type @h. Do you like what happened? OK, now to run the h macro 100 times, simply type 100@h.

Did that delete 100 (if you had that many) lines in your buffer with the word test in it? I hope so.

You can record any vim action in a macro, so have fun with it and see what you can come up with.

Hide

I have often wondered the same thing. Other than money, what does a programmer have to offer in trade with graphic artists?

see

http://blog.aisleten.com/2009/05/07/what-does-a-programmer-have-to-offer/

for the discussion

No tags Hide

Silly internet exploder. I get almost no feedback on an error in my javascript. I get a line number, but no js file to look in. So, I go through each js file, adding text to try and offset the line number. I finally find the right js file and guess what was my error? A comma. Yes folks a comma at the end of an array like this.

var x = {foo:'bar',};

ie will not process this and will not tell you what the problem is… it should have been like this…

var x = {foo:'bar'};

ARGGGG!!!!!!
I love Internet Explorer!

No tags Hide

« Previous Entries

Next Page »

Find it!

Theme Design by devolux.org