Skip to content

Instantly share code, notes, and snippets.

View treyharris's full-sized avatar

Trey Harris treyharris

View GitHub Profile
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
#use utf8;
use PerlIO::eol;
use open IN => ':raw:eol(CRLF?)';

Fuzzy matching of any numeric type

In Elisp: Numbers (Comparison of Numbers), a suggested definition of approx-equal is given as:

(defvar fuzz-factor 1.0e-6)
(defun approx-equal (x y)
  (or (= x y)
      (< (/ (abs (- x y))
            (max (abs x) (abs y)))

Fuzzy matching of any numeric type

In Elisp: Numbers (Comparison of Numbers), a suggested definition of approx-equal is given as:

(defvar fuzz-factor 1.0e-6)
(defun approx-equal (x y)
  (or (= x y)
      (< (/ (abs (- x y))
 (max (abs x) (abs y)))
default (current layout):
1. core.weechat
1. irc.server.freenode
1. irc.server.quakenet
2. perl.highmon
3. irc.freenode.#perl6
4. irc.freenode.#lopsa
5. irc.freenode.#lopsa-lounge
6. irc.freenode.#emacs
7. irc.freenode.#zsh
;; source: http://steve.yegge.googlepages.com/my-dot-emacs-file
;; TODO/FIX: Fix when another buffer is visiting a file with the same
;; basename. In this case, (buffer-name) becomes something like
;; "relative_dirname/filename", which breaks this function.
(defun rename-file-and-buffer (new-name)
"Renames both current buffer and file it's visiting to NEW-NAME."
(interactive "sNew name: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
#!/usr/bin/env perl6
# Stolen from https://docs.perl6.org/language/functions#sub_nextwith
# and annotated with line numbers
proto a(|) {*}
multi a(Any $x) {
say "Any $x";
say "This is Any L$?LINE";
@treyharris
treyharris / My-Modules-Script.pm6
Last active June 21, 2019 22:05
The minimal working CLI
#!/usr/bin/env perl6
## To get a MAIN to run in a unit module/package:
unit module My-Modules-Script;
## You must have the `is export` here; `our` will not work
sub MAIN($x) is export {
say "This is the module's MAIN called with $x";
@treyharris
treyharris / My-Fourth-Modules-Script.pm6
Created June 21, 2019 21:55
This is a unit package that works
#!/usr/bin/env perl6
unit package My-Fourth-Modules-Script;
our proto MAIN($) is export { * }
multi MAIN($x) {
say "This is the inside MAIN called with $x";
}
@treyharris
treyharris / My-Fourth-Modules-Script.pm6
Created June 21, 2019 21:46
This one produces no output
#!/usr/bin/env perl6
unit package My-Fourth-Modules-Script;
our proto MAIN($) is export { * }
multi MAIN($x) {
say "This is the inside MAIN called with $x";
}
#!/usr/bin/env perl6
package My-Fourth-Modules-Script {
proto MAIN($) is export { * }
multi MAIN($x) {
say "This is the inside MAIN called with $x";
}
}