Yearly Archives: 2011
Uncategorized PoliticsThe Would Be Rabbit Assassin
April 20, 2011 – 5:03 pm
On April 20th 1979, President Jimmy Carter was attacked by a giant, swimming rabbit. Yes, this actually happened, and we have the pictures to prove it.
NYC kills the 1 day MTA Fun Pass
April 14, 2011 – 10:43 am
If you live in New York City, people visit you. It’s not you, it’s the city, but hey, I’ll take it. Inevitably the question of the subway arises: How do I get from where you live to where I want to go? In the past, the answer was simple. Just buy the $4 one day funpass, and well, don’t worry about it. Just hop on the subway, and go! NYC is a daunting enough place for tourists, the funpass, introduced in 1999, helped make NYC a little bit friendlier and easier to navigate. I’ve personally walked a few random tourists through buying one.
It’s a real shame, and I think it’s a bad move on the MTA’s part. I understand why they did it: the $4 fun pass would have been $20 cheaper for your average commuter than the increasingly dear monthly pass. ( Which at $104 a month makes a vespa seem very attractive)
Unlimited transportation within the City is, I believe, a tremendously freeing thing. The monthly pass means that I can stop off anywhere, at any time, en route to work or coming home without racking up another $2.50 in fees. It means I can peruse shops at leisure, pickup something from the farmers market, or go out to eat without worrying how much it’s going to cost me just to get there and get home. The same is true for tourists: unlimited subway passes turn the city into their playground. How many tourists now are going to hop off the subway in soho on their way to Times Square when it will cost them an extra $2.50?
I’d wager that the loss of the funpass, while probably earning the MTA a little bit of money in the short run, will be a huge net loss for the City as a whole. Especially for small businesses in areas that don’t traditionally get alot of tourist traffic, the tax on wanderlust will hurt. Less tangible, though perhaps even more damaging, is the effect on the world’s image of NYC. The magic of travel is the road less travelled, the serendipitous cafe, the joy of discovery. The fun pass gave tourists the excuse to indulge in an adventure. It’s loss means that the City is a less magical place. It’s glitter will fade, and that for more and more visitors, Bubba Gump’s in Times Square, The Empire State Building, and Ground Zero will be their New York.
Whatever benefit the MTA gets from killing the funpass, it’s not worth it.
Magic Regex Generator
April 13, 2011 – 4:05 pm
txt2re.com: input the text you’d like to run a regex against, and then select the results you’d like returned, and presto! it provides the code in the language of your choice.
This system acts as a regular expression generator. Instead of trying to build the regular expression, you start off with the string that you want to search. You paste this into the site, click submit and the site finds recognisable patterns in your string. You then select the patterns that you are interested in and it writes a fully fledged program that extracts those patterns from that string. You then copy the program into your editor or IDE and play with it to integrate it into your program.
Amazing.
Glasses free 3d on the ipad 2
April 12, 2011 – 11:03 am
Using the forward facing camera to track the location of your eyes, the iPad2 can dynamically create a 3D environment that reorients itself as you and the iPad2 move.
Question Assumptions
April 11, 2011 – 4:52 pm
So often the traditional methods and means of getting things done are built around assumptions that are either outdated, or don’t apply in a novel situation. Mark Wahlberg was able to shoot several fight scenes, which typically take 20 days each, for a movie whose entire shooting schedule was 35 days. How did he do it? He actually filmed real fights, the same way that HBO films live fights for pay per view.
From 37 signals:
Experts go with what they know. And they’ll often insist something needs to take a long time. But when you don’t have tons of resources, you need to ask if there’s a simpler, judo way to get the impact you desire. Sometimes there’s a better way than the “best” way.
The question becomes, then, how can you tell if there is a simpler way? That is the result of being honest with yourself about what it is you are trying to achieve.
The goal was to make the fights seem real. Not to make them look good. To seem real. Focusing on that changes the requirements.
It enables you to switch mental modes: We aren’t making a movie, we are shooting a fight. That happens all the time, in real time, on TV. When you re-examine your requirements, you can see where there are shortcuts to be made not only because restrictions that previously existed no longer do, but a clearer understanding of the goal enables you to step outside your current domain and re-examine other domains for best practices. In the case of “The Fighter”, the other domain was that of sports television: literally brimming with expertise and best practices around capturing live action in a compelling way.
The enemy isn’t best practices and acquired wisdom, it’s a failure to understand truly what it is your want to achieve, and from there search for expertise in other domains.
Nginx, WordPress Network, and Fastcgi Cache: The Ultimate Guide.
April 5, 2011 – 1:06 pm
Update: new sections in the nginx config for handling the wordpress admin section!
Update: new upstart script.
Update Feb 9, 2016 No longer need ngx_cache_purge compiled in, Ubuntu 14.04+ specific.
In honor of Antirez’ fantastic post here: On the web server scalability and speed are almost the same thing, I’m sharing my Nginx configuration for WordPress Network (previously WordPress-Mu).
I’m assuming you are running ubuntu and you know the basics of system administration. I’m also assuming you’re using some sort of fastcgi backend. I suggest this excellent howto from interfacelab as an excellent starting point.
First, go get the nginx mainline PPA. Might need to install common-software-properties first.
|
1 2 3 |
sudo apt-get install -y software-properties-common apt-add-repository -y ppa:nginx/development apt-get update && apt-get install -y nginx-extras |
Next,in your nginx.conf, add this line in the http section:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
http { ... #this bit here keeps filesystem stats down to a minimum # at the expense of some ram. open_file_cache max=5000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on; #ramming speed! fastcgi_cache_path /dev/shm/nginx levels=1:2 keys_zone=WORDPRESS:32m inactive=64m; ... } |
This creates a cache of 64MB. It’s stored in memory, so be sure you’ve got overhead. If you’re running a blog, unless you’ve got HUGE files, it’s unlikely you’ll need this much cache, and you can probably safely pare this down further to save memory.
And the final piece, the server configuration for nginx. Note the usage of the variable $nocache, and also the purge location.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
server { listen [::]:80; # both ipv4 and ipv6! server_name .example.com; # if you are using subdomains gzip on; gzip_http_version 1.1; gzip_vary on; gzip_comp_level 9; gzip_proxied any; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; gzip_buffers 16 8k; gzip_disable "MSIE [1-6].(?!.*SV1)"; client_max_body_size 8M; client_body_buffer_size 128k; access_log /var/log/nginx/access.log; keepalive_timeout 10; root /var/www/wordpress; index index.php; #on server block ##necessary if using a multi-site plugin server_name_in_redirect off; ##necessary if running Nginx behind a reverse-proxy # port_in_redirect off; #this is if you use w3total-cache and want to use it's minification #features with rewrites instead of get variables for a cdn. location ~* \.(css|js) { if (!-f $request_filename) { rewrite ^/wp-content/w3tc(.*?)/min/w3tc_rewrite_test$ /wp-content/w3tc$1/min/index.php?w3tc_rewrite_test=1 last; rewrite ^/wp-content/w3tc(.*?)/min/(.+\.+.(css|js))$ /wp-content/w3tc$1/min/index.php?file=$2 last; rewrite ^/wp-content/w3tc(.*?)/min/(.+\.(css|js))$ /wp-content/w3tc$1/min/index.php?file=$2 last; expires 365d; } } # handle static files. location / { try_files $uri @wordpress; if_modified_since before; #keeps it new for the user expires 30d; # client side caching } # ugly but necessary regex. location @wordpress { rewrite ^.*/files/(.*) /wp-includes/ms-files.php?file=$1; if (!-e $request_filename) { rewrite ^.+/?(/wp-.*) $1 last; rewrite ^.+/?(/.*\.php)$ $1 last; rewrite ^(.+)$ /index.php?q=$1 last; } # use browser side caching for these expires 30d; add_header Cache-Control private; } # enable purging of stale content. # see this plugin: # http://wordpress.org/extend/plugins/nginx-proxy-cache-purge/ # activate it network wide location ~ /purge(/.*) { fastcgi_cache_purge WORDPRESS $host$1$request_method; allow SOME.IP.ADD.RESS; deny all; } location ~ \.php$ { # Zero-day exploit defense # http://forum.nginx.org/read.php?2,88845,page=3 # Won't work properly (404 error) if the file is not stored on this #server, which is entirely possible with php-fpm/php-fcgi. # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on #another machine. And then cross your fingers that you won't get hacked. try_files $uri =404; # checks to see if the visitor is logged in, a commenter, # or some other user who should bypass cache set $nocache ""; if ($http_cookie ~ (comment_author_.*|wordpress_logged_in.*|wp-postpass_.*)) { set $nocache "Y"; } #the usual fastcgi pass, I like unix sockets, less resource contention fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param REMOTE_ADDR $http_client_ip; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_pass unix:/tmp/php5-fastcgi.socket; # here is the fastcgi caching magic: # bypass cache if logged in. # Be sure that this is above all other fastcgi_cache directives fastcgi_no_cache $nocache; fastcgi_cache_bypass $nocache; # use stale cache if the backend fails. fastcgi_cache_use_stale error timeout invalid_header http_500; # cache key is based on the host and the uri, you could add other # key variables here as it suites your needs fastcgi_cache_key $host$request_uri$request_method; fastcgi_cache WORDPRESS; # what to cache, and for how long fastcgi_cache_valid 200 302 10m; fastcgi_cache_valid 301 1h; fastcgi_cache_valid any 1m; } location /nginx_status { # copied from http://blog.kovyrin.net/2006/04/29/monitoring-nginx-with-rrdtool/ stub_status on; access_log off; allow SOME.IP.ADD.RESS; deny all; } } |
Be sure to install the nginx_proxy_cache_purge plugin, and activate it network wide. And that’s it!
Just for kicks, try:
|
1 |
ab -c 1000 -n 10000 http://yourdomainhere.com/ |
Post your results in the comments!
If you happen to be using a recent ubuntu, try this out for your upstart script
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
description "nginx http daemon" author "George Shammas " start on (filesystem and net-device-up IFACE=lo) stop on runlevel [!2345] env DAEMON=/usr/local/bin/nginx env PID=/var/run/nginx.pid expect fork respawn pre-start script $DAEMON -t if [ $? -ne 0 ] then exit $? fi end script post-stop script start-stop-daemon --stop --pidfile $PID --name nginx --exec $DAEMON --signal TERM end script exec $DAEMON |
|
1 |
Mod_Pagespeed & Smush.it for jpegs: don’t use them
March 28, 2011 – 4:48 pm
Don’t use mod_pagespeed (with the default settings! see below for more info) or Smush it if you care at all about how your pictures look.
So, in looking around at some nifty solutions to speed up page rendering and web serving in general, I came across mod_pagespeed and smush.it, both claiming to provide all sorts of wonderful optimizations, specifically, losslessly compressing images. All of their other claims aside, the particular claim regarding lossless image optimization is a lie. A damned lie. The “optimized” images look like washed out crap, at least using the default optimization settings for both systems.
Smush.it claims it’s optimization is lossless, which is clearly not true. Mod_pagespeed lists lossy compression as a risk in their documentation. Points off for me for failing to RTFM.
Mouse over the images below to see just how bad the optimized versions are.
from mod_pagespeed
From Smush It:
Update from @jmarantz: Try ‘ModPagespeedDisableFilters rewrite_images’ or ‘ModPagespeedDisallow *.jp*g’ to turn off lossy compression.
Will do. Thanks for the note.
Chess Without Turns
March 25, 2011 – 4:51 pm
Reminds me of playing speed chess in Washington Square: Chess Without Turns.
Essentially the strategy against newbs is get the queen in action as soon as possible and go on the offensive. Against more advanced players, you have to play defense, attempting to take out their powerful players until all they have is pawns.
Electric Bikes Are Here.
March 25, 2011 – 4:20 pm
I’m an ardent futurist. I believe that prodigious improvements that technology has provided humanity over the course of our existence will continue indefinitely into the future, much like the inevitability of evolution and entropy.
That said, I’m a pragmatist as well. “If it ain’t broke, don’t fix it” are wise words to live by.
So, when I see an old standard, the preferred method of long distance locomotion for billions of human beings supplanted by new technology I start to take notice.
For the past year, after having moved out to brooklyn, I’ve noticed a trend among the deliverymen of our neighborhood: one by one they are moving to electric bicycles. At first, I thought it was a fad. Someone figured out that by spending a little bit more on their bike, they wouldn’t have to peddle all night long. I thought, surely this new technology, when faced with the rigors of delivery service would soon succumb to the more robust traditional human powered bike, with it’s easily repaired mechanical systems. But the fleet of electric bikes has only grown and surprisingly one model seems to have won out the in the selection of the fittest: the green power classic bike, which can be purchased for something on the order of 4 to 5 times the street value of a huffy.
Essentially, the benefits of an electric bike outweigh the total costs of ownership for delivering food, perhaps the most rigorous use case for a bike. This is a watershed moment for electric personal transportation revolution.
Here they are, in action:
Grepping for Gaddafi
March 23, 2011 – 7:52 pm
How do you programmatically find someone’s name in text if there is no generally agreed upon spelling? Moamer Kaddafi present a unique challenge for those of us who like to parse our news before reading it. Several solutions are presented at StackOverflow
The regex, which basically brute forces several well known spellings:
\b(Kh?|Gh?|Qu?)[aeu](d['dt]?|t|zz|dhd)h?aff?[iy]\b
This solution, though, is my favorite though. It uses Soundex which searches for any set of sounds in a given set of english text that approximate the basic phonetics of Gaddafi’s name:
What the Hell is a Microsievert?
March 20, 2011 – 11:15 am
Handy chart explaining radiation exposure from xkcd.
Navigational Aids for the Visually Impaired
March 17, 2011 – 2:57 pm
NAVI – Navigational Aids for the Visually Impaired: Hacking together the Kinect, a vibrotactile waist belt, and a blue helmet to help blind people navigate. Also Vibrotactile is my new favorite word.

Home