These are my notes from O’Reilly’s Website Optimization. It is a strange book, that will appeal to the one-renaissance-person web business: someone who optimizes Javascript for performance and tracks Google Ads conversion goals. You’re bound to find a useful chapter in here, but I doubt you will find more than one relevant to you. Here are my notes:
Monit tells you if something goes wrong on your server, and tries to fix it. It can, for example, alert you:
When a process dies.
When a machine stops responding to network requests
When your machine has too high load average, memory consumption, or CPU usage.
When a file changes, hasn’t changed for a period of time, or grows beyond a certain size.
It can run a script of your choosing to attempt to fix the problem. It has an HTTP interface that shows you essential stats about the services you are monitoring. For detailed graphs, I recommend Munin.
Here are my notes from setting it up, they are brief, but should help you get going.
All the monitored machines run a small daemon called munin-node. One machine is the central server. Every few minutes it gathers data from all the nodes (including itself), generates the graphs, and writes out some HTML files.
If your MySQL (5.0+) replication is broken, there’s two ways to fix it: The easy way, and the right way.
Run commands starting with $ on Unix. Run commands starting with mysql> in the MySQL client.
The easy way: Skip the problem
If you hit both databases at the same time, with the same INSERT, they will create their own record, and try and replicate to the other, which already has that record, causing a duplicate error.
In a simple case like that, you just want to skip the offending statement:
Most of the time, you skip one statement, and replication breaks again straight away, because there’s a whole queue of problem statements coming up.
The right way: Rebuild
If you are not sure that you can skip the duplicate, or if replication has been broken long enough that your two servers are out of synch, pick one database to be the master, and rebuild the other from a copy of that master.
In the general case, there is no way to list all the keys that a memcached instance is storing. You can, however, list something like the first 1Meg of keys, which is usually enough during development. Here’s how:
More and more, my web apps need to run things in the background: Sending email, re-calculating values, fetching website thumbnails, etc. In short, I need a message queue in my toolbox.
I setup my Mercurial repository in the same way we used to do CVS, then SVN: A directory owned by a group, with the GUID bit, and all users who need to commit are in that group.
The steps are, create the group and add relevant users to it:
:noclick
sudo groupadd topsecretgroup
sudo usermod -a -G topsecretgroup graham
I will be speaking at Open Web Vancouver on Thursday, June 11, 2009 and Friday, June 12, 2009.
That’s in Vancouver, B.C., Canada. There’s a very interesting speaker lineup, and the whole conference is reasonably priced, so come along, learn, interact, and enjoy Vancouver in the summertime.
My talk will be entitled How and Why to Extend Firefox in Javascript (and Thunderbird, Komodo, and Songbird). I will post the slides here in June.
When I was 16, I wrote a computer game, called Micro Zooides. It was called that partly because on Windows .EXE files all start with the two characters MZ, and partly because it was about small creatures. Micro-Zooides was going to be about humanity’s progress, it was going to be Civilization, which didn’t exist yet.
The game had a splash screen of a Far Side comic, then a short video of me tromping through the woods like a Neanderthal, which my Dad filmed and which I digitized with a very early video capture card.
In Borland’s Turbo C++ 3.0 I wrote a basic graphics engine to display the tiles of the world, and an event loop so I could move the main character around the world. I drew sprites for a proto-human (the micro zooid), dirt, rocks and sticks. He could walk around the world, and pick up and put down rocks or sticks.
Then I took a break to plan. I have a proto-human, rocks, and sticks. How do I get to civilization?
After a desktop and server upgrade, my subversion client stopped working. I am using Digest authentication, and it kept asking me for the username and password. Wireshark showed me that the SVN client wasn’t sending the Authentication header. To find out more, I turned on Subversion’s debug output. Here’s how you do it:
Edit /etc/subversion/servers
Add this line at the end: neon-debug-mask = 511
That showed me this error: auth: '/' is inside auth domain: 0.
This means that the path I was requesting (the root of the repo) was not considered inside the AuthDigestDomain I had set in Apache.
It turns out that at some point in the upgrade of Apache, Subversion, or a library, the AuthDigestDomain requires a scheme. I had AuthDigestDomain svn.myserver.com
whereas it should of been AuthDigestDomain http://svn.gkgk.org.
Foxden is a Firefox extension that allows you to tile all the web applications you use on one page. Imagine being able to see your email, your calendar, your bug tracker, feeds, twitter, whatever you use, on one page. Take a look at my setup:
As you can see, I have (counter clockwise from top left) my email, calendar, feed reader, todo list and a local text file for taking notes.
It’s free, should work wherever Firefox 3 works, and it could be yours right now.
Most ActionScript / Flash applications have a main event loop, triggered by Event.ENTER_FRAME. This is where the animation moves along to the next frame, or the sprites of the game are re-drawn in their new places.
In the Flex framework, you are expected to call invalidateDisplayList on the framework to say you need an update, and actually do the update when the framework calls your updateDisplayList method. This is the invalidation / validation pattern.
I went searching in the Flex code to understand how this invalidation / validation step ties in with Flash’s event model. I ignored properties and sizing, and edited the code down to the bare essentials.
Here is what happens when you change the label of a button:
UPDATE March 19th: Added First Steps in Flex, and Learning Flex 3.
You’re an experienced server-side programmer, with a background in C/C++/Java/C# or Python, but no Flash experience. You want to learn Flex. Which book should you buy to learn Flex 3?
I have speed-read the following, so that you don’t have to:
Los Angeles is under attack, by trigonometric functions! OMG! Trigo-what? If I wanted to do maths, I’d go to San Francisco!! You, like, totally gotta save L.A man. Enter your name, then move your tank.
Use the left and right arrow keys to rotate, the forward and back arrow keys to move. The barrel of the tank is the little black line. That’s the front.
No, your tank can’t fire. Avoid the mathematical blobs. YEAH!
The longer you live, the more points you get. A score above 100 is, like, totally AWESOME! Good luck Bro.
Let me know in the comments how much you score.
When writing object-oriented Javascript, there are two occasions when you need to be careful that this is set correctly: In inner functions and in callbacks.
this in inner functions
If you are not in an object, this refers to the global window object.
If you are in an object’s method, this refers to that object,
except in an inner function, when this refers to the global window object again.
Number 3 is what you need to watch for. It is considered a bug in Javascript. Here is an illustration of the three cases:
Javascript is not an opinionated language. At it’s heart it is a hash map. You can layer pretty much any idiom you want on top of it. I’d like to make it look like Python, and it’s pretty easy to do. They both are dynamically typed, have functions as first class objects, and can treat most types as hash maps.
Let’s assume code for a whimsical Moose Observation Project, and translate it from Python to Javascript.