Skip to content

Instantly share code, notes, and snippets.

View hindman's full-sized avatar

Monty Hindman hindman

  • Apple
  • Cupertino, CA
View GitHub Profile
@hindman
hindman / is_solved.py
Last active August 29, 2015 13:56
Sudoku: is_solved function
# Also see http://norvig.com/sudoku.html
from math import sqrt
def is_solved(raw_puzzle):
# Puzzle as a flat list.
puzzle = [int(v) for v in raw_puzzle.split()]
# Set up dimensions: for example N=81, n=9, and m=3.
N = len(puzzle)
@hindman
hindman / gist:7782111
Created December 4, 2013 03:59
Primes sieve
def primes():
'''
Yields a sequence of prime numbers via the Sieve of Eratosthenes.
This is a modified version of an approach I have seen in several
online discussions.
'''
# The sieve is stored in a dict S, where:
#
# values = all of the primes we have found so far (except 2)
# keys = the composites currently being sieved out.
@hindman
hindman / ElasticSearch_big_int_with_fields_param
Created November 21, 2013 23:07
ElasticSearch error: URLs with ?fields parameter: No matching token for number_type BIG_INTEGER
# Create index.
curl -X DELETE localhost:9200/xx
curl -X PUT localhost:9200/xx
# Set up the mapping to handle very large integer fields.
curl -X PUT localhost:9200/xx/yy/_mapping -d '{"yy": {"properties": {"a": {"type": "string"}, "b": {"type": "string"}}}}'
# Index two documents, the second having very large integers.
curl -X PUT localhost:9200/xx/yy/1 -d '{"a": 123, "b": 456}'
curl -X PUT localhost:9200/xx/yy/2 -d '{"a": 933655199414565157, "b": 9917602859033623819}'
@hindman
hindman / gist:3455954
Created August 24, 2012 21:41
OM: recreating missing elements in a hierarchy
require 'spec_helper'
describe "recreating missing elements in a hierarchy" do
before(:all) do
class FooDoc
include OM::XML::Document
set_terminology do |t|
t.root :path => 'doc', :xmlns => 'foo'
@hindman
hindman / gist:2007325
Created March 9, 2012 16:18
Undefined method `label' for ActiveFedora::SolrDigitalObject
1) Pre-assembly integration can run pre_assembly and produce expected files in staging dir
Failure/Error: @b.run_pre_assembly
NoMethodError:
undefined method `label' for #<ActiveFedora::SolrDigitalObject:0x111bcbf80>
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/active-fedora-3.3.2/lib/active_fedora/base.rb:197:in `label'
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/dor-services-3.1.0/lib/dor/models/identifiable.rb:58:in `to_solr'
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/active-fedora-3.3.2/lib/active_fedora/predicates.rb:47:in `each'
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/active-fedora-3.3.2/lib/active_fedora/predicates.rb:47:in `each'
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/rdf-0.3.5/lib/rdf/repository.rb:287:in `call'
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/rdf-0.3.5/lib/rdf/repository.rb:287:in `each'
@hindman
hindman / gist:1996378
Created March 7, 2012 21:33
Rubydora::FedoraInvalidRequest:
1) Pre-assembly integration can run pre_assembly and produce expected files in staging dir
Failure/Error: @b.run_pre_assembly
Rubydora::FedoraInvalidRequest:
Error getting dissemination for datastream workflows for object druid:wr622bz6218. See logger for details
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/rubydora-0.5.4/lib/rubydora/rest_api_client.rb:281:in `datastream_dissemination'
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/rubydora-0.5.4/lib/rubydora/datastream.rb:117:in `content'
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/dor-services-3.1.0/lib/dor/datastreams/workflow_ds.rb:32:in `content'
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/active-fedora-3.3.2/lib/active_fedora/metadata_datastream_helper.rb:29:in `ensure_xml_loaded'
# /Users/hindman/.rvm/gems/ruby-1.8.7-p357@pre-assembly/gems/active-fedora-3.3.2/lib/active_fedora/base.rb:258:in `to_solr'
# /Users/hindman/.rvm/gems/ruby-1.8.7-p