Ideas are a dime a dozen
30 April 2010 at 09:23
Filed Under: coding
It's common for the "business" people to have an idea and think that's what they're bringing to the table. I've had guys approach me to offer 5-25% equity in their imaginary company if I'll just build the product for free.
My response is, generally, "How about I build this and hire you when I'm done to sell it?" They'll protest "But this is my idea!" Who cares? Ideas are worth absolutely nothing. I have stacks of ideas that are gathering dust because I haven't had the time to do anything with them. Why should I suddenly stop everything and try to make you rich with my skills and then, inevitably, watch you try to screw me later if it works? Because you had an idea? Awesome - go to the library and check out PHP for Dummies and see if you can execute it.
Sales that haven't occurred are also worth nothing. If you want me to work for you, you need to bring something to the table - a paycheck, capital in the bank, connections or contracts that have been signed on the line that is dotted. Otherwise you're just a loser in a suit looking for a handout.
Reposted from a comment on reddit
Coder's Vocab #1 : Idempotent
09 April 2010 at 09:00
Filed Under: Vocab
In programming, the term idempotent describes a method that can be called multiple times without changing the result. Sometimes it can be a symptom of madness or incompetence - I've seen code where a save() method was called repeatedly "just in case."
Besides scratching the itch of the insane among us, idempotent routines are important. For a simple example, consider the "Checkout Button" on a typical ecommerce form. Often you will see strong language around the button asking the user to only click the button once - otherwise multiple orders will be placed and all sorts of pain and confusion may result. A common "solution" to this is disabling the button after the first click. A better solution would be writing the routine that is saving the order as an idempotent operation. In other words, it shouldn't matter how many times you save the order, you're just saving the same thing. This can be accomplished in myriad ways, from using a "replace into" database query or creating the key once and updating the database against that key.
Quiz Time! Which of the methods could be described as idempotent?
1.
function double($x) {
return $x * 2;
}
2.
$x = 2;
3.
$x = md5($x);
4.
function append($x,$y){
$x[] = $y
}
How to get Xinha Wysiwyg editor to work in S9y
16 November 2009 at 20:40
Filed Under: coding
For some reason I hadn't been able to get any of the wysiwyg editor plugins in my serendipity install to work. It's been a minor annoyance, so I decided to figure it out tonight. Here are the steps:
- Go to Configure Plugins and download/install the Xinha plugin. If you're lucky, it'll just work.
- Download the Xinha package from the xinha website.
- Drop the file you downloaded (Xinha_0.96beta2.tar.bz2 for example) in a folder of its own.
- Run bunzip2 Xinha0.96beta2.tar.bz2 on the command line in that folder.
- Then run: tar -xvf Xinha0.96beta2.tar
- Copy the files extracted to your plugins folder at:/plugins/serendipity_event_xinha/
- Refresh and hey - it actually works.
mySQL Murder
07 November 2009 at 11:47
Filed Under: coding
Good presentation from Jay Pipes about big mistakes you can make when developing with mySQL. I particularly like the point of not thinking in loops but in sets.
Building an Object Collection Manager with the SPL
Graphs in the database: SQL meets social networks
07 September 2009 at 14:41
Filed Under: coding
Graphs are ubiquitous. Social or P2P networks, thesauri, route planning systems, recommendation systems, collaborative filtering, even the World Wide Web itself is ultimately a graph! Given their importance, it’s surely worth spending some time in studying some algorithms and models to represent and work with them effectively. In this short article, we’re going to see how we can store a graph in a DBMS.A follow up to: Trees in the database: Advanced data structures
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.
Forking PHP
23 July 2009 at 16:10
Filed Under: coding, php
Interesting code used to fork long running processes in php.
The first script, prefork.php, is for forking a given function from a given file and running n children that will execute that function. There can be a startup function that is run before any forking begins and a shutdown function to run when all the children have died. The second script, prefork_class.php, uses a class with defined methods instead of relying on the command line for function names. This script has the added benefit of having functions that can be run just before each fork and after each fork. This allows the parent process to farm work out to each child by changing the variables that will be present when the child starts up. This is the script we use for managing our Gearman workers. We have a class that controls how many workers are started and what functions they provide. I may release a generic class that does that soon. Right now it is tied to our code library structure pretty tightly. We have also included two examples. They are simple, but do work to show you how the scripts work.from: http://brian.moonspot.net/php-fork
