// jQuery
$(document).ready(function() {
  // code
})| var fs = require('fs'), | |
| url = require('url'); | |
| module.exports = function (rootDir, indexFile) { | |
| indexFile = indexFile || "index.html"; | |
| return function(req, res, next){ | |
| var path = url.parse(req.url).pathname; | |
| fs.readFile('./' + rootDir + path, function(err, buf){ | 
| // @license http://opensource.org/licenses/MIT | |
| // copyright Paul Irish 2015 | |
| // Date.now() is supported everywhere except IE8. For IE8 we use the Date.now polyfill | |
| // github.com/Financial-Times/polyfill-service/blob/master/polyfills/Date.now/polyfill.js | |
| // as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values | |
| // if you want values similar to what you'd get with real perf.now, place this towards the head of the page | |
| // but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed | 
| @mixin no-select { | |
| -webkit-touch-callout: none; | |
| -webkit-user-select: none; | |
| -khtml-user-select: none; | |
| -moz-user-select: none; | |
| -ms-user-select: none; | |
| user-select: none; | |
| } | 
In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.
A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.
You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.
class Article < ActiveRecord::Base| Function SaveAllSheetsAsCSV(outputPath As String) | |
| On Error GoTo Heaven | |
| ' each sheet reference | |
| Dim Sheet As Worksheet | |
| ' path to output to | |
| 'Dim outputPath As String | |
| ' name of each csv | |
| Dim OutputFile As String | 
| # Usage: | |
| # ruby concat.rb /path-to-compass-gem/frameworks/compass/stylesheets/_compass.scss > compass-all.scss | |
| @seen = [] | |
| def concat(file) | |
| File.foreach(file) do |line| | |
| if line =~ /^\s?@import "(.+?)";/ | |
| import = $1 | |
| unless @seen.include?(import) | 
I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.
I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various efforts they've made to level it out. And their operations are a mess; they don't real
| (function(def){ | |
| def('myModule', ['someDependency', 'somethingElse'], function(someDependency, somethingElse){ | |
| //return the module's API | |
| return {}; | |
| }); | |
| }( | |
| // wrapper to run code everywhere | |
| typeof define === 'function' && define.amd? | 
