Skip to content

Instantly share code, notes, and snippets.

Class Something
attr_accessor :foo
end
something = Something.new
something.respond_to?(:foo) # => true
something.respond_to?(:foo=) # => true
something.respond_to?(:bar) # => false
@jrochkind
jrochkind / gist:22ee1b97a3cb581f9138
Created February 11, 2015 20:56
Here's how you get the leader in traject
to_field "something" do |record, accumulator|
leader = record.leader
# The only reason you want the leader is becuase you are going to do
# SOMETHING with it, right? You're not just gonna index the leader, are ya?
output = do_something_to(leader)
accumulator << output
end
@jrochkind
jrochkind / gist:488d4c5e63677038149d
Last active January 11, 2017 15:32
ruby_concurrent ThreadPool

Thread Pools

A Thread Pool is an abstraction that you can give a unit of work to, and the work will be executed by one of possibly several threads in the pool. One motivation for using thread pools is the overhead of creating and destroying threads. Creating a pool of reusable worker threads then repeatedly re-using threads from the pool can have huge performace benefits for a long-running application like a service.

concurrent-ruby also offers some higher level abstractions than thread pools. For many problems, you will be better served by using one of these -- if you are thinking of using a thread pool, we especially recommend you look at and understand Futures before deciding to use thread pools directly instead. Futures are implemented using thread pools, but offer a higher level abstraction.

But there are some problems for which directly using a thread pool is an appropriate solution. Or, you may wish to make your own thread pool to run Futures on, to be separate or have different characterist

<doc>
<container xmlns:foo="http://one">
<foo:node>
</container>
<container xmlns:foo="http://two">
<foo:node>
</container>
</doc>
^Crake aborted!
Interrupt:
/Users/jrochkind/.gem/ruby/1.9.3/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
/Users/jrochkind/.gem/ruby/1.9.3/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
/Users/jrochkind/.gem/ruby/1.9.3/bundler/gems/blacklight_marc-3959de95eb3f/lib/railties/solr_marc.rake:37:in `block (4 levels) in <top (required)>'
/Users/jrochkind/.gem/ruby/1.9.3/bundler/gems/blacklight_marc-3959de95eb3f/lib/railties/solr_marc.rake:20:in `block (3 levels) in <top (required)>'
Tasks: TOP => solr:marc:index:work
(See full trace by running task with --trace)
Error running fixtures
D, [2014-08-26T14:48:18.070539 #12386] DEBUG -- : Instance stop method called for pid '12397'
NFO [main] (MarcImporter.java:582) - Adding 30 of 30 documents to index
INFO [main] (MarcImporter.java:583) - Deleting 0 documents from index
INFO [main] (MarcImporter.java:456) - Calling commit (with optimize set to false)
Aug 26, 2014 2:41:00 PM org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer$Runner run
WARNING: A problem has occured exiting runner org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer$Runner@bdccedd
org.apache.solr.common.SolrException: Not Found
Not Found
request: http://127.0.0.1:8888/solr/update?wt=xml&version=2.2
@jrochkind
jrochkind / gist:59b6330e3f52710cc49e
Last active June 8, 2023 07:47
Monkey patch to ActiveRecord to forbid
######################
#
# Monkey patch to ActiveRecord to prevent 'implicit' checkouts. Currently tested with Rails 4.0.8, prob
# should work fine in Rails 4.1 too.
#
# If you create a thread yourself, if it uses ActiveRecord objects without
# explicitly checking out a connection, one will still be checked out implicitly.
# If it is never checked back in with `ActiveRecord::Base.clear_active_connections!`,
# then it will be leaked.
#
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.8)
actionpack (= 4.0.8)
mail (~> 2.5.4)
actionpack (4.0.8)
activesupport (= 4.0.8)
builder (~> 3.1.0)
erubis (~> 2.7.0)
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.5)
actionpack (= 4.0.5)
mail (~> 2.5.4)
actionpack (4.0.5)
activesupport (= 4.0.5)
builder (~> 3.1.0)
old = hash[:a][:b]
hash[:a][:b] = hash[:a][:b].dup
hash[:a][:b].equal? old # shouldn't, but did somehow