Next 30 day challenge: social media/news cleanse

For January 2015, I tried to declutter around the house for 15 minutes a day. We now have a couple rooms that are much cleaner, and I gave away a bunch of magazines.

For February 2015, my 30 day challenge was to go on daily 15 minute walks with my wife. That was nice.

Lately I’ve been spending more time than I’d like on social media and reading news sites. So for March 2015, I’m going to do a social media and news cleanse. I’ve done a social media cleanse several times before and it’s usually quite helpful for getting re-centered.

Here’s the steps that I’m taking:
– I’m using the StayFocusd Chrome extension to limit myself to 15 minutes a day of Google News, Twitter, Google+, Hacker News, Techmeme, Nuzzel, Reddit, and Imgur.
– On my R7000 home router I’m using the “block site” functionality for several of these sites. It looks like the R7000 can block HTTP sites, but not HTTPS.
– On my phone, I’m removing the new tab thumbnails for these sites. I’m also removing some social media apps from my home screen.

I figure that either I’ll get some good stuff done, read a lot of books, or die of boredom. I may (rarely) drop a link on social media, but if you see me just hanging out, please remind me to close my tab and move on. 🙂

Fixing “full path disclosure” issues

Whether you’re running a web service or a blog, you should always keep your software fully patched to prevent attacks and minimize your attack surface. Another smart step is to prevent full path disclosures. For example, if your blog or service throws an error like

“Warning: require(ABSPATHwp-includes/load.php) [function.require]: failed to open stream: No such file or directory in /home/horace/public_html/wp-settings.php on line 21”

then by noting the full pathname from that error, an attacker could reasonably infer that your username is “horace” and use that try to guess your password. It’s not the end of the world if your attacker has that information, but why not make an attack as hard as possible?

For WordPress, here’s a couple ways to prevent full path disclosure vulnerabilities:
– In a php.ini file, you can add a line like “display_errors = off” (without the quotes).
– In an .htaccess file, you can add a line that says “php_flag display_errors off” (without the quotes).

It sounds like the php.ini approach might be slightly better, because some web hosts run PHP in CGI mode which might not allow php_flag or php_value directives in .htaccess files.

After you’ve made this change, php errors shouldn’t be shown to web clients. If you’re developing live code on a PHP installation, that can make debugging slightly less easy. But if you’re running (say) a blog, it’s probably better to turn off display errors for a little extra protection against attacking hackers.

Lessons learned from the early days of Google

Earlier this month I did a talk at the University of North Carolina at Chapel Hill about lessons learned from the early days of Google. The video is now online and watchable, or you can watch it on YouTube:

We did the talk in a pretty large room, and the camera at the back of the room couldn’t easily record me and the slides at the same time. So here are the slides to go along with the talk:

Or you can view the slides at this link.

I believe all the pictures should be covered either by license or fair use (the talk was free), but let me know if you see anything that you believe is problematic. I hope you enjoy the talk!

My two favorite books of 2014

I’d like to mention two books that stood out for me in 2014:

Nonfiction: The First 20 Minutes. Gretchen Reynolds is a New York Times columnist who distills health and exercise research down to practical, readable advice. I’ve never dog-eared as many pages in a book as The First 20 Minutes. Reynolds writes about why you might want to brush your teeth standing on one foot, work out before eating breakfast, and how pickle juice might help with cramps. Should you get a cortisone shot? Does it help to believe in luck? Does long-distance running make your knees less healthy? Is chocolate milk a good recovery drink? Read the book and find out.

Whether you’re a couch potato or a ultramarathoner, you’ll probably learn something interesting and helpful from Reynolds’ book. Reynolds also writes with the easy readability of a seasoned newspaper columnist, and each chapter ends with bite-sized summaries of what the current scientific research recommends. My only nitpick is that I wish Reynolds had included footnotes pointing to the original research for people who want to dig deeper.

Fiction: As I’ve written before, The Martian describes an astronaut stranded on Mars who needs to figure out how to survive and get home with minimal supplies. Some of the science gets detailed, but the book builds to a very successful ending in my opinion.

What was the single best fiction or nonfiction book you read in 2014?

Fun mosaic effect with Go

A few months ago I saw a cool mosaic effect in a Wired ad for CA Technologies. Here’s what part of the ad looked like:

Photomosaic of people in an office

I liked the ad, so I wondered how they did it. Can you see out how to create a similar effect? Take a minute to figure it out as an exercise.

Here’s what I came up with: divide the image into tiles. For each tile, compute an average overall color for that tile. Then go back and blend every pixel in that tile with the average color. So if a tile is partly dark and partly blue, the average color is a dark blue, so the blue in that tile becomes even darker. I like that the effect is pretty simple once you figure out how to do it.

Of course, once I had an idea of how to do it, I wanted to write some code and see whether I could recreate the effect. Go has good libraries for handling images and I’ve been meaning to try Go. I ended up with about 70 lines of moderately-ghastly Go code that did the job.

For this Creative Commons image (thanks Fuelrefuel/Wikimedia Commons!)

Photo of people in an office

I ended up with a photomosaic like this:

Photomosaic of people in an office

As far as I can tell, that’s pretty much the same filter that ran in the ad. Here’s another example. First, a picture of me:

Matt Cutts

and here’s the resulting mosaic’ed image:

Matt Cutts in mosaic form

That’s all the interesting stuff. You can stop reading now.

This part is boring. Really. No need to keep reading. The code I came up with is really ugly, but the pseudo-code is pretty simple:


- Read the picture into a go image
- Number of horizontal tiles = image_width / desired_tile_width
- Number of vertical tiles = image_height / desired_tile_height
- Loop through tiles with nested vertical and horizontal for loops
- For each tile, loop over the tile's pixels to compute average RGB values
- Loop over the tile's pixels again & set new_color = (avg_color+curr_color)/2
- Write the image out as a new picture

That’s it! I wanted a quick and dirty test, so I didn’t worry about things like the leftover pixels if the tiles didn’t evenly divide the image.

Let’s see, what else. Things I liked about Go:
– It’s super-easy to read and write images, so I could concentrate on the fun stuff.
– I like that documentation like this gives a clear, easy way to set up your environment. The golang tour is great too. And installing Go on Ubuntu is easy: “sudo apt-get install golang” and you’re done.
– The language makes a lot of sense to me, in a C kind of way.

Some things didn’t make as much sense to me, or at least I need to do more reading:
– My initial program just read a JPEG and wrote it back out, and the output image was considerably dimmer. I was just using default encoding values, so maybe some gamma values got left out, but it was a little weird. I was expecting read->decode->encode->write to be a no-op.
– When I read the JPEG into an image and tried to write directly to that image, Go gave me an error. That was a little strange. I ended up copying the JPEG to a new image and then I could write.
– In the spirit of just doing stuff without reading the documentation, it seemed like Go images stored their At() component colors with 16 bits of range (from 0..65536). But when I wanted to write colors with Set() it seemed like Go wanted 8 bits in the example I found. So for a while I was casting stuff with (uint8) and getting totally random bits written into the image. That also generated a fun image:

Random mosaic from converting a 16 bit-range color to uint8

but it took me a few minutes to figure out what was going on. I’m sure some reading would clear things up, but.. who cares? I was also doing some weird float arithmetic to compute color averages. This was just quick/dirty code, and I can read more about the nitty gritty later. As soon as I got the effect I wanted, I rapidly lost interest. I even hard-coded image filenames because I couldn’t be bothered to search for go command-line flag info. All in good fun.
– Arrays and slices are cool, but allocating 2D arrays and slices seems a little verbose.
– I like that Go’s designers have opinions and enforce them, at least 99% of the time. When you’re hacking ugly code, it was annoying to get the “you didn’t use this variable” errors. But I understand the rationale and it’s probably a good idea for writing Real Code that’s not intended to be thrown away.
– I was all set to grouse about go fmt’s enforced indentations/spacing, but it actually looks pretty reasonable. Basically, each indent is a tab. Then if you’re a 3 or 4 space indent kind of guy, you can configure your editor like vim or emacs to change how the tab width is displayed.

Historically, Python is my language of choice to knock out a quick script thing–I love Python dictionaries. But with Go’s speed, support for dictionaries/maps, and capability to do HTTP servers very easily, I might end up switching to Go. I think I’ll use Go for my next little fun project.

Added: Thanks to Tom Madams who whipped a prototype of this filter in video using Shadertoy!

css.php