ruby static typing

Check my post

http://aspn.activestate.com/ASPN/Mail/Message/ruby-talk/3617312

for the code of a first hack at a parameter checker [and a poor one, at that].

though there’s something about ‘Numeric’ in there posted in a later post

a competitor project appears to be the ‘types’ library

http://www.codecommit.com/blog/ruby/adding-type-checking-to-ruby

though you can decide which one looks prettier :)

-R

how to avoid back pain as a programmer (short one)

To avoid back pain…well if you have some then the steps to take are to fix the cause of it and do back exercises (lower and upper–maybe depending on where the pain is) twice daily or what not.

Fixing the cause of it is the tricky part.  I can give some advice if you use a computer….

For me I have to be able to sit so that my back is like straight up–but still well supported in the lower region when it is.  That means a chair that is super flexible or what not.  The keyboard has to be pretty low–low enough that your elbow are about at a 90 degree angle and then your fingers still go down to the keys.  I guess everything is at a 90 degree angle.
Your chair should also be low enough so that your feet at easily flat (so taht they can push back against your body and your back–push it into that seat which supports your lower back).

Since my home work here is not set up for it very well, though, I just use a back brace that I bought at walmart (you sit down, then strap it around you) and it has helped me a lot.  So I’d say overall the trick is getting your work space set up so that it supports you.

Don’t know if that made sense but anyway good luck and I can answer questions if you have any.
Overall sit forward, keyboard way down, and still be supported.

seashore shadows

So…you have something circular in seashore and you want to create a shadow for it, eh?

This is actually somewhat possible!

First: the background that you want to not see (completely transparent) must be black.

If it is currently white and you have any pixels that are ‘half and half’ (faded white or what not), then you’ll need to  convert the whole image to black background

1) invert the colors

2) re-draw the colors of the visible areas with what you really want

Next create an overlay that shows only the areas you want visible (as in creating a normal transparency).

create normal transparency

http://www.uoregon.edu/~noeckel/BitmapGraphics.html

Next create a second layer to your image.

Make sure you’re viewing only the  alpha layer of your second layer.

Now here’s the tricky part:

Cut your new layer in half where you want shadows to begin, then move that layer in the direction the shadows should fall (i.e. if you have a circle and want a shadow to the left of it, then you’d select the leftmost half of the image, and then just move that half left a little more).

Currently it should have a very dark dark shadow :)

Now set that layer to have say 50% transparency .

Now smudge the entire length of the shadow where it will be (its edge) and it should look all right.

static typing in ruby

Posted some code to my useful functions (and on the mailing list) of a method for arbitrarily static tpying ruby.  Still flexible like ruby.  Still controllable, like  Java :)

http://code.google.com/p/ruby-roger-useful-functions/wiki/Summary

rails mime help

Ever get this?

NoMethodError (undefined method `call’ for nil:NilClass):
/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/mime_responds.rb:169:in `respond’
/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/mime_responds.rb:163:in `each’
/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/mime_responds.rb:163:in `respond’
/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/mime_responds.rb:105:in `respond_to’

This (for me) meant ‘you added a mime type, then used an browser that lists that mime type before others, meaning it is attempting to always render that mime type!’

To fix it I hacked into

actionpack-1.13.3/lib/action_controller/mime_responds.rb

and had to swap priorities for whatever reason.  Basically if you rewrite an existing mime type, you must always always render that in a render block, if you use render blocks, and a browser depends on its existence.

Anyway so the fix is to artifically give that a low priority in the render pipeline.

line 176 or so.

def respond

@mime_type_priority.push(@mime_type_priority.shift) if @mime_type_priority[0].to_sym == :degree # degree being the one added

also allows rails to work with opera now, and firefox 3 beta 4

how to test authorize.net SIM

The docs say that: 

4007000000027 + $70.44 total will generate error codes–doesn’t work for SIM. So instead use 4222222222222 with dollar count for error code.  HOWEVER it turns out that with SIM, it appears that no error codes will EVER be passed back to the relay response page, so they’re hard to test for (they’re all caught and reported to the user on authorize.net’s page).  However, AVS and CCV errors will be relayed, so you can check for those.

 

Note also that I believe with Paypal IPN that no also no errors are ever reported to the calling website.  Only success, though I’m totally clueless having never really examined it closely.  Not even sure how Paypal IPN works if it’s possible for them to “not get around to” calling back to the origin web site for awhile.  That is bizarre.