open without leaving process fragments in your terminal
31 August 2009 at 18:54
Filed Under: coding
open()
{
NO_ARGS=0
if [ $# -eq "$NO_ARGS" ]
then
echo " enter a program";
else
$1 &>/dev/null &
fi
}
PHP Validation and Sanitization with filters
31 August 2009 at 08:39
Filed Under: coding
One of the most common problems in web development in validating and sanitizing user inputted data. Often, we're tempted to reinvent the wheel when validating emails, ranges, booleans, etc. Fortunately, php has a lot of these tasks already written. You can use the built in filters to validate and sanitize in a manner that's already been tested and optimized by the core developers. Documentation:
Validation:
$email = 'test@example.com';
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo 'This (email) email address is considered valid.';
}
$ip = '127.0.0.1';
if (filter_var($ip, FILTER_VALIDATE_IP)) {
echo 'This (ip) IP address is considered valid.';
}
$int_example = '4';
$options = array(
'options' => array(
'min_range' => 0,
'max_range' => 3,
)
);
$options['options']['default'] = 1;
if ($int_example = filter_var($int_c, FILTER_VALIDATE_INT, $options)) {
echo 'This (int_example) integer is considered valid (between 0 and 3) and is $int_example.';
}
Sanitization:
$c = '(bogus@example.org)';
$sanitized_c = filter_var($c, FILTER_SANITIZE_EMAIL);
if (filter_var($sanitized_c, FILTER_VALIDATE_EMAIL))
{
echo 'This (c) sanitized email address is considered valid.\n';
echo 'Before: $c\n';
echo 'After: $sanitized_c\n';
}
$search_html = filter_input(INPUT_GET, 'query', FILTER_SANITIZE_SPECIAL_CHARS);
Howl
29 August 2009 at 07:34
Filed Under: coding
I saw the best minds of my generation destroyed by
coding, starving hysterical naked,
debugging their code through var dumps at
dawn looking for an angry fix,
angelheaded hipsters scripting for the ancient
heavenly connection to the starry dynamic typing
in the machinery of night,
who poverty and tatters and hollow-eyed and high
sat up smoking in the supernatural darkness of
the web floating across the tops of integers
contemplating lisp,
who bared their brains to Heaven under the C and
saw Euclidean angles staggering on
algorithms illuminated,
who passed through universities with radiant cool
eyes hallucinating data structures
among the scholars of war,
who were expelled by startups for crazy &
committing obscene codes on the windows of the skull,
who cowered in unshaven rooms in novelty t-shirts,
burning down charts and sprinting toward
the Terror on their wall
The Insufficiency of SCRUM
19 August 2009 at 11:50
Filed Under: coding
Interesting analysis of creeping issues in SCRUM. Having recently adopted SCRUM I haven't seen the problems described here yet, but it'll be good to keep an eye out.
Using gmdate()
19 August 2009 at 11:32
Filed Under: php
Recently at work I came across an odd bug involving gmdate(). A client wanted us to post some information to them including two fields: source_date and source_time. The values are really just the time when we're sending the information to them. However, they wanted it to be sent as GMT. So in preparing the request, I wrapped the source_time in gmdate(), tested and confirmed that it was giving the correct result. Then during an audit of their data they pointed out that around midnight our time would swing back 24 hours. Of course the issue was not wrapping the source_date in the same function. By not doing that our time would advance to tomorrow (from our perspective) but the date would be sent as today - therefore appearing to them as 24 hours previous. It's an easy bug to fix, and obvious once you think about it. I think it really shows the danger of failing to imagine edge cases - always a danger when working with dates.
