Archive for the ‘Programming’ Category

Regex is COOL

Programming | Posted by attriel June 16th, 2010

We started on a Tuesday this month didn’t we?  damnit!

Well, on an unrelated note, Regular expressions kick ass.  Here’s one I cribbed together to break things on :-separated pairs with optional preceding un-paired text

We started on a Tuesday this month didn’t we?  damnit!

Well, on an unrelated note, Regular expressions kick ass.  Here’s one I cribbed together to break things on :-separated pairs with optional preceding un-paired text

We started on a Tuesday this month didn’t we?  damnit!

Well, on an unrelated note, Regular expressions kick ass.  Here’s one I cribbed together to break things on :-separated pairs with optional preceding un-paired text

‘/(.*(?!s+w+:|$))(w+):(.+(?=s+w+:|$))/U’

Also, zero-length lookahead is sick and twisted and I liky!

Perl … just wow :o

Externally Sourced, Programming | Posted by attriel April 17th, 2009

Hoping this shows right …

    ''=~(        '(?{'        .('`'        |'%')        .('['        ^'-')
    .('`'        |'!')        .('`'        |',')        .'"'.        '\$'
    .'=='        .('['        ^'+')        .('`'        |'/')        .('['
    ^'+')        .'||'        .(';'        &'=')        .(';'        &'=')
    .';-'        .'-'.        '\$'        .'=;'        .('['        ^'(')
    .('['        ^'.')        .('`'        |'"')        .('!'        ^'+')
   .'_\{'      .'(\$'      .';=('.      '\$=|'      ."|".(      '`'^'.'
  ).(('`')|    '/').').'    .'\"'.+(    '{'^'[').    ('`'|'"')    .('`'|'/'
 ).('['^'/')  .('['^'/').  ('`'|',').(  '`'|('%')).  '\".\"'.(  '['^('(')).
 '\"'.('['^  '#').'!!--'  .'\$=.\"'  .('{'^'[').  ('`'|'/').(  '`'|"&").(
 '{'^"[").(  '`'|""").(  '`'|"%").(  '`'|"%").(  '['^(')')).  '\").\"'.
 ('{'^'[').(  '`'|"/").(  '`'|".").(  '{'^"[").(  '['^"/").(  '`'|"(").(
 '`'|"%").(  '{'^"[").(  '['^",").(  '`'|"!").(  '`'|",").(  '`'|(',')).
 '\"\}'.+(  '['^"+").(  '['^")").(  '`'|")").(  '`'|".").(  '['^('/')).
 '+_,\",'.(  '{'^('[')).  ('\$;!').(  '!'^"+").(  '{'^"/").(  '`'|"!").(
 '`'|"+").(  '`'|"%").(  '{'^"[").(  '`'|"/").(  '`'|".").(  '`'|"%").(
 '{'^"[").(  '`'|"$").(  '`'|"/").(  '['^",").(  '`'|('.')).  ','.(('{')^
 '[').("["^  '+').("`"|  '!').("["^  '(').("["^  '(').("{"^  '[').("`"|
 ')').("["^  '/').("{"^  '[').("`"|  '!').("["^  ')').("`"|  '/').("["^
 '.').("`"|  '.').("`"|  '$').",".(  '!'^('+')).  '\",_,\"'  .'!'.("!"^
 '+').("!"^  '+').'\"'.  ('['^',').(  '`'|"(").(  '`'|")").(  '`'|",").(
 '`'|('%')).  '++\$="})'  );$:=('.')^  '~';$~='@'|  '(';$^=')'^  '[';$/='`';

That there is some nice formatting :o 

Source: http://www.99-bottles-of-beer.net/language-perl-737.html
Bottling (and obfuscating) done by: Acme::EyeDrops

Code Profiling

Programming | Posted by attriel April 14th, 2009

Working on a large project, we were adding a large new feature.  Extending an old feature with a lot more power.  Except it was taking forever.  So we decided to look into what the app was doing, compare the two (old feature vs new feature), see how bad of a difference it really was.

Timing it, it turned out to only be 12 vs 15 seconds in the worst case scenarios we could think of to try.  OTOH, for a webapp, they’re both horrendous answers.  That’s when we decided to look deeper.

Code profiling is that deeper step.  It provides usage statistics on how long each function takes, each callout, etc.  In the past we’d all done ad-hoc profiling by putting in some debug statements in places we thought were taking the longest.

print “STARTING FUNCTION XXX ” + now();

print “EXITING FUNCTION XXX” + now();

The problem with this, obviously, is that it requires foresight or backpatching.

Foresight because you can put this in every function with a call to a pair of defined functions that you null-out in production.
function enter_function(name) {
     if DEBUG {
          print “ENTERING ” + name + ” ” + now();
     }
}
That way you get the output, but it goes away in production (when debug is presumably set to false).  Of course, now you always have it for all functions (assuming it’s part of your function template so it always gets added)
The second option is backpatching.  Going through your functions and adding either the prints or the function call.  Which gives you the same problem, but now you’re no longer sure that you’re hitting all of the functions.
The third option is modifying the compiler/interpreter so that it puts in that code for you.  Which is, honestly, what we did with it.  Because it’s easier than drinking from the firehose or attaching the hose to a kitchen faucet.

When QA qAttacks!

From The Lines, Programming | Posted by attriel December 9th, 2008

So, we’re working on conjoining our quick development and structured development groups, at work.

First off, to define those …

Quick Development
I intentionally renamed this after initially calling it “rapid development” because RD is a defined methodology of development, which isn’t what I’m talking about. QD is, if you will, just development of scripts and small applications that consistently need a short turnaround. Get the project Monday, and if it’s a big project maybe get until the following Monday. But frequently of the “we need this by noon” variety. Small things, change this text, whip up something that provides the user with XYZ, etc.
Structured Development
The SD team, on the other hand, gets requirements, builds design documents, has a QA team associated with them, and frequently can get 6-12 months for a significant update.

Now, I’m not saying that the SD team doesn’t get “uh oh! the code in this app is wrong, it needs to be fixed before anyone goes home tonight!” issues (Error Reports, they get a high priority), and QD gets some tasks that take months, like completely changing how the system works. But QD is much less formalized and closer to “whoever reads their email first grabs whatever’s come in” in the morning, while SD has weekly meetings to assign out new tasks. Because no one expects them to be done immediately anyway, a few days here and there doesn’t slip the deadline any

But, as I said, they’re trying to conjoin the two teams. Which makes sense, why have two sets of developers? Except it’s running into some problems. First of all, the two teams use entirely different programming tools, in general. Java and PHP share little in common. Second, the mindsets are drastically different “I wonder if anything is on fire?” vs “What is on fire now?”. And then there’s the QA process. QD does their QA by internal testing. Usually the developer runs some tests based on vague commandments in the requirements. And if you ask for guidance, what you get is “Click around and make sure everything works.”

Now with QD expected to use QA for testing, we’re having to document our QA tests. And most of our tests are either vague (“I clicked a few things and nothing exploded”) or non-existent (“They said to change this to do X, now it does X”). This has led to some amusing issues of late.

On one project, we were asked to write a script that generates an email and lists the records matching X and Y. So we wrote the script, working with the people who needed the email to make sure we were matching X and Y correctly. When the script was done, we had them tell us that the email was correct and matched what they wanted. Then we had to send it to QA. Uh? OK. Here’s the script. Testing procedures? You run it. What’s the output supposed to be? Ask the people who want it, or I can give you the output from the last test I did and you can make sure it still matches itself … You want to test the automated execution of the script? But that not working is user, not coding, error! *sigh*

The other I’m still working on. This literally had directions of “Try various View links and make sure it displays the right stuff.” For my own testing I had expanded it to note the various KINDS of links to make sure I checked multiple options. I noted the various uses and the various conditions that should work or not (as in, if you change the date to before today to look something up, you can’t create a new entry in the past. Only the future. But today is OK, even before now today, as long as it’s still today. But not after 8pm, because that’s not today anymore, it’s tomorrow, but still show today … see why I needed notes?) Now I’m working on formalizing the testing for the QA team to test the latest updates.

It turns out that the set of options for just CLICKING AND LOOKING had 16 different variations. Maybe only 8, but to make sure that various links work I had to end up looking at the same generating page multiple times, but with slightly different data. Make sure that entries created by admins show up differently than entries created by users, make sure that if you choose column A and then change the date that you still get column A on the new date. Now make sure that picking column B leaves your date alone. Three views of the same page, but different tests.

I’m truly fearful of the vast number of tests for creating and editing entries. Because there are two types of entries, and each type has 3 or 4 sub-classifications. And they’ll all need to be tested. And that’s just for tests that should succeed. Then I need tests that should fail, to make sure the failure is meaningful and functional. Wheeee

Hopefully by the time this posts I’ll have finished the test listing and can fill this in with how many total tests there were in the end. But I’ll be shocked if it doesn’t clear 100. If it gets near 200, I won’t be done when this posts, because this is boring and that’d be like 40 a day … plus other projects that get higher priorities :o

Counterintuitive Much?

Programming, Site Maintenance | Posted by attriel September 4th, 2008

I was working on my other blog a little while ago.

First off, Kiir noticed the avatars on someone else’s blog and realized that ours supports them by default.  so she wanted an avatar.  She went and set up her account, getting it all set up nicely with a nice pic, rebuilding it a few times as she figured out the (apparently undocumented) size she could use.  Apparently it can take an 80×80 (gravatar this is) and it auto-resizes whenever someone requests a different size.  More to the point, it takes the smaller image, resizes it UP to 80×80, and then can resize down.  So her 50×50 didn’t turn out so well.  Actually, I think 80×80 is what I told her from something I read after she did 50×50.  I think she said it was noticeably larger still.  So yeah.

Then she went to look at the blog.  and her avatar wasn’t showing.  So she was fiddling with her gravatar account and her commenters account.  And there I am trying to get it working for her.  I’m looking at the IMG SRC (which, it turns out, auto-rebuilds to the ACTUAL src, which was the fallback default, rather than the full URL, so that confused me for a bit).  Then I’m digging through the code for the template, maybe guy broke it somewhere (yeah, because, you know, I’m the first person to ever try using gravatars on that theme).  digging, looking, debugging, wtfing.  Find the full URL.  Falls back to the default.  Try it piecemeal, and it worked all the way to the end.  Seriously, it took me 10 minutes and I eventually fell back to using vi and diff to fin the difference between the working URL that I put together and the broken one that it was using.

Near as I can tell?  One of them had ;r=G and the other had &r=G. There was also a difference in image sizes, technically.  I don’t know which of them was the broken part.  I’m guessing the & vs ;.  But it works for the other persons avatar, so thats obviously not it either.

So then I’m looking at the admin options, because maybe this is some kind of cached response thing … or something.  I finally turned off the default avatar, figuring maybe that’d flush whatever it was.  And suddenly it worked!  So I turned it back on, and it didn’t work anymore.

So, now, my other blog doesn’t have a default avatar.  Not sure about this one yet.  It doesn’t have any comments, so I’m not real concerned.

Problems with Python

Programming | Posted by attriel August 28th, 2008

One of the things I’m having to deal with at work lately is Python.  It’s used around the UltraSeek (nee Inktomi) search engine in use that predates me (and boy is THAT a nuisance)

And a few things I’ve learned about python so far:

  1. If I wanted to use a position-sensitive language, I’d go back to programming in FORTRAN.  whitespace should be used for making things pretty and legible, not for replacing “ugly” braces
  2. Bacchus-Nauer Form language definitions are NOT good user documentation
  3. The guy who wrote the local mods for this code was an idiot!

On the first point:  Seriously?  Whitespace structured code?  Jesus, Guido, (no, that’s not a slur, that’s the man’s name who designed python), did someone put out a hit on { and } ???  I’m scared to replace tabs with spaces, because, honestly?  I don’t know what effect that would have.  I think 1 space would===1 tab, but wtf knows.  Because back in FORTRAN we used spaces b/c those first couple columns had meaning.  I’m not versed enough in python to know all the ins and outs, but I think it’s just “whitespace”. 

Point the second, BNF.  Don’t get me wrong, I can read BNF.  I actually LIKE BNF definitions.  They’re great for the details and nuances of “what can I put here” once you’ve got the basic setups.  But for interpreting “what does this line do”?  BNF SUCKS.  Because now you have to know the answer to know where to look for the answer.

For instance.  How do I print out the contents of a variable who’s type I don’t know?  Only way to print anything that I’ve found is “write(variable)” (no EOL markers, b/c the newline character is whitespace and thus meaningful, ooooh).  I’m sure if I knew python I’d know how to write the equivalent of PHP’s print_r() or var_dump().  But because I don’t, the official docs that I found on python.org don’t help any.  Oh, and join(“,”, $array)? join(“, “, @arr)?  yeah, reading the docs, it’s supposed to be “, “.join(arr) … uh, W T F?  I have to make an string variable, assign it the conjunction, then use it to invoke join?  who joins on the conjunction?  arr.join(“, “) would be SOOOO much more logical I’m sorry.  And I still haven’t figured out how the code is doing when it calls “string.join(arr, “, “)” … because string doesn’t have a join that takes two parameters.

I’ll grant this:  Coming from Perl (language of line noise) to looking at python (language of whitespace) is kindof a long jump.  They’re kindof conflicting paradigms, honestly.  But still.  I hate python.