Skip to content

Instantly share code, notes, and snippets.

@femto113
femto113 / transpose.js
Last active September 6, 2023 00:28
one line transpose for 2-dimensional Javascript arrays
function transpose(a)
{
return a[0].map(function (_, c) { return a.map(function (r) { return r[c]; }); });
// or in more modern dialect
// return a[0].map((_, c) => a.map(r => r[c]));
}
@femto113
femto113 / view_source_filter.rb
Created February 10, 2011 22:01
Server-side view source for Rails via after_filter with SyntaxHighlighter
class MyController < ApplicationController
after_filter { response.body = %Q{<html><body><pre>#{CGI.escapeHTML(response.body)}</pre></body></html>} }
#...
end