Skip to content

Instantly share code, notes, and snippets.

View phluid61's full-sized avatar
😶
¯\_(ツ)_/¯

Matthew Kerwin phluid61

😶
¯\_(ツ)_/¯
View GitHub Profile
sub render_possible_doi
{
my( $session, $field, $value ) = @_;
$value = "" unless defined $value;
$value =~ s!^https?://(?:dx\.)?doi\.org/+!!;
if( $value !~ m!(doi:)?10(\.[^./]+)+/.+!i ) { return $session->make_text( $value ); }
$value =~ s!^doi:!!i;
@phluid61
phluid61 / test_a.rb
Last active March 28, 2017 23:46
How to unit test module methods
require 'test/unit'
$VERBOSE = true
#require 'a'
module A
extend self
def add(x, y)
x + y
end
end
@phluid61
phluid61 / bigdecimal-test.rb
Created July 19, 2017 03:31
Testing BigDecimal in Ruby
require 'bigdecimal'
def _sprintf num
('%0.45f' % num).sub(/0+$/,'')
end
n = 1
loop do
n += 1
@phluid61
phluid61 / hpush.pm
Last active July 20, 2017 02:52
hpush -- like 'push' for a hash
package hpush;
use base 'Exporter';
our @EXPORT = ('hpush');
use strict;
use warnings;
sub hpush (\%@) {
my $h = shift;
@phluid61
phluid61 / README.md
Last active September 14, 2017 09:26
EPrints - custom view menu size function

Adds a custom function to EPrints' repository view configuration, so you can define a subroutine for each menu level that returns the map of {id=>count} for that level.

Particularly handy when the a conflict between the menu's fields and the generated DISTINCT BY clause include NULL values in the menu despite allow_null=>0 being specified in config.

See the discussion at

@phluid61
phluid61 / reencode.pl
Last active November 7, 2017 20:53
EPrints 'reencode' subroutine to heuristically detect certain non-UTF-8 encodings
#
# A percent-encoded URI does not necessarily have to encode UTF-8
# sequences. For example:
#
# <https://zhidao.baidu.com/question/210190177.html?qbl=relate_question_0&word=%C4%DA%B2%BF%C9%F3%BC%C6%CD%E2%CE%C4%B2%CE%BF%BC%
#
# The percent-encoded sequence is actually EUC-CN (a Chinese character
# encoding). We have no problem in perl when the 'word' parameter is
# naively converted to octets, however the database will definitely
@phluid61
phluid61 / strings.rb
Last active February 1, 2018 02:32
The best way to generate strings in Ruby...
# A Percent character '%'
eval '% %s %% % '
# (wrapped in `eval` to highlight the trailing space, which is critical)
# A Question-mark character '?'
%?%s?%??
# A Hash character '#'
%{#{%##%%##}#}
@phluid61
phluid61 / hangmun.rb
Last active September 13, 2018 03:57
Redwine's assignment, done in Ruby
all_words = File.open('dictionary.txt', 'r') {|f| f.each_line.map{|l|l.strip}.to_a }
all_words.reject! {|w| w.nil? || w == '' }
# --- prompt and initialise
candidates = []
while candidates.empty?
print "Word length: "
length = STDIN.gets.to_i
@phluid61
phluid61 / generate_views_parallel
Last active June 6, 2019 01:31
Run generate_views in parallel: `MAX_PARALLEL_CHILDREN=4 bin/generate_views_parallel myrepo`
#!/usr/bin/perl -w
use FindBin;
use lib "$FindBin::Bin/../perl_lib";
use EPrints;
use strict;
use Getopt::Long;
use Pod::Usage;
@phluid61
phluid61 / 2019-09-05.md
Created September 15, 2019 04:44
thoughts on draft-ietf-httpbis-header-structure

Thoughts on draft-ietf-httpbis-header-structure

2019-09-15

RE: httpwg/http-extensions#913 (and 790, and 629, ...)

I've been thinking about data types and models again. My premise is that a type is a combination of a range/domain of values, and a set of operations that can be performed on those values.