Skip to content

Instantly share code, notes, and snippets.

Avatar
😶
¯\_(ツ)_/¯

Matthew Kerwin phluid61

😶
¯\_(ツ)_/¯
View GitHub Profile
@phluid61
phluid61 / keyboard hijacks.js
Created Nov 3, 2019
Greasemonkey script to disable keyboard hijacking
View keyboard hijacks.js
// ==UserScript==
// @name Disable keyboard hijacking
// @description Stop websites from highjacking keyboard shortcuts
//
// @run-at document-start
// @include *
// @exclude https://www.youtube.com/*
// @grant none
// ==/UserScript==
@phluid61
phluid61 / 2019-09-05.md
Created Sep 15, 2019
thoughts on draft-ietf-httpbis-header-structure
View 2019-09-05.md

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.

@phluid61
phluid61 / generate_views_parallel
Last active Jun 6, 2019
Run generate_views in parallel: `MAX_PARALLEL_CHILDREN=4 bin/generate_views_parallel myrepo`
View generate_views_parallel
#!/usr/bin/perl -w
use FindBin;
use lib "$FindBin::Bin/../perl_lib";
use EPrints;
use strict;
use Getopt::Long;
use Pod::Usage;
@phluid61
phluid61 / hangmun.rb
Last active Sep 13, 2018
Redwine's assignment, done in Ruby
View hangmun.rb
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 / strings.rb
Last active Feb 1, 2018
The best way to generate strings in Ruby...
View strings.rb
# 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 / reencode.pl
Last active Nov 7, 2017
EPrints 'reencode' subroutine to heuristically detect certain non-UTF-8 encodings
View reencode.pl
#
# 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 / README.md
Last active Sep 14, 2017
EPrints - custom view menu size function
View README.md

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 / hpush.pm
Last active Jul 20, 2017
hpush -- like 'push' for a hash
View hpush.pm
package hpush;
use base 'Exporter';
our @EXPORT = ('hpush');
use strict;
use warnings;
sub hpush (\%@) {
my $h = shift;
@phluid61
phluid61 / bigdecimal-test.rb
Created Jul 19, 2017
Testing BigDecimal in Ruby
View bigdecimal-test.rb
require 'bigdecimal'
def _sprintf num
('%0.45f' % num).sub(/0+$/,'')
end
n = 1
loop do
n += 1
@phluid61
phluid61 / test_a.rb
Last active Mar 28, 2017
How to unit test module methods
View test_a.rb
require 'test/unit'
$VERBOSE = true
#require 'a'
module A
extend self
def add(x, y)
x + y
end
end