Login

Handy: Regexes for smart quotes

//Quotes: Replace smart double quotes with straight double quotes.
//ANSI version for use with 8-bit regex engines and the Windows code page 1252.
preg_replace('[\x84\x93\x94]', '"', $text);

//Quotes: Replace smart double quotes with straight double quotes.
//Unicode version for use with Unicode regex engines.
gsub('[\u201C\u201D\u201E\u201F\u2033\u2036]', '"', $text);

//Quotes: Replace smart single quotes and apostrophes with straight single quotes.
//Unicode version for use with Unicode regex engines.
gsub("[\u2018\u2019\u201A\u201B\u2032\u2035]", "'", $text);

//Quotes: Replace smart single quotes and apostrophes with straight single quotes.
//ANSI version for use with 8-bit regex engines and the Windows code page 1252.
gsub("[\x82\x91\x92]", "'", $text);

//Quotes: Replace straight apostrophes with smart apostrophes
gsub("\b'\b", "?", $text);

//Quotes: Replace straight double quotes with smart double quotes.
//ANSI version for use with 8-bit regex engines and the Windows code page 1252.
gsub('\B"\b([^"\x84\x93\x94\r\n]+)\b"\B', '?\1?', $text);

//Quotes: Replace straight double quotes with smart double quotes.
//Unicode version for use with Unicode regex engines.
gsub('\B"\b([^"\u201C\u201D\u201E\u201F\u2033\u2036\r\n]+)\b"\B', '?\1?', $text);

//Quotes: Replace straight single quotes with smart single quotes.
//Unicode version for use with Unicode regex engines.
gsub("\B'\b([^'\u2018\u2019\u201A\u201B\u2032\u2035\r\n]+)\b'\B", "?\1?", $text);

//Quotes: Replace straight single quotes with smart single quotes.
//ANSI version for use with 8-bit regex engines and the Windows code page 1252.
gsub("\B'\b([^'\x82\x91\x92\r\n]+)\b'\B", "?\1?", $text);

Amazing bash scriptaculousness: Find out how long a MySQL schema change will take

#!/bin/bash
(while(true); do  \
(mysql -e 'show innodb status \G' | grep undo\ log\ entries ; sleep 1 ;  \
mysql -e 'show innodb status \G' | grep undo\ log\ entries ) |    \
egrep '[0-9][0-9][0-9][0-9]‘ |awk ‘{print $10;}’ ; done ) | \
perl -e ‘$t = ROWS_IN_TABLE; while(1) { \
$n ++; $nn; $a = <>; $b = <>; $nn += ($b-$a); \
printf “Rate: %d, avg: %d, %0.3f%% complete, done in %d sec\n”, \
$b-$a, $nn/$n, ($b/$t)*100, ($t-$b)/($nn/$n); }’;

God, altering tables is the biggest craptastic part of MySQL. Luckily this takes some of the mystery out of an otherwise harrowing experience.

+10,000 usefulness points if you use MySQL with any scale

Hat tip @michaelmontano

ActiveRecord Optimization with Scrooge: Like Magic!

Brett is experimenting with Scrooge, this awesome drop-in Rails plugin that optimizes ActiveRecord attribute selection. It's an automated application layer query optimizer. You basically transparently get big database performance gains for absolutely free.

It's the closest thing to magic I've seen since... Rails.

Unix for Poets (how to use tr, awk, and all those other crazy unix utils)

Must-read for terminal junkies out there.

WTF is a SuperColumn? An Intro to the Cassandra Data Model (Arin Sarkissian explains)

For the last month or two the Digg engineering team has spent quite a bit of time looking into, playing with and finally deploying Cassandra in production. It’s been a super fun project to take on – but even before the fun began we had to spend quite a bit of time figuring out Cassandra’s data model… the phrase “WTF is a ’super column’” was uttered quite a few times. :)
via arin.me

Digg has gone long on Cassandra. Up until this point I was pretty interested in MongoDB. But suddenly maybe Cassandra is the go-to non-sql data store. If it's good enough for Twitter, Facebook and Digg...

Great, well written, detailed article on understanding Cassandra by Arin Sarkissian here.

Storing 67 terabytes for less than $8K out the door


AWESOME. Might have to build a few of these ourselves sometime soon. Backblaze does online storage/backup so it's pretty obvious that off the shelf cloud storage won't cut it in the long term.

Mad props to them for breaking it down all the way to parts lists. Talk about open source innovation!

Best practices for adding mobile support to your Rails app

199 out of 200 applicants for programming jobs can't code at all

199 out of 200 applicants for every programming job can't write code at all. I repeat: they can't write any code whatsoever.

An oldie but goodie from coding horror. But the fix is easy: always have them code for you in the interviews.

Can you imagine this being true for other professions? Though I suspect it might actually be.

How to scale your site: Solve only 80% of your problem (Often this is not by choice)

Solve only 80% of a problem. That's usually good enough and you'll not only get done faster, you'll actually have a chance of getting done at all.

This strategy is given by Amix in HOW TWITTER (AND FACEBOOK) SOLVE PROBLEMS PARTIALLY. The idea is solving 100% of a complex problem can be so hard and so expensive that you'll end up wasting all your bullets on a problem that could have been satisfactoraly solved in a much simpler way.

If you solve your scaling issue 100%, then you might not be working on features or other important things enough. In a startup, you just can't freaking afford the time and effort.

Rails http acceleration using Varnish + ESI (Edge-side Includes)

Doing research now about ESI / Varnish, and saw this useful explanation of the entire process. ESI looks like a pretty powerful weapon in the web scaling arsenal.
 
Assembling Pages Last: Edge Caching, ESI and Rails