Skip to content

Instantly share code, notes, and snippets.

View pragdave's full-sized avatar
🖍️
Alternating between Haskell and PDP-11 assembler

Dave Thomas pragdave

🖍️
Alternating between Haskell and PDP-11 assembler
View GitHub Profile
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class BuildStatusTest < ActiveSupport::TestCase
context "expiring build statii" do
should "remove the old one" do
assert_equal 2, BuildStatus.count
BuildStatus.expire_old
statii = BuildStatus.all
assert_equal 1, statii.size
assert statii[0].updated_at >= 30.days.ago
if RUBY_PLATFORM =~ /java/
ENV["GEM_HOME"] = ENV["GEM_PATH"] = nil
require 'rubygems'
gem 'nokogiri'
end
require 'nokogiri'
doc = Nokogiri::XML.parse(DATA.read, nil, 'utf-8')
p doc.errors
module MigrationHelpers
def fk(from_table, from_column, to_table=from_column.to_s.sub(/_id$/, 's'))
constraint_name = "fk_#{from_table}_#{from_column}"
execute %{alter table #{from_table}
add constraint #{constraint_name}
foreign key (#{from_column})
references #{to_table}(id)}
end
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:rx="http://www.renderx.com/XSL/Extensions">
<!-- ============================================================ -->
<!-- -->
<!-- This file makes a part of RenderX XSL Test Suite -->
<!-- -->
<!-- Author: Alexander Peshkov -->
<!-- -->
<!-- (c) RenderX, 2003 -->
<!-- -->
def m(*args)
print "Args to m: ", args.inspect, " Result: "
120
end
n = 6
o = 2
# Imagine using a language where whitespace is significant? Pah!
# Ask Nokogiri to find the row containing the header names
headers = table.search('thead > tr')
# Create a hash that maps the column name to the column index, so I can access subsequent
# rows' data by name
header_map = headers.search('th')
.map(&:text)
.each_with_index
.with_object({}) {|(name, index), hash| hash[name] = index}
require 'coverage'
Coverage.start
STDOUT.reopen("/dev/null")
require_relative 'fizzbuzz.rb'
Coverage.result.each do |file_name, counts|
File.readlines(file_name).each_with_index do |code_line, line_number|
count = counts[line_number] || "--"
STDERR.printf "%3s: %s", count, code_line
end
end
# A poor implementation of FizzBuzz, just to show code coverage stuff
1.upto(100).with_object('') do |i, x|
if i % 3 == 0
x += 'Fizz'
end
if i % 5 == 0
x += 'Buzz'
end
if x.empty?
NAME = "ruby3" # eg: JAERLANG, RAILS -*- ruby -*-
# This stanza is for the creation of the code .zip and .tgz files.
# It's also used for the .mobi file
TITLE = "Programming Ruby 1.9"
AUTHOR = "Thomas, with Fowler and Hunt"
CODE_IGNORE_LIST = "README"
require "../PPStuff/util/rake/main.rb"
input = [ 1, 2, 3, 4, 5, 8, 9, 11, 12, 13, 15 ]
# Need to box the value to make it mutable
State = Struct.new(:last_value)
def returning(value) yield; value; end
# divide the input into runs of consecutive numbers
s = input.slice_before(State.new(input.first)) do |value, state|
returning(value != state.last_value.succ) do