Converting a site to use Cachefly for static content

February 24th, 2009

I recently needed to move static content from a live site to a cachefly account. Rather than go through the directories, looking for the resources (js/css/images) I needed to ftp, I thought, “Man, this sure sounds like it could be automated”.

The first step was to collect a list of items that needed ftping to cachefly. I know what you’re saying, “Use find!” In case Ben is reading this, find “searchs for files in a directory hierarchy” (that’s from find’s man page Ben). I wanted to separate the resources out so I ran three different invocations.

For javascripts and css, the invocation was nearly identical:

find . -name '*.js' > js.libs
find . -name '*.css' > css.libs

Images were a little trickier. Most of the images are static content, but some are user-generated, likely to change or be removed. These do not go up to the CDN (at least for now). The user-generated content is located under one directory (call it /images/usergen), so we simply need to exclude it from find’s search.

find -path '*images/usergen*' -prune -o -path . -iname '*.gif' -o -iname '*.jpg' -o -iname '*.png' > image.files

The important parts:

  • -path '*images/usergen*' -prune

    Remove any found items that contain images/usergen in the path name.

  • -o -path .

    Search within the current directory (the root of the project).

  • -iname '*.gif' -o -iname '*.jpg' -o -iname '*.png'

    Match, case-insensitive (-iname instead of -name), any files ending in gif, jpg, or png.

We are then left with three files, each line of which contains the path, relative to the project root, of each resource I want to upload. I created a simple php script to upload the images, maintaining the pathing, to cachefly. So an image with relative path /images/header/header_left.png would now be accessible at instance.cachefly.com/images/header/header_left.png.

So the images are now up on the CDN. Now we need our code to point there as well. Fortunately, most of the resources were prepended with a domain (stored in the global $live_site). So the src attribute of an image, for instance, would be src=”< ?= $live_site ?>/images/header/header_left.png”. Creating a $cachefly_site global, we now only need to find lines in our code that have a basic layout of “stuff……$live_site…stuff…..png” where stuff is (.*) in regex land. So we utilize two commands, find and egrep. Find locates files we want and egrep searches the found files for a regex that would locate the resources in the code.

So first, we build the regex. We know a couple elements that need to be present, and one that should not be present. Needed are live_site and a resource extension (js/css/jpg/png/gif), and not needed is the “images/usergen” path, as this points to user generated content. So the regex becomes:

'live_site([^images/usergen])+.+(png|gif|jpg|css|js)'

This is the arg for egrep (the -l switch means print the file names that have a match, rather than the lines of a file that match):

egrep -lr 'live_site([^images/usergen])+.+(png|gif|jpg|css|js)'

Now we need to tell egrep what files to search using find:

find . -name "*.php" -exec egrep -lr 'live_site([^images/usergen])+.+(png|gif|jpg|css|js)' {} \;

We then store this list of files into a shell variable:

export FILES=`find . -name "*.php" -exec egrep -lr 'live_site([^images/usergen])+.+(png|gif|jpg|css|js)' {} \;`

Now that we have the files we need, we can search and replace $live_site with $cachefly_site for resources. The goto command for search and replace is sed. The sed command will look generically like this:

sed -i 's/search/replace/g' FILE

We actually have two issues though. Due to the nature of the code, we have to account for the $live_site variable being passed in via the global keyword. So not only are we searching for resource files, but we also have to add $cachefly_site to the global lines to make sure $cachefly_site is defined within the function where output is generated.

Searching and replacing resource files is pretty easy:

sed -i '/live_site.+\|js\|css\|gif\|png\|jpg/s/live_site/cachefly_site/g' $FILES

$FILES, of course, came from our find/egrep call earlier. There is one catch to the regex used here. It is actually of a different generic form than mentioned above:

sed -i '/contains/s/search/replace/g' FILE

With this format, we put a condition on whether to replace text, meaning the regex in the “contains” portion must be matched before the search and replace is performed on that line.
So our sed above says if the line contains live_site, followed by anything, ending in one of the listed resources (\| means OR), then replace live_site with cachefly_stite. I left of the $ since its common to both variables.

Running the sed command replaces everything nicely, but when we reload the page, we see notices about $live_site being undefined and resources being pulled from the host and not cachefly. So we need to handle the global importing.

This one is a little tricker because we are not really replacing live_site with cachefly_site, but appending it to the list of imported globals. So a line like

global $foo, $bar, $live_site, $baz;

becomes

global $foo, $bar, $live_site, $cachefly_site, $baz;

The other trick is that the global line should not already contain $cachefly_site. We don’t need that redundancy. So, without further ado, the sed:

sed -i '/global.*live_site.*\(cachefly_site\)\{0\}/s/live_site/live_site,\$cachefly_site/g' $FILES

The “contains” portion matches the keyword global, followed by stuff, followed by live_site followed by stuff, with cachefly_site appearing exactly 0 times (denoted by \{0\}). This ensures we only replace live_site when cachefly_site is not in the line already.
The “search” portion is easy; search for live_site. The replace portion replaces live_site with live_site,$cachefly_site. This takes into account when live_site is followed by a comma or semi-colon so we don’t get syntax errors.

And that is basically how I converted a site to use cachefly for static content.

Re-assert The Federal Government’s Role As An Agent Of the Several States

February 5th, 2009

A template for a resolution for you to send to your state legislature requiring the Federal Government to reign itself back into it’s Constitutional constraints and cease imposing its will on the States. Remember, the Federal Government is an agent of the States, not the other way around.

  • WHEREAS, the Tenth Amendment to the Constitution of the United States reads as follows: “The powers not delegated to the United States by the Constitution, nor prohibited by it to the States, are reserved to the States respectively, or to the people”; and
  • WHEREAS, the Tenth Amendment defines the total scope of federal power as being that specifically granted by the Constitution of the United States and no more; and
  • WHEREAS, the scope of power defined by the Tenth Amendment means that the federal government was created by the states specifically to be an agent of the states; and
  • WHEREAS, today, in 2009, the states are demonstrably treated as agents of the federal government; and
  • WHEREAS, many federal laws are directly in violation of the Tenth Amendment to the Constitution of the United States; and
  • WHEREAS, the Tenth Amendment assures that we, the people of the United States of America and each sovereign state in the Union of States, now have, and have always had, rights the federal government may not usurp; and
  • WHEREAS, Article IV, section 4, United States Constitution, says in part, “The United States shall guarantee to every State in this Union a Republican Form of Government”, and the Ninth Amendment states that “The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people”; and
  • WHEREAS, the United States Supreme Court has ruled in New York v. United States, 112 S. Ct. 2408 (1992), that Congress may not simply commandeer the legislative and regulatory processes of the states; and
  • WHEREAS, a number of proposals from previous administrations and some now pending from the present administration and from Congress may further violate the Constitution of the United States.

THEREFORE - Be it resolved by the House of Representatives of the State of <STATE>, the Senate concurring, that:

  1. That the State of <STATE> hereby claims sovereignty under the Tenth Amendment to the Constitution of the United States over all powers not otherwise enumerated and granted to the federal government by the Constitution of the United States.
  2. That this Resolution serves as notice and demand to the federal government, as our agent, to cease and desist, effective immediately, mandates that are beyond the scope of these constitutionally delegated powers.
  3. That all compulsory federal legislation that directs states to comply under threat of civil or criminal penalties or sanctions or requires states to pass legislation or lose federal funding be prohibited or repealed.
  4. That the Secretary of State of the State of <STATE> transmit copies of this resolution to the President of the United States, the President of the United States Senate, the Speaker of the United States House of Representatives, the Speaker of the House and the President of the Senate of each state’s legislature and each Member of Congress from the State of <STATE>.

Replace “State of <STATE>” with your state or commonwealth and send it away. Or create this as a petition, gather signatures, then present it to your legislators. Take back your state from the Federal bureaucrats.

The Argument For Guns

December 15th, 2008

I am not a gun-toting fellow by any means. Typically I have waffled between whether to ban some guns or leave them all available to private citizens. I know it is a slippery slope when talking bans and I don’t trust future legislators to not take advantage of a current legislator’s good intentions in limiting a subsection of firearms.

That said, I think it is always good to refresh your position with a well-articulated essay in support of your thoughts. And while I probably will not be toting any machine guns or bazookas, I think a handgun and some training might be time and money well spent. We’ll see. Until then, here’s the post that I feel articulates a good reason for the 2nd Amendment to be un-abridged by any gun laws:

The Gun is Civilization Maj. L. Caudill USMC (Ret)

Human beings only have two ways to deal with one another: reason and force. If you want me to do something for you, you have a choice of either convincing me via argument, or force me to do your bidding under threat of force. Every human interaction falls into one of those two categories, without exception. Reason or force, that’s it.

In a truly moral and civilized society, people exclusively interact through persuasion. Force has no place as a valid method of social interaction, and the only thing that removes force from the menu is the personal firearm, as paradoxical as it may sound to some.

When I carry a gun, you cannot deal with me by force. You have to use reason and try to persuade me, because I have a way to negate your threat or employment of force.

The gun is the only personal weapon that puts a 100-pound woman on equal footing with a 220-pound mugger, a 75-year old retiree on equal footing with a 19-year old gang banger, and a single guy on equal footing with a carload of drunk guys with baseball bats. The gun removes the disparity in physical strength, size, or numbers between a potential attacker and a defender.

There are plenty of people who consider the gun as the source of bad force equations. These are the people who think that we’d be more civilized if all guns were removed from society, because a firearm makes it easier for a [armed] mugger to do his job. That, of course, is only true if the mugger’s potential victims are mostly disarmed either by choice or by legislative fiat–it has no validity when most of a mugger’s potential marks are armed.

People who argue for the banning of arms ask for automatic rule by the young, the strong, and the many, and that’s the exact opposite of a civilized society. A mugger, even an armed one, can only make a successful living in a society where the state has granted him a force monopoly.

Then there’s the argument that the gun makes confrontations lethal that otherwise would only result in injury. This argument is fallacious in several ways. Without guns involved, confrontations are won by the physically superior party inflicting overwhelming injury on the loser.

People who think that fists, bats, sticks, or stones don’t constitute lethal force watch too much TV, where people take beatings and come out of it with a bloody lip at worst. The fact that the gun makes lethal force easier works solely in favor of the weaker defender, not the stronger attacker. If both are armed, the field is level.

The gun is the only weapon that’s as lethal in the hands of an octogenarian as it is in the hands of a weight lifter. It simply wouldn’t work as well as a force equalizer if it wasn’t both lethal and easily employable.

When I carry a gun, I don’t do so because I am looking for a fight, but because I’m looking to be left alone. The gun at my side means that I cannot be forced, only persuaded. I don’t carry it because I’m afraid, but because it enables me to be unafraid. It doesn’t limit the actions of those who would interact with me through reason, only the actions of those who would do so by force. It removes force from the equation…and that’s why carrying a gun is a civilized act.

Satire or Reality?

December 3rd, 2008

(Not mine, but can’t find original source either)

For Immediate Release

Washington, DC - President Barack Obama and the Democrat controlled Congress is considering sweeping legislation that will provide new benefits for many Americans. The Americans With No Abilities Act. AWNAA is being hailed as a major legislative goal by advocates of the millions of Americans who lack any real skills or ambition.

‘Roughly 50 percent of Americans do not possess the competence and drive necessary to carve out a meaningful role for themselves in society,’ said California Senator Barbara Boxer. ‘We can no longer stand by and allow People of Inability to be ridiculed and passed over. With this legislation, employers will no longer be able to grant special favors to a small group of workers, simply because they have some idea of what they are doing.’

In a Capitol Hill press conference, House Majority Leader Nancy Pelosi and Senate Majority Leader Harry Reid pointed to the success of the U.S. Postal Service, which has a long-standing policy of providing opportunity without regard to performance. Approximately 74 percent of postal employees lack any job skills, making this agency the single largest U.S employer of Persons of Inability.

Private-sector industries with good records of non-discrimination against the Inept include retail sales (72%), the airline industry (68%), and home improvement ‘warehouse’ stores (65%). At the state government level, the Department of Motor Vehicles also has an excellent record of hiring Persons of Inability (63%).

Under The Americans With No Abilities Act, more than 25 million ‘middle man’ positions will be created, with important-sounding titles but little real responsibility, thus providing an illusory sense of purpose and performance.

Mandatory non-performance-based raises and promotions will be given so as to guarantee upward mobility for even the most unremarkable employees. The legislation provides substantial tax breaks to corporations that promote a significant number of Persons of Inability into middle-management positions, and gives a tax credit to small and medium-sized businesses that agree to hire one clueless worker for every two talented hires.

Finally, the AWNAA contains tough new measures to make it more difficult to discriminate against the non-abled, banning, for example, discriminatory interview questions such as, ‘Do you have any skills or experience that relate to this job?’

‘As a Non-abled person, I can’t be expected to keep up with people who have something going for them,’ said Mary Lou Gertz, who lost her position as a lug-nut twister at the GM plant in Flint, Michigan, due to her inability to remember ‘rightey tightey, lefty loosey.’ ‘This new law should be real good for people like me,’ Gertz added. With the passage of this bill, Gertz and millions of other untalented citizens will finally see a light at the end of the tunnel.

Said Senator Dick Durbin (D-IL): ‘As a Senator with no abilities, I believe the same privileges that elected officials enjoy ought to be extended to every American with no abilities. It is our duty as lawmakers to provide each and every American citizen, regardless of his or her inadequacy, with some sort of space to take up in this great nation and a good salary for doing so.

Uncle-fied

October 31st, 2008

I’m proud to announce the newest addition to the Aimonetti family. Brosef Jeffrey and Steffi have a new son, Leon Jeffrey Michael! He was born this morning, weighed 8 lbs 8 oz, and was 21 inches in length. He, Mom, and Dad are all doing wonderful! Very exciting to have the first nephew aboard.

See the first pictures at my flickr page.

Education vs Schooling

October 31st, 2008

It is hard to question the value of public schools. The premise, a free education to enable children to lift themselves up and be productive members of society, is certainly hard to argue against. And yet, we see public schools failing, some quite miserably, to produce competent young adults. Solutions proposed, like “No Child Left Behind” are equally hard to argue against. How can a politician vote against such a proposition? And yet we have seen a good deal of backlash from teachers and administrators as to the decrease in quality learning that students have received.

Despite all the “work” put into public education, public schools are not producing the intellectual citizens hoped for and desired. So we need to question deeper. I was given an article today that takes a deeper look at public education and provides some refreshing insight. The author, John Taylor Gatto, questions the premises of public education and finds that, not only are they ineffective, but designed to be so.

Read with an open mind and see if the content jives with you. At the very least, we need to examine so many of the governmental institutions put in place in the last century that we take as necessary, and public education is certainly one of those institutions that will generally be disregarded in that discussion. The Federal Reserve, the IRS, Homeland Security, and more are easier targets because they have a negative impact on our society. Public education is generally perceived as a net positive for society, and thus tends to be exempt from discussion on its needed existence.

Obama’s Wealth Redistribution In Action!

October 27th, 2008

From a mailing list:

Today on my way to lunch, I passed a homeless guy with a sign that read, Vote Obama; I need the money.” I laughed.

Once in the restaurant, I noticed my server had on an “Obama 08″ tie. Again I laughed as he had given away his political preference — just imagine the coincidence!

When the bill came, I decided not to tip the server and explained to him that I was exploring the Obama redistribution of wealth concept.

He stood there in disbelief while I told him that I was going to redistribute his tip to someone whom I deemed more in need — the homeless guy outside.

The server angrily stormed from my sight.

I went outside, gave the homeless guy $10 and told him to thank the server inside, who, I decided, did not need the money as much as the homeless guy. The homeless guy was most grateful!

At the end of my rather unscientific redistribution experiment, I realized the homeless guy was very grateful for the money although he did not earn it. And the waiter was pretty angry that I gave away the money he did earn, even though the actual recipient deserved the money more.

I guess redistribution of wealth is an easier thing to swallow in concept than in practical application. Or is it? Redistribution of someone else’s wealth is a great idea — or just a fool’s game?

It seems like there should be a market for all those Obama supporters to bind together into a group fund that then they can redistribute their wealth by choice, and not force others that don’t agree with the method of redistribution. Oh wait, there are…they’re called charities and non-profits. No need for the government there! If only…

Important Ideas

October 20th, 2008
  • You cannot help the poor, by destroying the rich.
  • You cannot strengthen the weak, by weakening the strong.
  • You cannot bring about prosperity, by discouraging thrift.
  • You cannot lift the wage earner up, by pulling the wage payer down.
  • You cannot further the brotherhood of man, by inciting class hatred.
  • You cannot build character and courage, by taking away people’s initiative and independence.
  • You cannot help people permanently, by doing for them what they could and should, do for themselves.

To whom are these attributed to? None other than Abraham Lincoln. Sad that after all these years, our politicians haven’t learned these lessons, and our citizenry hasn’t elected politicians that do get it.

Get rid of the Fed

October 3rd, 2008

Regarding the VP “Debate”: Overall, Palin didn’t suck. Biden was good. Neither was very impressive. I would have liked to have seen a third party VP candidate up there to actually talk substance.

That said, why will no one acknowledge that the Federal Reserve is directly responsible for the financial meltdown?

The monetary supply was increased by the Federal Reserve and loaned that increase to firms on Wall Street at low interest rates. There was no call from the market for an increase, there was no market influence on the interest rate. Other than Ben Bernanke, can anyone name someone else on the Federal Reserve board? Can anyone remember voting for Bernanke to replace Greenspan? So, we have a board with no tangible oversight determining the monetary supply and interest rates.

With all this cheap money to be had, and with the nature of Wall Street to make money, it is only natural (good or bad is subjective) for the financial industry to take the money and do something with it. The cliche “kid in a candy store” is so fitting because we are seeing the tummy ache of too much candy. Do you blame the kid for getting the tummy ache? Sure, there has to be personal responsibility. The kid has to learn a lesson. But what about the parent who let the kid run wild in the store? If you gave a kid $500 and let them loose, don’t you think they’d most likely buy candy and not something more nutritious?

So the Wall Street folks took the artificially low-interest money and went nuts. How did the kid get the $500? It was given to him for essentially free. Now, what if the kid had had to work hard to earn $20, perhaps by mowing the lawn or some other chore. Wouldn’t they be more likely to purchase something of value instead of some candy? The same with Wall Street. Given sound money, investments would be more prudent, and investors would not be buying debt-backed investments at such ravenous rates.

The Federal Reserve is ultimately to blame for the mal-investments. By corrupting the free market with cheap money, investors binged on candy and now have a tummy ache. The bailout will be another handout, and another tummy ache (or worse) later down the road. Sure, those investors that lost their scruples will need to pay, to be hurt by the collapse. In that way, the market becomes stronger. If the Federal Reserve continues to inflate the money supply, we will see more bubbles (remember, this “housing” bubble was preceded by the tech bubble, which also was fed by artificially low interest rates).

Let’s take a look at some other numbers.

The 2008 fiscal year ended Sept 30th. On that day, the Federal Debt was $10,024,724,896,912.49. $10 trillion dollars. In 1913, when the Federal Reserve was spawned into being, the Federal Debt was $2.916 billion. Almost a 3,500 times increase.

The national debt grew by $1,017.1 billion this year (2008), the first time the debt has grown by over $1 trillion dollars. The rancid cherry is that since Sept. 15th of this year, the debt increased $390.6 billion. In 15 days! 40% of the year’s debt in 15 days? Sounds like Sec. Paulson and Bernanke have assured the next few generations an uphill battle to solvency.

The $700 billion bailout will not stem the tide. It will not turn the ship. It will do nothing but exacerbate the problem. The silver lining, so far, is that the citizens of this country pressured the House enough to get a ‘No’ vote on the initial bailout bill. The Senate has passed a turd of a bill that includes the $700 billion bailout, as well as over $150 billion in tax breaks. So they want to take $700 billion and remove another $150 billion from the tax revenue. Doesn’t that seem odd? Anyway, if Americans are ever to take their country back, a doubling, tripling, even a quadrupling of efforts is needed to ensure the bill does not pass the House.

Now, there are those Congressmen that know the bailout is bad news for the taxpayer, but they can’t get help but feel like they need to do something. Here’s how you can help them do something. When you call, fax, and email them, everyday, you can mention that they should support three bills: HR 2755 (Federal Reserve Board Abolition Act), HR 2756 (Honest Money Act), and HR 4683 (Free Competition in Currency Act). These three bills will help the economy recover in a more timely manner and with more lasting changes that will discourage this scenario from playing out again.

To those Congressmen that voted ‘yes’ on the initial bailout, they must reverse their votes or else be run out of town. To those that voted ‘no’ initially, encourage them, thank them, and require them to stay true to that ‘no’ vote.

Happy (belated) Constitution Day

September 18th, 2008

From an email received today:

24 Constitutional Questions Every American Should be Able to Answer

Adapted from “A Quiz About the U.S. Constitution”
By John F. McManus, writer and narrator of “Overview of America”

  1. Has the Constitution always guided the country?
  2. Does the Constitution allow the Supreme Court to make law?
  3. Does the Constitution allow the President to make law?
  4. Does the Constitution give the federal government any power in the field of education?
  5. Where in the Constitution is there authorization for foreign aid?
  6. What are the three branches of government named in the Constitution?
  7. Does the Constitution require a minimum age requirement for a Senator?
  8. What are the Constitutional requirements for a person to be President?
  9. Did the Constitution give the federal government power to create a bank?
  10. Can treaty law supersede the Constitution?
  11. Does the Constitution allow a President alone to take the nation to war?
  12. Are there any specific crimes mentioned in the Constitution?
  13. Are the Bill of Rights considered part of the original Constitution?
  14. According to the Constitution, how can a President and other national officials be removed from office?
  15. What authority does the Constitution give the Vice President?
  16. How many amendments to the Constitution are there?
  17. Does the Constitution say anything about illegal immigration?
  18. Does the Constitution tell us how new states are added to the union?
  19. How is an amendment to the Constitution added?
  20. Is the term of a President limited by the Constitution?
  21. Which part of Congress is designated by the Constitution as having the “power of the purse?”
  22. How does the Constitution explain expelling an elected member of the House or Senate?
  23. What does the Constitution say about financing a military arm?
  24. How many times is the word democracy mentioned in the Constitution?

Also, why the economy is tanking, why it is the Federal Reserve’s fault, and why aren’t the two major party candidates talking about it? The Fed and the Recession