HTML — Non Destructive HTML Tabifier

For whatever reason, if you need a non destructive HTML tabifier, I’ve found a great one. It will NOT modify your code.

http://tools.arantius.com/tabifier

I’m working in a shopping cart environment that can only handle one template file for the product pages and it must be < 64kb, meaning I've started to remove all whitespace to fit in my templates.

You really can't argue that the size should be below 64kb, if you have one template to handle infinite product types.

Python — If Else Condition in Lambda Expression

I was writing a lambda function to decode unicode into UTF8 but needed a conditional as some items would be None.

The syntax for inline if else is..

'result' if 'condition' else 'else result'
map(lambda x: x.encode('UTF8') if isinstance(x, unicode) else x.__str__(), mylist)

Django — Ordering Admin / ModelAdmin Inlines

Ordering admin inlines is a common problem with a not so documented fix that I created. Even the BaseInlineFormSet.get_queryset() isn’t documented. By the way, it’s ever so slightly confusing that managers use `get_query_set` and this uses `get_queryset`.

To order admin inlines, specify the FormSet used by the Inline and override get_queryset() in your formset definition with ordering.

from django.forms.models import BaseInlineFormSet

class OrderedFormSet(BaseInlineFormSet):
    def get_queryset(self):
        return super(OrderedFormset, self).get_queryset().order_by('-sortfield')

class MyInline(admin.TabularInline):
    model = Item
    formset = OrderedFormSet

Django Docs Down

The django docs are down!

It occurs to me I’ve been preaching about how amazing the docs are. If I lost access to them, they wouldn’t be so useful.

I’ll go look into downloading them. Apparently they are in the release folder. I’ve never looked 🙂

WordPress — Disable Proofreading

I put this one off for months because I could never find the settings and google searched didn’t return very helpful results.

Proofreading settings live in Users > Personal Settings

SolidWorks — Where is the Show Feature Dimensions Button?

I’m trying to use a spreadsheet driven part because I will be trying MANY different sizes and combinations of these parts experimentally to find a design I like.

Configurations were not the answer, as I’d still need go into the part and manually change the extrudes, save as a new configuration, etc.

Anyways, to use design tables, you need to see your feature dimensions, and the solidworks help files just say “Annotations > Show Feature Dimensions”. It’s definitely not in the options tool, no, it’s in the right click menu of “Annotations” in your Feature Manager.

Laser – Structural Beam Bending Calculations

This is the first post in the Laser category. I wrote “Structural Beam Bending” because I am not referring to a laser beam, but an aluminum beam in my laser.

It took me a while to get back on the engineering concepts train. The last time I did any unit conversions at all was at least 5 years ago.

The first major hiccup I experienced while attempting to do beam bending calculations with a program called BeamBoy was that I wanted to determine my beam lengths in inches. All of my material data is in metric, so converting mm4 to in4 took me a moment to realize you simply divide by (mm/inch)^4, which is 25.4^4, or 416,231.4256

Unlike programming, physics information is not as readily available in easily digestible formats. I will outline my experiences to help anybody else who stumbles across this blog.

To calculate beam deflection:

Find your material’s Moment of Inertia, Modulus of Elasticity, and the Distance to Farthest Fiber.

My parts come from Misumi, so their data sheet looks like this:

The Moment of Inertia for the two axes are clearly shown. The Modulus of Elasticity is a property of the material, and I couldn’t actually find the exact grade of aluminum Misumi is using, so I looked online for average values and it ranged from 9,000,000 PSI to 11,000,000 PSI.

Distance to farthest fiber is the farthest distance from the beam’s neutral axis, so I interpret that to be 1/2 the width. This may be wrong.

First, start up BeamBoy and type in the length of your beam.

Enter in the properties of your beam as discussed above: moment of inertia, modulus of elasticity, and distance to farthest fiber.

Next, add two supports to your structure, I simply added a support at the start and end of my beam.

Add a distributed load over the length of your beam equal to the weight per distance (in my case, lb/ft) to simulate the weight of the beam itself.

Optionally, add a distributed or point load to the beam. I wanted maximum deflection for a given weight so I used a point load in the “worst” possible spot: the center, away from my 2 support structures.

Click calculate and see your results!

PS: I tried doing this in Solidworks beam modeler but the results don’t seem to be accurate.. Perhaps it’s because I was using a distributed load?

The Solidworks beam simulation is potentially a huge time saver as you the length, material properties and thickness is auto calculated.

Just can’t trust it yet.

Programmatically log into a website with Python and urllib, urllib2. This one for my django.

"""
Log into Django Site
====================


By Yuji Tomita
2/22/2011
"""

import urllib
import urllib2
import contextlib


def login(login_url, username, password):
    cookies = urllib2.HTTPCookieProcessor()
    opener = urllib2.build_opener(cookies)
    urllib2.install_opener(opener)
    
    opener.open(login_url)
    
    try:
        token = [x.value for x in cookies.cookiejar if x.name == 'csrftoken'][0]
    except IndexError:
        return False, "no csrftoken"
    
    params = dict(username=username, password=password, \
        this_is_the_login_form=True,
        csrfmiddlewaretoken=token,
         )
    encoded_params = urllib.urlencode(params)
    
    with contextlib.closing(opener.open(login_url, encoded_params)) as f:
        html = f.read()
        
        print html
    # we're in.