Skip to content

Instantly share code, notes, and snippets.

View draegtun's full-sized avatar

Barry Walsh draegtun

View GitHub Profile
@draegtun
draegtun / remove-last.r3
Last active December 21, 2015 03:39
What I would like to see REMOVE/LAST do.
Rebol []
; see - http://stackoverflow.com/questions/18231434/in-a-series-what-is-the-best-way-of-removing-the-last-element
remove-last: func [
"Removes value(s) from tail of a series."
series [series! port! bitset! none!]
/part range [number!] "Removes to a given length."
][
either part [take/last/part series range] [take/last series]
Rebol []
; PHP
; $string = preg_replace( '/^@(.*?)@$/', '#$1#', $string );
;
; Perl
; $string =~ s/^\@(.*?)\@$/#$1#/;
;
; # or...
; $string =~ s/\A\@(.*?)\@\Z/#$1#/;
Rebol [
see-gist: https://gist.github.com/miyagawa/5455942
also-this: https://gist.github.com/shanselman/5422230#comment-823247
comment: "My fledgling Rebol port of this Perl code"
requires: "Rebol/View - for https:// port"
github-support: "Thank you Austin@Github for (initiating) the fix for Rebol syntax highlighting"
]
split-string: func [text delim /local s coll] [
coll: copy []
@draegtun
draegtun / select.r2
Last active December 16, 2015 07:59
Simple Rebol dialect example.
REBOL [
Purpose: "Providing Rebol example of a Lisp macro given in HN comment"
HNcomment: https://news.ycombinator.com/item?id=5482124
usage: "select [word-value from collection-list]"
]
select: func [block /local totals] [
parse block [
set this word!
'from
@draegtun
draegtun / fasta.pl
Last active December 11, 2015 23:18
Faster fasta.pl
use 5.016;
use warnings;
# See: http://news.ycombinator.com/item?id=5141179
#
# This fasta.pl is a port of fasta.rb and is 2.6 times quicker than original alioth fasta.pl
use constant IM => 139968;
use constant IA => 3877;
use constant IC => 29573;
@draegtun
draegtun / goldilocks_1_port_from_js.pl
Last active December 11, 2015 04:08
Goldilocks (subset) in perl 5 & 6
use 5.016;
use warnings;
# Inspired by: http://news.ycombinator.com/item?id=5024754 | http://news.ycombinator.com/item?id=5025485
# (port of) - https://gist.github.com/3755270
package Bear {
sub new {
my ($class, $porridge, $chair, $bed) = @_;
bless {
@draegtun
draegtun / gist:2836306
Created May 30, 2012 13:20
Log of Perl 5.16 install + cpanm + Moose & MongoDB
[~]$ date
Wed 30 May 2012 13:01:15 BST
[~]$ perlbrew install perl-5.16.0
Fetching perl-5.16.0 as /Users/barry/perl5/perlbrew/dists/perl-5.16.0.tar.gz
Installing /Users/barry/perl5/perlbrew/build/perl-5.16.0 into ~/perl5/perlbrew/perls/perl-5.16.0
This could take a while. You can run the following command on another shell to track the status:
tail -f ~/perl5/perlbrew/build.log
@draegtun
draegtun / Compute.pl
Created March 22, 2012 10:23
Saw this and just wanted to play!
#
# see http://perl.plover.com/idiocy/Addition.pm by MJD
#
use 5.014;
use warnings;
{
package Compute;
use Carp;
@draegtun
draegtun / accessor.pl
Created February 9, 2012 20:07
Python accessor example converted to Moose
{
package AnotherPerson;
use Moose;
use namespace::autoclean;
has _firstname => (is => 'rw', isa => 'Str', accessor => 'firstname');
has _lastname => (is => 'rw', isa => 'Str', accessor => 'lastname' );
}
my $you = AnotherPerson->new;
@draegtun
draegtun / arity.io
Created November 2, 2011 16:16
block() with unknown arity
arity := block (
"You provided #{call argCount} args" interpolate println
call evalArgs foreach (arg, "... #{arg}" interpolate println)
)
// "call evalArgs" is a shortcut for "call message argsEvaluatedIn(call sender)"
var := "test"
arity call( "1", 2 + 2, var );
arity call