Categories
English Uncategorized

Ruby 2.0.0 p195 PSA

In Ruby 2.0.0 patchlevel 195, you can no longer mix old- and new-style hash syntaxes in method arguments.

For example:

Wrong

method hello: 'there', :goodbye => 'goodnight'

Right

method { hello: 'there', :goodbye => 'goodnight' }

or

method :hello => 'there', :goodbye => 'goodnight'

Apparently this has been fixed in another patch to Ruby 2.0.0, but that doesn’t really matter, since p195 is out right now.

Source: https://gist.github.com/stephencelis/5595842

Categories
English Uncategorized

My Experiences with Rubinius

Rubinius is an implementation of the Ruby language spec. I’ve been using it recently for a project, and I’ve been liking it so far. Here’s a few thoughts I’ve been having while using it.

Philosophy

The Core

Rubinius, in its core, is written in C++ and uses LLVM (Low Level Virtual Machine). Without getting too technical, it translates the Ruby code that you write into efficient machine code, then executes the machine code directly on the CPU. This architecture is very similar to Google’s V8 (and one of the reasons that Google Chrome is a fast browser).

The Concept

Now for the concept of “Ruby”. “Ruby” is a programming language specification, not a program or compiler. The standard reference implementation is called MRI (Matz’s Ruby Interpreter, not magnetic resonance imaging). MRI is used in many production environments, and especially with the latest 2.0.0 release, introduces many performance improvements, and is very stable (all of our new Rails apps are on 2.0.0).

MRI is written mostly in C.

Rubinius’ tagline “Rubinius: Use Ruby™” summarizes the intent of Rubinius. Use Ruby! Because the Rubinius core is as fast as it is, and Ruby code is basically machine code (from the computer’s standpoint), standard libraries – the basic functions of the language – can be written in Ruby. Use Ruby!!

Speed

In development, Rubinius seems to be a little slower than MRI – especially in the first load. Rails is a big library.

In production, especially with a threaded app server (Rubinius has no “Global Interpreter Lock” and supports real threads), however, Rubinius is extremely fast. I’ve been using Puma.

You do need to write thread-safe code, but the payoffs are enormous.

Conclusion

This little project I’m working on will probably not see a “real production” environment anytime soon, so I really wanted to try out some alternative Rubies (there are a few). All in all, my experience with Rubinius has been very good. Can’t wait for the production release of Rubinius!

Categories
English Uncategorized

謎WordPress Part 1

There’s a Japanese word I like, “謎” – the dictionary defines it as “a mystery”, “riddle”, or “enigma” – I like to define it as “something that makes no logical sense whatever”.

Here is a part of WordPress that I think makes no logical sense whatever.

Inconsistent Naming Convention

In The Loop, as WordPress likes to call it, you are given some functions that will output information for you. Handy!

the_title(); // outputs the title of the blog post
the_content(); // outputs the content of the blog post
the_time(); // outputs the timestamp of the blog post
the_permalink(); // a "permalink" to the blog post

You get the idea. Now, you don’t want to output them? You want them in a variable? Fine:

$title = get_the_title();
$content = get_the_content();
$time = get_the_time();

BUT WAIT A SECOND.

$permalink = get_permalink();

WHAT?

WordPress, you had a great, consistent naming scheme up until then. Come on.

Categories
English Uncategorized

Fighting Against Internet Explorer, Part 2

I’ve been making a Facebook iframe app recently, and I found that this little code »

jQuery('a').children('img')

just doesn’t work on Everyone’s Favorite Browser™ (Internet Explorer 8).

jQuery('a').children('img').length

always returned “0” for me. So I had to end up using .find('img') instead.

Categories
English Uncategorized

I hate WordPress

date();

is NOT correct!!!

date_i18n();

(This only applies if you’re outside of UTC. What’s that, like 99% of the world?)

Categories
English Uncategorized

Fighting against IE, part 1.

a:focus {
    outline: 0;
}

Now, back to real work.

Categories
English Uncategorized

The Origins of Twitter

The origins of Twitter.

  1. Here you go, free service!
  2. Wow, thanks for all those users!
  3. Look, you were great, but we don’t (really…) need you anymore.
  4. Fuck you.

In related news, if you haven’t heard about it yet: Twitter API v1.1

Categories
English Uncategorized

text-rendering: optimizeLegibility;

Basically, do not use text-rendering: optimizeLegibility; with Japanese. At least, not yet. Why not? Here are some examples.

The top line has text-rendering: optimizeLegibility; applied, and the bottom line use the browser defaults. As you can probably tell, optimizeLegibility has indeed optimized the legibility, and the type looks much nicer. However, there is a fatal bug in rendering Japanese characters with optimizeLegibility: It seems that the actual optimization is taking place after the length of the line is calculated. As you can imagine, this is a problem. Here’s a screenshot with an underline applied:

Because length-of-line calculations are used to determine line breaks, this bug will also make your sentences break in weird places.

Screenshots taken with Chrome 21 on Mac OS X 10.8. I was able to reproduce this in all WebKit browsers.

Categories
English Uncategorized

Font Smoothing

This is what text (more or less) looks like in Windows! Just do:

“`css
* {
-webkit-font-smoothing: none;
}
“`

To enable Windows Emulation mode. Great stuff.

There’s a few resources about -webkit-font-smoothing in English, but I was wondering what it would look like in Japanese. Here we go.

none;

おはようございます。僕の名前は敬太郎です。東京にうまれ、アメリカのメイン州育ちです。大学は国際基督教大学、3年間の後で退学しました。今は、東京武蔵野市の吉祥寺に住んでて、Flagship LLCでエンジニア・プログラマーとして働いています。よろしくお願いします。

subpixel-antialiased;

おはようございます。僕の名前は敬太郎です。東京にうまれ、アメリカのメイン州育ちです。大学は国際基督教大学、3年間の後で退学しました。今は、東京武蔵野市の吉祥寺に住んでて、Flagship LLCでエンジニア・プログラマーとして働いています。よろしくお願いします。

antialiased;

おはようございます。僕の名前は敬太郎です。東京にうまれ、アメリカのメイン州育ちです。大学は国際基督教大学、3年間の後で退学しました。今は、東京武蔵野市の吉祥寺に住んでて、Flagship LLCでエンジニア・プログラマーとして働いています。よろしくお願いします。
 

Source: Max Voltar

Categories
English Uncategorized

Varnish on a Dynamic Site

TL;DR: Scroll to the bottom for the attached VCL.

No, I’m not talking about the stuff you put on paint to make it last longer.

I’m talking about this amazing piece of software: https://www.varnish-cache.org/

Put simply, Varnish is a “reverse proxy” – a piece of software that goes between the main server and the client. Basically what it does is caches content, so PHP (or whatever backend you’re using) doesn’t need to run for every single request – this makes perfect sense with static content. For sites like WordPress, filled with mostly static content, Varnish will work out of the box (minor configuration changes are required for small things).

Using Varnish with mixed-static and dynamic content is a little harder, though. Recently, we were hired to optimize a client’s website. This particular website was written on a particularly horribly-written framework (it looked like some proprietary framework – not something I want to dissect and analyze for performance). For an example of how awful this framework was, it took about 10 seconds (yes, seconds) for the server to render the index page. After doing as much optimization as possible without dissecting, I was able to cut the time down to about 2 seconds.

2 seconds is still an eternity.

So, I decided to use Varnish. With a big caveat: it only caches content if you aren’t logged in. Since the framework I was working with was intent on setting the PHPSESSID cookie on every page load, I couldn’t just tell Varnish to cache when that cookie was present. Instead, when the user logs in, a LOGIN cookie is set, and Varnish uses this cookie to determine whether to cache the content or not. Logged-in users still have the awful user experience of having to wait 2 seconds for each page to load, but at least people who are just coming to look around have a decent experience.

Here are the relevant sections of the VCL file that enables this logic:

sub vcl_fetch {
  if (!(beresp.http.Set-Cookie ~ "LOGIN") && !(req.http.cookie ~ "LOGIN")) {
    unset beresp.http.Pragma;
    unset beresp.http.Set-Cookie;
    set beresp.http.Cache-Control = "public; max-age=1800";
    unset beresp.http.Expires;
    set beresp.ttl = 30m;
    return (deliver);
  }
}

sub vcl_recv {
  if (req.http.Cookie ~ "LOGIN") {
    set req.http.Cookie = ";" req.http.Cookie;
    set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
    set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID|LOGIN)=", "; 1=");
    set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
    set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
    if (req.http.Cookie == "") {
      remove req.http.Cookie;
    }
  } else {
    remove req.http.Cookie;
  }
}