Skip to content

Instantly share code, notes, and snippets.

View steveklabnik's full-sized avatar
🦀
Rustacean

Steve Klabnik steveklabnik

🦀
Rustacean
View GitHub Profile
@steveklabnik
steveklabnik / source.rake
Created February 13, 2012 15:21 — forked from indirect/source.rake
rake tasks to fix whitespace
def find_and_replace_in_source_files(find, replace)
extensions = %w[.rhtml .rxml .erb .builder .rb .css .js .rake]
files = Dir["**/*"]
files.each do |file_name|
next if (file_name =~ /^vendor/) || !extensions.include?(File.extname(file_name))
text = File.open(file_name, 'r'){ |file| file.read }
changed = text.gsub!(find, replace)
File.open(file_name, 'w'){|file| file.write(changed)} if changed
end

You're right, I think, about there being an inverse relationship between power and readability in code.

I strongly, strongly disagree with this. Mostly because 'readability' is entirely subjective. For certain audiences, things can be more powerful and more readable at the same time.

For example, let's examine a case in Ruby, that also pertains to Haskell: Symbol#to_proc. A new Rubyist may write some code that looks like this:

[1,2,3,4,5].each {|number| number.to_s}

However, a more experienced Rubyist will write this code like this:

@steveklabnik
steveklabnik / lolmetaprogramming.rb
Created February 14, 2012 17:56
Metaprogramming rots your brain.
# Metaprogramming rots your brain.
# First I wrote this:
Data = Struct.new(:title)
data.collect{|datum| Data.new(datum["title"])}
# Then I decided I didn't want to make a huge list of attributes, so I decided to use an
# OpenStruct, and ended up doing this:
require 'hateoas'
class Maze
include Hateoas::MediaType
media_type "application/vnd.amundsen.maze+xml"
serialization :xml
element :maze,
@steveklabnik
steveklabnik / index.html
Created February 27, 2012 20:01
hypermedia search
<!DOCTYPE html>
<html>
<head><title>SEARCH</title></head>
<body>
<form method="GET" action="/results">
<input type="text" name="q" />
<input type="submit" />
</form>
</body>
</html>
@steveklabnik
steveklabnik / plain_language.txt
Created March 9, 2012 01:54
Hypermedia benefits in plain language
Hypermedia designs scale better, are more easily changed and promote decoupling
and encapsulation, with all the benefits those things bring. On the downside,
it is not necessarily the most latency-tolerant design, and caches can get stale
if you're not careful. It may not be as efficient on an individual request level
as other designs.
@steveklabnik
steveklabnik / toc.text
Created March 11, 2012 14:19
"Designing Hypermedia APIs TOC"
Foreward
About This Project
Hypermedia API
Web Worship
Hypermedia Benefits in Plain Language
Linking
Hypertext
Programming The Media Type (COMING SOON)
The Design Process an Overview
Building the W3CLove API
@steveklabnik
steveklabnik / conference_dicks.txt
Created March 13, 2012 17:30
A woman's opinion on dick jokes at conferences
[redacted] is real good at making me angry.
the argumentation lacks any show of willingness to try to empathize
with those that whole differing view points, or who may be impacted
negatively by the behavior in question.
Why is he defending dick jokes, moreover, why is he defending people
that make dick jokes; why does he make dick jokes. I feel like, by
asking those three questions, I am currently at a more powerful point
for real understanding than he is, because he is
require 'rubygems'
require 'bundler/setup'
require 'webmachine'
require 'webmachine/adapters/rack'
require './shoes'
Shoes = Webmachine::Application.new do |app|
app.routes do
add ["css", "*"], PublicResources