jlm-blog
~jlm

26-Oct-2005

Protecting running scripts from modifications

Filed under: programming — jlm @ 13:48

The shell reads scripts in as it runs, and not even nicely line-by-line, so when you modify a running script, weird things can happen as the shell gets inconsistent versions. Usually this just results in harmless errors like “/home/jlxmodmap not found”, but if you’re like me you worry about “rm tmpfile; process importantfile” turning into “rm importantfile”. The usual technique for the paranoid is to “mv script script.old; cp script.old script”; the shell sees the old script, which you keep unmodified, while you edit the copy. But it’d be nice if you didn’t have to do this everytime…

So, someone told me the trick of having all the work a script does happen in a shell function, which you call at the end of your script. I’m using this for my .xsession (canonical example of a script modified while it’s running), which looks like:

main() {
  do stuff
  do more stuff
  do even more stuff
  exit
}
 
main

voilà. It’s already read in all of main() by the time it runs it, so you can modify it freely, except when it’s just starting up and parsing things.

20-Oct-2005

Men are from Earth, women are from Earth

Filed under: science — jlm @ 17:04

So, the results from the meta-meta-analysis (seriously) are in: Despite what well-selling relationship books may tell you, men and women are way more alike than different. Ha! I figured this was all over-exaggerated and over-weighted.

Popular science version

Real science version

10-Oct-2005

Why to wear shoes, II

Filed under: biking, humor — jlm @ 07:17

[photo of my shoes]

30-Sep-2005

Ping!

Filed under: humor — jlm @ 14:19

This review of The Story about Ping made me (literally) laugh out loud.

[book cover art]

[link to amazon.com review]

24-Sep-2005

Spokes

Filed under: math — jlm @ 08:27

So, can spokes help hold our Orbital (see below post) together? After all, internal tension acts mostly transverse to the centrifugal force whereas a spoke would act mostly along it. How about attaching the spoke to its opposite point on the Orbital?

Well, centripetal acceleration at a distance r from the center we already worked out to be a = r·4π²/d². If the spoke has linear density σ, then the mass of a bit of spoke Δr long would be ΔM = σΔr and have weight Δw = aΔM = r·(4π²/d²)·σΔr. So the total weight of the spoke half would be w = ∫dw = ∫r·(4π²/d²)·σdr = (4π²/d²)·σ∫r dr = (4π²/d²)·σ·(r²/2) = (2π²/d²)·σr²   (integrating from 0 to the Orbital’s radius).

The tension on the spoke just from its own weight is that of both halves, or T = (4π²/d²)·σr². This gives a T/σ of (4π²/d²)·r² just for the spoke to be strong enough to support itself. With d = 86400 s and r = 2×109 m, we’d need a strength of 2×1010 m²/s², which is as much as we’d need for the Orbital to support itself with internal tension anyway! Tweaking values won’t help, as in both cases the equations work out to T/σ = a·r. I think this means that diametric spokes can only be less effective than a band at holding a spinning structure (of any size) together.

What if we add a hub? Then the tension on the spoke is halved, but we have the problem of holding the hub together. We can also vary the spoke thickness, because tension is not uniform over it: Near the Orbital, it’s only carrying the support load, but at the hub it has the load from its own weight as well. With constant specific material strength S = T(r)/σ(r) and support load s, and Orbital radius R, we get the integral equation T(r) = s + ∫rR dw = s + ∫rR r·(4π²/d²)·σ(r) dr, or σ(r)·S = s − ∫Rr r·(4π²/d²)·σ(r) dr.

This gives the differential equation σ’(r)·S = −r·(4π²/d²)·σ(r) with initial condition σ(R) = s/S. At this point, I had to go and dust off my old math books. In standard form, the diff. eq. is σ’(r)+(4π²/Sd²)·rσ(r) = 0. This has solution σ(r) = (s/S)·exp(−A(r)) where A(r) = ∫Rr (4π²/Sd²)·r dr = (4π²/Sd²) ∫Rr r dr = (2π²/Sd²)·(r² − R²).

This simplifies to σ(r) = (s/S)·exp((2π²/Sd²)·(R²−r²)). At the hub r=0, so we have σ(0) = (s/S)·exp(2π²R²/Sd²). So the tension on the hub is T(0) = s·exp(2π²R²/Sd²). Kevlar has a S = 2500 MPa/(g/cm³) = 2.5×106 m²/s². So, for each pound the Orbital supports, this would place exp(4000) = 101800 lb of tension on the hub. That’s farther beyond scrith’s capabilities than scrith is beyond ours. How about that miracle nanotube cable? S = 37 GPa/(g/cm³) = 3.7×107 m²/s², so T(0)/s = exp(286) = 10124. Trying to hold it together with a hub makes the problem much harder, not easier.

How big is an Orbital?

Filed under: math — jlm @ 06:38

In science fiction, it’s fairly common to use centrifugal force to simulate gravity in space. This is usually used for ships or space stations, but Larry Niven took it to an extreme with his famous Ringworld, which circles a star at orbital distance and spins enough faster than orbital speed to provide Earth-equivalent “gravity” against its inside. Iain Banks thought this was too extreme even for fantastically-powerful civilizations, so toned it down a bit by having a ring that revolves once per day and provides 1 g from its spin. (Niven’s Ringworld needed “shadow squares” between the ring and the star to provide night.) Banks calls these “Orbitals”, places them in planetary orbits, and implies that they’re of planetary dimensions. But, how big is an Orbital really?

Well, we want a period of about an Earth day (d), and centripetal acceleration of about an Earth gravity (g). Consider a point x on the Orbital at angle θ. x = r î cos θ + r ĵ sin θ. To provide an Earth day, the Orbital revolves through 2π radians in 1 d, so dθ/dt = 2π/d. Acceleration is the second derivative of position, so a=d²x/dt²=(-r î cos θ-r ĵ sin θ)(4π²/d²). We want ∥a∥ to be 1 g, so ∥a∥ = r·(4π²/d²) = g, or r = g·(d²/4π²). To match Earth, g should be about 9.8 m/s² and d about 86400 s, which puts r at about 1.9×109 m.

That’s huge! (Though not Ringworld huge.) The radius of the Earth is only 6×106 m, and Jupiter is “only” 7×107. An Orbital is 300 times as wide as the Earth. (Though potentially much shorter.) But still not orbital distances– it’s only 1% of the size of Earth’s orbit.

Now, how strong does an Orbital have to be? Well, let’s consider a small section of the Orbital subtending an angle Δθ. This will have length Δl = r·Δθ. If the Orbital has a linear density σ, this section will have mass ΔM = σ·Δl and weight Δw = g·ΔM = gσr Δθ. If the tension is T, the internal force at the edge of the section will be T î sin ½Δθ + T ĵ cos ½Δθ. The i component of this force holds “up” half of the section’s weight, the other edge providing the other half. Using the small angle approximation for sine, we get ½Δw = T·½Δθ, or T = gσr. So the strength we need is T/σ = gr = 2×1010 m²/s². If the Orbital’s cross-sectional area is τ, then the internal tensile pressure is P=T/τ so T = P·τ. If its material density is δ, then σ=δ·τ, so T/σ = P·τ / δ·τ = P/δ, which tells us that the 2×1010 m²/s² is the ratio of tensile strength to density we need. This is 10000 times as strong as existing high-tension materials like Kevlar (stuff like steel and titanium and diamond isn’t particularly strong in the tension department) and still 600 times as strong as the supposed carbon nanotubes that they say may make a space elevator possible. And this is just enough for the structure to not tear itself apart by its own spin, much less support anything you want to have on the Orbital. I thought solar tides might be an issue, being about 9×1020 N for each Earth mass of the Orbital, but the spin tension blows that away at 6×1025 N per Earth mass. So, sadly, even through this is orders of magnitude more feasible than the Ringworld, it’s still never going to work.

21-Sep-2005

Berkeley DB locking

Filed under: programming — jlm @ 18:28

The locking in Berkeley DB is fundamentally broken.

This isn’t something that’s bitten me recently, but talk about it did come up recently, and many BDB users are unaware of the problem. It’s especially surprising when you first encounter it because BDB is so solidly done in the rest of its implementation and the problem isn’t advertised. Of course locking will work — everything else does!

The problem is that BDB locks are bare mutexs, and no forcible release mechanism is provided. There is no way to rollback to a state before a lock was acquired. There is no way to retry. You take the lock, do your modifications, and release. Or you take the lock, do some of your modifications, and the circuit breaker trips, power is quickly restored, the server reboots, and now your BDB is hosed. You can’t take the lock because BDB thinks your old instance has it. You can’t release the lock because you don’t have it. If you could release the lock, your database is inconsistent because you can’t rollback. The only way you can do anything is to blow away the BDB environment and make a new one (suffering collateral damage when you just want to destroy a mere lock) and hope that the partial transaction you’re unleashing as a result isn’t a problem (and if it isn’t, why did you need a lock?).

So, what can you do? You can try to build your own transaction system on top of BDB, but that’s a lot of work. A lot of work, when there’s better featured databases out there already. If you were using BDB and need more, MySQL is probably good enough for you. It has partial transaction support (probably more than you want to write!), and does have a library implementation (libmysqld) so you can avoid running a server and just use data files, like in BDB. If you need full transaction support (good luck implementing that on your own), there’s always ye olde enterprise-grade PostgreSQL. Or maybe you don’t need transactions after all? Then Berkeley DB is solid as a brick.

9-Sep-2005

What is that thing, anyway?

Filed under: web — jlm @ 17:19

So, the firefox logo makes sense.

[firefox logo]

A fox, with a firey look. Cool logo.

But what’s that thing behind the fox? Well, with the Deer Park logo, we get a better look.

[deerpark logo]

But if you look closely, you see that the shapes on the FF globe don’t match those on the DP globe. And they don’t look like the continents I know. Maybe it’s just an ordinary circle with abstract shapes? But it’s shaded like a globe. Is it one of those funky extrasolar planets? (They’re planning a Galaxy Wide Web!)

I think I preferred the fox. I also liked the old Red Star mozilla logo, not so much the dino head or the big “m”. And don’t get me started on the ship steering wheel or the big “N”. Even the old NCSA Mosaic logo was better than those.

[mozilla red star][mozilla dinosaur head][mozilla “m”][ship rudder wheel][Netscape Navigator big “N”][NCSA Mosaic logo]

Why does every iteration of the product need a new logo? Doesn’t seem like the best way to build brand awareness. Compare:

[Microsoft Internet Explorer logo]

New Firefox

Filed under: web — jlm @ 14:27

Firefox 1.5 beta 1 (“Deer Park”) has just been released.

This was good timing for me, as I’d just updated GTK+ from 2.4.14 to 2.8.3 in order to get GnomeMeeting working, and that had broken Firefox 1.0PR, so I was back to using the old Mozilla 1.7 I had lying around.

Download pre-built versions at http://www.mozilla.org/projects/firefox/ or build it yourself from the source at http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5b1/source/

This will unpack into a directory named “mozilla”, so be careful about clobbering other mozilla builds if you have them. Build directions are at http://www.mozilla.org/build/

The “Starting the Build” directions didn’t work for me, instead I had to do what it has under the box: cd $objdir; ../configure; make

Oh, and the tarball it makes from make -C $objdir/browser/installer is tagged “1.4” still, but that’s minor enough. Now I just need for the extentions and “themes” (skins) to be updated.

Big screens

Filed under: general — jlm @ 09:53

I promised you a more upbeast post, so here it is…

Work recently gave me two very nice LCD monitors to replace those I’d been using before. 24″ TFT from Dell.

“Unfortunately”, the graphics card in the desktop I had (which I’d been using since getting hired) couldn’t drive these things, so they gave me a HP xw4200 to replace my xw4100, double the RAM and faster processor.

Now my computer can display on my monitors, but side by side things are very wide. But, these monitors can rotate on their stands! (Couldn’t do that with my old ones.) So, I want them vertical and side by side. Well, someone else had done the hard work of figuring out how to make that work, so I went and followed his lead. The distillation of that came down to:

  • Install the x.org X server (this deserves a post in itself)
  • Edit xorg.conf, turning off Xinerama and turning on xrandr (for now they’re incompatible):
    • In the “Device” Section, add Option "NoTwinViewXineramaInfo" "on"
      and Option "RandRRotation" "on"
    • Change TwinViewOrientation to “Above” or “Below”
    • In the “ServerLayout” Section, add Option "Xinerama" "off"
  • Put xrandr -o left at the start of your .xsession

Before and after screen shots at 1/8 scale:
[before]

[after]

I finally have enough space to have all the xterms I want! I’ve been trying to reach this state since forever, first with screen then with just piling the xterms onto all the real estate I could get. I don’t have to drop context and have space left over now. It’s surprising how good this feels– It’s this slight pressure that I never really noticed, the small frustation of having to look for somewhere to type– gone.

Powered by WordPress