Skip to content

Instantly share code, notes, and snippets.

View ctfliblime's full-sized avatar

Clay Fouts ctfliblime

  • PTFS
  • Portland, Oregon
View GitHub Profile
@ctfliblime
ctfliblime / opac-search.pl
Created May 26, 2011 14:58
Using "local" to isolate caching
### a snippet from code added to opac/opac-search.pl
use vars qw($cache $MRXorig);
# This is not intended to be a long-term cache, but one that persists for
# only the duration one might expect to page around some search results.
# The max_size may need to be increased for very busy sites.
$cache = CHI->new(driver => 'Memory', global => 1, max_size => 3_000_000, expires_in => 120);
$MRXorig = \&MARC::Record::new_from_xml;
sub _koha_marc_update_bib_ids {
my ($record, $frameworkcode, $biblionumber, $biblioitemnumber) = @_;
my @isbns = $record->subfield('999','e'); # Account for 999$e field
my $new_field = MARC::Field->new(
'999' , '', '',
'c' => $biblionumber,
'd' => $biblioitemnumber,
map { ('e' => $_) } @isbns
);
@ctfliblime
ctfliblime / gist:1187534
Created September 1, 2011 23:09
Using TIEHANDLE to modify filehandle output
package Plack::Middleware::Debug::CatchStderr;
use parent qw(Plack::Middleware::Debug::Base);
use strict;
use warnings;
our $VERSION = '0.001';
sub TIEHANDLE {
my ($class, $fh) = @_;
@ctfliblime
ctfliblime / gist:1211547
Created September 12, 2011 15:28
How to get this exception to percolate all the way up to the Plack middleware?
sub reserve_GET : Args(1) {
my ($self, $c, @args) = @_;
try {
my $reserve = Koha::Model::Reserve->new(reservenumber => $args[0])->load;
$self->status_ok($c, entity=>as_tree($reserve));
}
catch {
if (/^No such Koha::/) {
HTTP::Exception::404->throw;
@ctfliblime
ctfliblime / gist:1235618
Created September 22, 2011 18:42
Why do these hashes have different contents?
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
sub return_void {
return;
}
@ctfliblime
ctfliblime / gist:1275289
Created October 10, 2011 13:14
This one will work on Perl 5.8 (and probably much earlier)
#!/usr/bin/env perl
use strict ;
use warnings;
use locale ;
my @table=(1,2,3,8,5,8,0,4) ;
my @places ;
# Max value
@ctfliblime
ctfliblime / gist:1314938
Created October 26, 2011 00:27
This is not the most efficient way, but it seems to work.
#!/usr/bin/env perl
use Koha;
use C4::Context;
use C4::Reserves;
use C4::Circulation;
use C4::Items;
my $dbh = C4::Context->dbh;
my $itemnumbers = $dbh->selectcol_arrayref(
@ctfliblime
ctfliblime / gist:2846252
Created May 31, 2012 21:01
Solr index schema
<?xml version="1.0" ?>
<schema name="VuFind Bibliographic Index" version="1.2">
<types>
<fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
<fieldType name="textFacet" class="solr.TextField" sortMissingLast="true" omitNorms="true">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<!-- strip trailing punctuation from facets: -->
<filter class="solr.PatternReplaceFilterFactory" pattern="(?&lt;!\b[A-Z])[.\s]*$" replacement="" replace="first"/>
</analyzer>
@ctfliblime
ctfliblime / gist:2969326
Created June 21, 2012 23:58
Web API sketch
HTTP request headers indicate API version and representation format:
Accept: application/vnd.koha.liblime.com+json; version=0.01
Accept: application/vnd.koha.liblime.com+xml; version=0.01
Defaults to JSON and most recent API version.
POST /catsearch?query=asdf #Generates catalog search result set and returns HTTP 201 with Location set to search ID
GET /catsearch/12345 #Returns the result set, defaults e.g. start=0, count=20
@ctfliblime
ctfliblime / gist:3997082
Created November 1, 2012 22:21
LibLime Koha Solr stats for 2012-10-31
LibLime Koha Solr stats for 2012-10-31
Searching:
- 37.4k total searches (average 1,558/hour)
- peak hour handled 3,660 (about 1/second)
- average request service time was 49ms
Index updates:
- 71.5k total document updates (average 3,578/hour)
- peak hour had 6,988 updates (just under 2/second)