Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@judofyr
judofyr / superio.rb
Created August 28, 2008 16:06
Turns everything into an IO
require 'open-uri'
# == Feed me with:
#
# Filename:: and I'll give you the file!
# URL:: and I'll give you the content!
# Any string:: and I'll give you a StringIO!
# An integer:: and I'll give you the stream for
# the given integer file descriptor!
# Any IO:: and I'll give you the same IO!
---
extension: xml
layout: nil
filter:
- erb
---
<% pages = @pages.find(:limit => 10,
:in_directory => 'posts',
:sort_by => 'created_at',
:reverse => true) -%>
(defun scheme-run-outline (arg)
(interactive "p")
(save-excursion
(outline-previous-visible-heading arg)
(setq before (point))
(outline-next-visible-heading arg)
(scheme-send-region before (point))))
(define-key scheme-mode-map (kbd "C-c C-o") 'scheme-run-outline)
# Mixin to scan an array for objects that respond to a given method
module WithMethod
# Iterates through the array and returns a list of items that
# respond to method
def with_method(method)
self.select do |item|
item.respond_to(method)
end
end
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en-US'>
<head>
<title>Hampton Catlin Is Totally Awesome</title>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
</head>
<body>
<!-- You're In my house now! -->
<div class='header'>
Yes, ladies and gentileman. He is just that egotistical.
Author.new do
name "Magnus Holm"
location :norway
nickname :judofyr
blog judofyr.net
twitter @judofyr
github / judofyr
end
// This would be sweet Miko:
// Go Object.property!
Speck.describe("your mother") {
it.should("be true") {
true.should = true
}
it.should("not be false") {
false.should_not = true
}
Objects
=======
Here's an object:
+------------+
| Object |
+------------+
If we expand it we can see it contains three parts:
$:.unshift 'lib'
require 'rubygems'
require 'camping'
require 'parkaby'
Camping.goes :App
module App
include Parkaby::Frameworks::Camping
## There's more than one way to do it.
# 0
thing = [1, 2, 3]
# 1
thing.each { }
# 2 (raggi)
thing.each() { }