the state of fluxt

Software engineer, political news junkie, kind of obsessed with volleyball, tennis and snowboarding. Other topic liable to be covered here, in the grand and generic tradition of the mid-20's college-educated city-dwelling white male: college football, cooking and restaurants, beer, and economics

Recession

Yglesias says 'Oy', to which I reply, 'Ack!' That's all.

Using sed to delete multiple lines below a pattern

I needed to remove a 7-line create statement and two neighboring alter statements from a set of SQL migration files, and I came up with the following sed one-liner:

 sed -i '/CREATE.*some_table/,+6d;/ALTER.*some_other_table.*some_column/,+1d' migrations/from*.php

This finds the line "CREATE TABLE 'some_table' (..." and deletes it, plus the 6 lines below it.  It also finds the line "ALTER TABLE 'some_other_table' ADD COLUMN 'some_column'..." and deletes it, and the line below it.  The trickiest part was figuring out the ,+1 syntax, which says do this for this line and the X number of lines below it. Also note the -i option actually changes the file.  If you want to test your sed command, just run sed without -i and examine the output.

Earl update

Impacts
The primary threats from Earl are going to be surf, wind, and storm surge. The wind threat is going to be greatest in eastern MA since the passage of Earl is expected to bring hurricane-force winds to Nantucket. Eastern Long Island will have the greatest winds outside of MA, with estimated winds of 30-40 mph, with gusts to 55 mph. This is expected to bring down trees and cause trouble for older mobile homes. Elsewhere between the Outer Banks and New England, expect weak tropical storm force winds (less than 35 mph).

Phase 1

Bed, tv, dresser, chair, tivo.

COUNTDOWN: ZERO

College football is coming.

Prank

Atop the MIT building of course.  Not sure how I missed this one from a week ago. My question isn't how did they get it up there, but where the hell did they get the box?

Earl

Impact of Earl on New England
Residents in Eastern Long Island, Rhode Island, and Southeast Massachusetts need to complete all of their hurricane preparations by early Friday morning. By Friday afternoon, winds will rise quickly. Earl's recent increase in strength means that New England will see a stronger hurricane than was expected. The latest track forecasts still keep the eye barely offshore, or have it passing over Nantucket and the extreme eastern tip of Cape Cod, Massachusetts. The 5am NHC intensity forecast calls for Earl to have top winds of 100 mph at 2am Saturday, when the storm is expected to be over or just offshore of the eastern tip of Cape Cod. Earl will be moving near 25 mph at that time, meaning that that top sustained winds on the north side of the eye, over land, will be 50 mph, and the winds will be 100 mph on the south side over water. NHC is giving a 10% chance that a storm surge of 3 - 5 feet will occur in Long Island Sound (Figure 4), and 2 - 3 feet along the south coast of Long Island. A small deviation in Earl's track to the left, resulting in a direct hit on eastern Long Island and Providence, Rhode Island, would probably be a $10+ billion disaster, as the hurricane would hit a heavily populated area and drive a 7 - 15 foot storm surge up Buzzards Bay and Narragansett Bay. The odds of this occurring are around 3%, according to the latest NHC wind probability forecast. The forecast is calling for a 28% chance of hurricane-force winds on Nantucket, 7% in Providence, 4% in Boston, 7% in Eastport, Maine, and 17% in Hyannis.

Density

if the entire state of Maine (35,385 square miles) were as densely populated as the city of Somerville, Massachusetts (18,147 per square mile) it could hold over 640 million people

Mongo DB is web scale

Writing your data to /dev/null is really fucking fast.
As of this moment I officially resign my job as software engineer and will take up shoveling pigshit and administering anal suppositories to horses because that will be 1000x more tolerable than being in the same industry as dipshits like you.

Shell renaming

As a follow up to the previous post, it turns out renaming files without perl rename can be a bit of a hazard.  I needed to find some set of files in a directories This or That, and move the word "Foo" from the beginning of the file name to the end of the file name.  Luckily, between Stu, some man pages, and some sed one-liners I was able to come up with the following one-liner that did exactly what I wanted:

find . -name "Foo*.php" | egrep "(This|That)" | while read line; do echo "mv $line $(sed 's/\(.*\)Foo\(.*\)\.php/\1\Foo\.php/' <<< $line)"; done | sh
  1. Find all files whose name starts with "Foo"
  2. Filter for only paths that contain "This" or "That" - note that this could possibly be done using a find -regex but it wasn't cooperating with the OR statement so I used egrep
  3. Pipe the list of file paths to an in-line shell script that reads each path one at a time
  4. Construct a mv command consisting of "mv", the initial path, and then use sed to manipulate the initial path into the destination path
  5. Echo the command
  6. Pipe to shell

Note: it's recommended to review the echo'd commands before piping to shell, although if you're in a version controlled environment like git this is obviously less of an issue :)