This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Nanoc3::Filters | |
class Tar < Nanoc3::Filter | |
type :text => :binary | |
identifier :tar | |
def run(filename, params={}) | |
# Stores the filenames of all reps to include | |
filenames = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
preprocess do | |
# Find items to put in archives | |
items_to_archive = items.select { |i| i.identifier =~ /^\/files/ } | |
# Group them by extension | |
item_groups = items_to_archive.group_by { |i| i[:extension] } | |
# For each extension (and their items)... | |
item_groups.each_pair do |extension, items| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mp3info' | |
require 'yaml' | |
rule %r{^dst/.*\.mp3$} => [proc { |tn| tn.sub(/^dst\//, 'src/') }] do |t| | |
puts "*** copying #{t.source}" | |
# Copy | |
FileUtils.mkdir_p(File.dirname(t.name)) | |
FileUtils.copy_file(t.source, t.name) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NEW: | |
def test_compile_with_two_mutually_dependent_reps | |
with_site(:compilation_rule_content => 'filter :erb') do |site| | |
File.open('content/foo.html', 'w') do |io| | |
io.write('<%= @items.find { |i| i.identifier == "/bar/" }.compiled_content %>') | |
end | |
File.open('content/bar.html', 'w') do |io| | |
io.write('<%= @items.find { |i| i.identifier == "/foo/" }.compiled_content %>') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Implementation | |
class Arrow | |
class Either | |
attr_reader :obj | |
def initialize(obj) | |
@obj = obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FibSlow | |
def run(n) | |
if n == 0 | |
0 | |
elsif n == 1 | |
1 | |
else | |
run(n-1) + run(n-2) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'nokogiri' | |
doc = Nokogiri::HTML('<p>abc</p>') | |
doc.inner_html = '<p>…</p>' | |
puts doc.inner_html | |
# output: <p>â¦</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
puts "Setting up..." | |
array = [] | |
10000.times { |i| array << i } | |
puts "Running..." | |
Benchmark.bmbm do |bm| | |
bm.report('.reverse_each') do | |
10000.times { array.reverse_each { |i| } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'minitest/autorun' | |
require 'nokogiri' | |
class MyEncodingTest < MiniTest::Unit::TestCase | |
def test_replace_document | |
doc = Nokogiri::HTML('<p>abc</p>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
▸ ls -l content | |
-rw-r--r-- 1 ddfreyne staff 29 Jun 9 21:21 header1.h | |
-rw-r--r-- 1 ddfreyne staff 22 Jun 9 21:57 header2.h | |
-rw-r--r-- 1 ddfreyne staff 87 Jun 9 21:45 main.c | |
▸ cat content/header1.h | |
#include "header2.h" | |
OlderNewer