Skip to content

Instantly share code, notes, and snippets.

@keithrbennett
keithrbennett / gist:809088
Created February 3, 2011 05:23
WordLookup, for Rick
class WordLookup
def run()
lines = File.readlines('words.txt')
File.open('words-with-definitions.txt', 'w') do |output_file|
# assume the only thing on the line is the word
lines.each do |word|
@keithrbennett
keithrbennett / sample.xml
Created March 31, 2011 02:39
XML File Illustrating Use of SYSTEM Keyword for DTD Validation
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE Foo SYSTEM "sample.dtd">
<Foo/>
@keithrbennett
keithrbennett / sample.dtd
Created March 31, 2011 02:41
Minimal DTD Sample
<?xml version="1.0" encoding="us-ascii"?>
<!ELEMENT Foo ()>
@keithrbennett
keithrbennett / dtd_test_irb_session.txt
Created March 31, 2011 02:44
Transcript of IRB session illustrating DTD Validate Problem
ree-1.8.7-2011.01 :003 > doc = Nokogiri::XML::Document.parse(File.read('sample.xml'))
=> #<Nokogiri::XML::Document:0x80899448 name="document" children=[#<Nokogiri::XML::DTD:0x80898e44 name="Foo">, #<Nokogiri::XML::Element:0x80898d40 name="Foo">]>
ree-1.8.7-2011.01 :004 > puts doc.validate
No declaration for element Foo
=> nil
{ % }: ls -lRh 5.Apr.11 16.46
total 0
drwxr-xr-x 5 kbennett staff 170B Apr 5 14:44 candidate_summary
drwxr-xr-x 5 kbennett staff 170B Apr 5 15:39 committee_summary
drwxr-xr-x 3 kbennett staff 102B Apr 5 15:40 fda-drug-labels
drwxr-xr-x 4 kbennett staff 136B Apr 5 15:40 fdic-failed-institutions
drwxr-xr-x 5 kbennett staff 170B Apr 5 15:41 fdic-insured-institutions
drwxr-xr-x 3 kbennett staff 102B Apr 5 15:42 foreign_labor_statistics
drwxr-xr-x 4 kbennett staff 136B Apr 5 15:38 mining
@keithrbennett
keithrbennett / riak_object_save_delete_save_test.rb
Created June 3, 2011 20:48
Script that illustrates that when an RObject is created, saved, created, deleted, then created, saved again, it is not successfully saved to the riak data store.
#!/usr/bin/env ruby
# Script that illustrates that when an RObject is created, saved,
# created, deleted, then created, saved again, it is not
# successfully saved to the riak data store.
require 'rubygems'
require 'riak'
CLIENT = Riak::Client.new
@keithrbennett
keithrbennett / make_rel.out
Created June 6, 2011 21:32
Output of 'make rel' of riak 0.14.2 on Mac OS
fatal: Not a git repository (or any of the parent directories): .git
./rebar get-deps
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
==> cluster_info (get-deps)
==> skerl (get-deps)
==> protobuffs (get-deps)
==> basho_stats (get-deps)
==> mochiweb (get-deps)
@keithrbennett
keithrbennett / instance_validator.rb
Created June 19, 2011 21:23
Validates that public instance methods of a class are defined.
# Shows a crude way to enforce that a class implements
# required methods. Use it like this:
#
# class OkClass
# def foo; end
# def bar; end
# def baz; end
# end
#
#
@keithrbennett
keithrbennett / encryption_contract.rb
Created June 19, 2011 21:30
Sample Contract Class
require 'instance_method_validator'
module EncryptionContract
def required_function_names
[
# The purpose of this function is self-evident, but in other
# cases the methods would benefit from some explanation
# that would be helpful to authors of new implementations,
# such as defining correct behavior, format and data type
@keithrbennett
keithrbennett / reverse_encrypter_spec.rb
Created June 19, 2011 21:31
Beginning of rspec test class for ReverseEncrypter
require 'rspec'
require 'reverse_encrypter'
describe ReverseEncrypter do
it "should implement required methods" do
lambda { subject.validate_contract }.should_not raise_error
end
end