PHP debugging addendum

In case anybody out there is actually getting PHP tips from me (hint: that’s not a good idea) I should point out that you should be using Xdebug.

My last tip works plenty-fine with it, but additionally it gives you pretty-printed backtraces in the browser. Sort of like Django’s error screen, but not nearly as nice.

Don’t be like me. Don’t spend two years manually emitting backtraces to the system log. In Ubuntu (11.10, at least) getting Xdebug is as simple as:

sudo apt-get install php5-xdebug
sudo service apache2 restart

I’m sure your distro’s package manager is as simple as mine.

PHP: Display errors, but also hide them

I develop php with the correct php.ini settings:

error_reporting = E_ALL | E_STRICT
display_errors = On
log_errors = On

But, this has the problem of occasionally showing me errors that I care about, but not right now.

Which is unacceptable. Hence, my new error_{prepend,append}_string:

error_prepend_string = "<pre style="color: #ff0000; cursor: pointer;" ondblclick="\"'none';\">"
error_append_string = "&lt;/pre>"

(Substitute ‘<’ for ‘&lt;’. Sorry: WordPress is silly.)

Now I can doubleclick on errors to dismiss them. I like it.

I’m a columnist

I totally wrote for my school paper.

If you were wondering what kind of resources the Internet has for students, well, boy, you should check this out.

My extremely specific DNS settings

As previously mentioned, I recently got a Dreamplug which I am using as a media server. Hopefully.

One of my requirements for something as general purpose as a media server is that I be able to tell people “feel free to play some of my music, just go to carsonella.home and look around.” (My smallest computer is called carsonella, get it?) I specifically don’t want to have to tell people “Go to… oh wait let me check what IP carsonella is on… [3 minutes later] No, that’s a web address, just put it in your browser. Yeah, Firefox is actually a web browser.” And etc.

So: I want names. Mapped to IPs. I’m used to doing this for my (linux) computer with /etc/hosts, so I thought I would be able to do this for my local network via some magic setting in my router, but it turns out I just want my own DNS server. Also I’m not an IT professional, who knew?

I’ve got a D-Link DIR-655 (HW version B1, firmware 2.00NA) router and a Dreamplug Running Debian Squeeze. And no JTAG adapter, so I really don’t want to mess anything up.

This should work for any Debian/D-Link setup, but caveat emptor.

It turns out that there are only a couple of things that need to happen to make this work, but they’re independent of each other so I couldn’t find any tutorials that collect it all in one place. Basically:

  1. install dnsmasq on the plug
  2. configure dnsmasq on the same
  3. configure my D-Link to use the plug as the DNS server
  4. and, separately, tell it not to use the ISP’s DNS settings.

That last point really bit me.

1) Installing dnsmasq is as easy as install anything on debian:

apt-get update
apt-get install dnsmasq

2) Configuring it involves editing a couple of files: I set my /etc/resolve.conf to look like:

domain .home
search home

I think that the first two lines tell this computer that it’s responsible for handling everything that ends with a .home pseudo-TLD. Honestly this is just cargo-cult server setup and I would appreciate any comments or corrections, and don’t take my word for this.

I know it’s appealing to make computers on your network have no dots in them, but all kinds of services (e.g. Firefox, and apparently most of Windows) will assume that you messed up your url if you didn’t put in at least one dot and will try to “fix” it for you.

The third line is essential: it tells the plug that it is its own nameserver, and to check itself before it checks anything else for a real name. It also, apparently, sets up local caching– hopefully this will improve DNS lookup times for common sites by a few ms. (I’ve noticed mine go from 18-20ms down to 2, when I’m plugged into my ethernet.)

The last two lines configure it to use opendns, a great (better than your ISP’s) DNS service. A problem with it, though, is that by default if you try to visit a nonexistent domain it will show you an OpenDNS “search” page filled with ads. You can follow these instructions to get proper 404 behavior. If that’s too much work you can use Google’s public DNS, which does the right thing by default, but then Google will know Even More about you.


I then modified /etc/hosts to look like: localhost carsonella.home

I am reasonably certain that the .home part of carsonella.home there must match what is set as the domain in resolv.conf

3) Configuring the D-Link to use the plug as the DNS server isn’t terrible, if you know where to look.

The first thing that I needed to do was to get my dreamplug to have a static IP. Since I didn’t want to mess with network settings on the plug (no JTAG means no debugging if things go to hell) I just used the D-Link’s “reserve IP” functionality.

You find the reserve IP settings at the bottom of the “Setup ? Network Settings” page in the D-Link admin. One bug there was that I needed to click “Save Settings” at the top for the settings to take effect, even though they looked saved and the DIR-655 told me that there was “nothing new to save.”

Choose some IP to reserve for the dreamplug, for example

To tell the D-Link that it needs to use your plug for DNS you need to go to “Setup ? Internet” and click on the “Manual Internet Connection Setup” button.

Here you need to fill in the IP you chose for your plug as the Primary DNS Address. I also recommend putting in one of the IPs you used as a nameserver as the secondary DNS addres in case your computer goes down.

Save these settings.

Almost done!

4) Go back to “Setup ? Network Settings” and make sure Enable DNS Relay is unchecked. Without this your router will ignore all of your settings and just assign your local computers DNS settings as provided by your ISP.

Save these settings. (I’m pretty sure you don’t want to do this before you’ve configured a new nameserver, because changing settings on the D-Link has some random chance of renewing your DHCP lease, and if you do that without a DNS server you won’t be able to find any damned thing.)

You’re done!

Or at least I am, this was supposed to be a quick reminder in case I ever needed to do this again.

Using getopts with required args in a posix shell

I recently wanted to add a verbose flag to a script. My script required some arguments, and I didn’t want to change the (very limited) already existing logic. Because programming in bash sucks enough that I am willing to spend 6 hours googling “getopts options with args” rather than re-arrange 3 lines of code.

This seems like such a common need that I figured it would be easily googlable, but based on the number of unanswered forum posts that I found, it isn’t.

It turns out that the advanced bash scripting guide does talk about this! Casually, and without any kind of callout. On page 203. As part of the discussion of internal commands.

It turns out that what I wanted was to use the standard getopts loop, followed by a call to shift:

while getopts "k:vh" o ; do # set $o to the next passed option
  case "$o" in
    v) # set "v" flag
    k) # do something with "k" and $OPTARG, the arg to this opt
    h) print "$usage"
shift $(($OPTIND - 1))
# $1 is now the first non-option argument, $2 the second, etc

You see, getopts sets the $OPTIND POSIX variable to the index of the option that it should process next every time it’s called, and shift arg shifts arg arguments off the argument list.

Combining those two facts, and using the $(( )) numeric context, lets you set a bunch of options and then act as though your script has only arguments in any POSIX-compliant shell.

I think. This is working for me in bash and zsh, and it’s part of the POSIX standard, so it should be true for you.

Technorati Tags: , ,

Apt-cache search errors on Debian (in a dreamplug)

I just got a Dreamplug and have been playing around with it, when for some reason apt-cache search started failing weirdly. Sometimes I got segmentation faults, sometimes it would just run with no output, taking up to a few minutes.

My apt version is, so a couple of old Debian bugs that recommended rm /var/cache/apt/*.bin (which has since the taken to filesystem name randomization since the time of the bug, so I actually needed to rm /var/cache/apt/*.bin*) seemed like it probably wouldn’t work. And indeed it didn’t.

There was also this guy’s “delete everything and let apt cache it out” solution, which also didn’t work.

Then I tried man apt-cache which almost immediately told me about apt-cache gencaches:

gencaches performs the same operation as apt-get check. It builds the source and package caches from the sources in sources.list(5) and from /var/lib/dpkg/status.

apt-get check fixed it. Possibly it wouldn’t have if I hadn’t deleted practically everything  apt ever created, though, so I told you about my journey.

And, yes, I rm -rf‘d entire file structures almost blindly. Don’t do that.

Technorati Tags: ,

I’m sick of crazy people lying about “secular thought” in major newspapers

Why have people got to go around continuously misstating and, well, lying about the implications and demands of a secular worldview? For example, take this sentence:

Once the world is … thought of as being “composed of atomic particles randomly colliding and . . . sometimes evolving into more and more complicated systems and entities including ourselves”

OK, completely aside from calling some of the most elegant and impressive discoveries of humankind (friggin’ fundamental laws of physics and evolution, ladies and gentlemen) “particles randomly colliding and sometimes evolving into complicated shit,” (The Disenchantment of Secular Discourse, Stephen “I Hate and Fear History” Smith) this description of secular thought ignores hundreds of years of secular thought. Which, don’t worry, Stanly Fish will continue to misrepresent and misunderstand for a good 1776 words, in the end arguing that there are no non-spiritual reasons for doing anything. And, no, I did not make that number up.

This fundamental misunderstanding of what “secular” means is important because the article is all ab out how we make public decisions: what appeals is it legitimate for a member of government to make? Fish starts off by saying that “policy decisions should be made on the basis of secular reasons,” which — given a minimally good definition of “secular” — I agree with. Policy decisions should be made based on the effects they will have on the world, not on of many imaginary deities. Unfortunately I edited that to make him look like less of an idiot, this is is a more complete version: “policy decisions should be made on the basis of secular reasons, reasons that, … do not reflect the commitments or agendas of any religion, morality or ideology“. (emphasis mine)

Allow me to provide you with a selection of the most popular ethical systems around today, the systems that most inform current American morality according to my incompetent analysis:

  • Utilitarian Ethics (do what makes the most people the most happy)
  • Respect Ethics (do unto others as though they deserve the best you can reasonably do. This is a mild reformulation of the golden rule, and based on the fact that you have probably never given a homeless person your credit card, the version of it that you actually follow. Usually called duty ethics.)
  • Fulfillment Ethics (do things because they will help you or others be the best people that you/they can be. Usually called Virtue ethics, because that’s what they called things back when Aristotle was writing.)

Know what those fundamental systems of morality all have in common? They are secular. Which is to say they do not depend on unjustified assumptions that threaten you with eternal torture for their basis. Oh, wait, that reminds me, I forgot one:

  • Ignoring all of the effects of my system, because I don’t care about how people live. (Usually called religion.)

That one does depend on unjustified assumptions about the fundamental nature of reality, assumptions which (often) conveniently involve your horrible pain for a literally meaningless amount of time.

Quickly take a look at those four systems, tell me if I have misunderstood any of them, recognize which ones you actually use to make decisions. And then think about how you don’t actually need to incorporate anything non-secular to reach those same decisions. Every worthwhile moral theory is secular. Seriously Stan, don’t be a jerk.

Oh no here he goes again:

While secular discourse, in the form of statistical analyses, controlled experiments and rational decision-trees, can yield banks of data that can then be subdivided and refined in more ways than we can count, it cannot tell us what that data means or what to do with it. No matter how much information you pile up and how sophisticated are the analytical operations you perform, you will never get one millimeter closer to the moment when you can move from the piled-up information to some lesson or imperative it points to; for it doesn’t point anywhere; it just sits there, inert and empty.

If he was going to be so technical about it I’d think he’d want to bound us a little tighter and say “nanometer” at least. He is so insanely incorrect I can think of about 7 things before I type the number “7″ to use to argue against him. Let me lay out for you a simple example of secular reasoning that I don’t care if anyone disagrees with, because they suck:

  1. Getting raped sucks big time.
  2. We should prevent people from raping other people.

OK? Stan and Steve, would you say that I have stayed within the bounds of the “truncated discursive resources available within the downsized domain of ‘public reason’”? And, if I haven’t, could you please explain you me why (2) requires me to appeal to some fundamental teleological aspect of the universe instead of just pointing out that we should keep things that suck from happening, if we can help it?

Oh, wait, you never address that.

Here’s some more gibberish, loosely related!

If [secular] reason has “deprived” the natural world of “its normative dimension” by conceiving of it as free-standing and tethered to nothing higher than or prior to itself, how, Smith asks, “could one squeeze moral values or judgments about justice . . . out of brute empirical facts?”

Well, because one of the empirical facts is getting raped sucks. That is a fairly well-acknowledged and -documented fact. There are a variety of other observations of the human condition that count as facts that allow us to make a wide variety of other well-formed and non-arbitrary arguments about how to behave.

No way that is not a sleight of hand.

Sweet. I expect my invitation to perform at the Magic Castle by the end of the week.

This is the cul de sac Enlightenment philosophy traps itself in when it renounces metaphysical foundations in favor of the “pure” investigation of “observable facts.” It must somehow bootstrap or engineer itself back up to meaning and the possibility of justified judgment, but it has deliberately jettisoned the resources that would enable it do so.

I wasn’t going to include that, but I really love the use of scare quotes around “observable facts.” And I felt like it was only fair to make him look like even more of an idiot, because the article really pissed me off.

He goes on for awhile with some other minor misunderstandings and lies about the definition of “secular,” as well as some truly interesting problems — what does freedom mean? to whom do we owe what? — unfortunately the only case that he makes against secular thought is that it seems to be incapable of observing humanity. Which is, you know, false.

Technorati Tags: , , , ,


hi there. my name is brandon. I come to write to you a memorabilia. A short memory, that is to say. Something fun for everyone, the whole family.

I was walking through the park one day, and I stumbled. Fell down, didn’t see the path, tripped, choked my way into blackness.

As it were.

This, being a short memory, you’ll forgive me if i don’t elaborate. It is like swimming in cold water: you’re pretty sure you should be panicked, or at least your body thinks it should be. Freezing water, the kind you can see ice float past. When you swim: you can see ice float when you swim. It’s a bad idea to dwell in it. Cramps, nausea, a violent retribution; people say stay away with good reason. But there are places to swim, people to see. Or avoid. These things are here for a reason, don’t let them tell you they’re not. There are good reasons for saying that they’re not, but, that’s not the reason to let them not tell you that they’re not. Just keep swimming, is the thing.

Your body can only panic for so long, is the thing. Keep this in mind: panic is useful, it keeps you swimming. Without a continuous flow of adrenaline you would give up. That, as you can imagine, is fatal when walking through a park. Do not give up; walk through the darkness and the bracken. There is only so far that you can walk in the middle of a city before you meet someone of like mind, similar vocation, maybe a hint of hypothermia.

It’s the blue lips that you should look for.

What, no plot? Plot assumes a point: a place to go, something teleological. Law and the word — the end word — the word transported. Useless like pink lips.

New mathematical model shows stupid is highly contagious

Or: Homeopathy is famous because it doesn’t work. The article is interesting, and the gist of it is:

  • people do things they see other people doing
  • people spend more time on medicines that don’t work than medicines that do
  • medicines that don’t work have more time to convince people to try them

Now, completely aside from how horribly depressing that is — and how interesting it is that somebody used the mathematical models used to understand the spread of disease to the spread of crazy — it clarifies and provides a metaphor for a thought that I’ve sort of had knocking around the back of my head for awhile now.

Worldviews (Weltanschauung?  nah.) seem to spread in similar ways to crackpot ideas; I mean, you understand the world in ways that come from the people you interact with. The more strongly that people express a worldview the stronger the effect it has on you. Not necessarily positively, of course. But who is going to believe the most passionately about their WV? People who really need something to believe in. And, of course, if your philosophy is just really fundamentally not working out for you — as, for example, it wouldn’t if you just expect everything to work out because somebody somewhere loves you / hates your coworkers — then you are going to need a philosophy all the more. And especially if it doesn’t lead obviously to gratuitous horrors you are more likely to tell your friends and coworkers (whom your deity/world energy/doctor doesn’t like) that it is the thing that makes the world OK.

So, point is, think carefully when you tell people that ______ is always there for you/around you/touching you with his noodly appendage, because sometimes even an imaginary touch is inappropriate.

Technorati Tags: , , ,

Starry McFlamingpantserson, and other remnants.

Well, an hour ago I didn’t know what a snowclone was, but then this guy but now I’m going to share some links with you. I’m going to share some links with you so hard.

Actually, all links to the ADS-L, because this one thread beat my hours of research, or it was the end of it (why are the keys always in the last place I look?) [also, because their icons are meaningless and have no alt-text, the lightbulb with the right arrow seems to mean "next in thread"]

OK, first, if you consider “‘McLintock!’ is McNificent!” to be the origin, than this dates back to 1948. I don’t.

Then there’s “Marian McPartland’s Mcmagic”. (1956) That’s better, but still kind of lousy.

There’s a, an, ah, myspace forum dedicated to what people have started “Mc-y-ing”, in honor of greys anatomy. It’s not Xy McYerson, though it is horrible. And it’s from 2007, so by this point we know it’s from between 1956 and 2007.

ah! :

So far I haven’t been able to find anything
earlier than Nov. 1, 2001 — the first appearance of Hottie
McHotterson (on (hmmm)

OK, even better:

These may have been inspired by Bill Maher, who took to calling Bush
“Drinky McDumbass” as early as 2000 (when his show “Politically
Incorrect” was still on the air).

–Ben Zimmer

That seems about right for the recent surge in them, although I also remember saying it in highschool. Wait, highschool, that means…

Tipsy McStagger from “Flaming Moe’s” (Season 3,
aired Nov 21, 1991). In the episode, a representative from Tipsy
McStagger’s Good Time Drinking and Eating Emporium tries to get the
recipe for the “Flaming Moe” drink from Moe the bartender.

the simpsons. Of course.

Technorati Tags: , ,