Skip to content

Instantly share code, notes, and snippets.

View rwstauner's full-sized avatar
💤
I may be slow to respond.

Randy Stauner rwstauner

💤
I may be slow to respond.
View GitHub Profile
@rwstauner
rwstauner / hashthread.rb
Created January 22, 2024 23:20
java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because "store[...]" is null
h = { a: 0 }
n = 1000
threads = (1..n).flat_map do |i|
[
Thread.new { h["i#{i}"] = 1 },
Thread.new { h.delete("i#{i}") },
]
end.map(&:join)
puts h.inspect
@rwstauner
rwstauner / perl-syntax-sql.vim
Created June 22, 2011 15:01
highlight SQL syntax in a Perl heredoc
" ~/.vim/after/syntax/perl.vim
let s:bcs = b:current_syntax
unlet b:current_syntax
syntax include @SQL syntax/sql.vim
let b:current_syntax = s:bcs
" match optional, surrounding single or double quote and any whitespace in the heredoc name
syntax region perlHereDocSQL matchgroup=Statement start=+<<\(['"]\?\)\z(\s*SQL\s*\)\1+ end=+^\z1$+ contains=@SQL
@rwstauner
rwstauner / check_prereqs.pl
Last active January 4, 2016 13:29
Look for unlisted perl prereqs
#!/usr/bin/env perl
# Originally from http://github.com/cpan-api/cpan-api (5c280d86fb0db818bedefdc46ee1d2c6276a01e4).
# PODNAME: check_prereqs.pl
# TODO: this stuff should be in other modules somewhere
use strict;
use warnings;
use Perl::PrereqScanner 1.014;
use CPAN::Meta::Requirements;
@rwstauner
rwstauner / gist:5678576
Last active December 17, 2015 21:59
Get an ini string from a plugin bundle
*$ perl -MData::Dumper -e 'use Dist::Zilla::Config::BundleInspector;
print Dist::Zilla::Config::BundleInspector->new(
bundle_class => "Dist::Zilla::PluginBundle::RJBS"
)->ini_string'
[Git::GatherDir]
[CheckPrereqsIndexed]
[CheckExtraTests]
[@Filter]
package inc::AlienBuild;
use Moose;
extends 'Dist::Zilla::Plugin::ModuleBuild';
with 'Dist::Zilla::Role::FileGatherer';
sub gather_files {
my ($self) = @_;
my $file = $self->zilla->main_module->name;
@rwstauner
rwstauner / req
Last active December 13, 2015 18:08
Examples of paths used for perl modules (inside their releases) that aren't beneath "lib/" or in the root (no directory)
*$ perl -MJSON -Mojo -e '$j = j(p( $ARGV[1], $ARGV[0] )->body); @f = map { $_->{fields} } @{ $j->{hits}{hits} }; print @f ? JSON->new->utf8->pretty->encode([@f, {total => $j->{hits}{total}}]) : $j' '{"query":{"match_all":{}}, "filter":{"and":[ {"term":{"module.indexed":true}}, {"term":{"status":"latest"}}, {"not": {"or": [{"prefix":{"path":"lib/"}}, {"term":{"level":0}}] } }]}, "fields":["release", "module.name", "path"],"size":50}' "https://api.metacpan.org/module/_search"
[
{
"module.name" : "XML::Pastor::Test::Type::Country_name",
"path" : "test/out/lib/XML/Pastor/Test/Type/Country_name.pm",
"release" : "XML-Pastor-1.0.4"
},
{
"module.name" : "XML::Pastor::Test::Type::Country",
"path" : "test/out/lib/XML/Pastor/Test/Type/Country.pm",
@rwstauner
rwstauner / main.pl
Created April 30, 2012 16:18
trying to figure out win32 STDIN hang with IPC::Open2
$arg = ' ' . shift @ARGV;
$script = qq[perl pipe1.pl $arg];
system(q{perl -e "print qq[hi$/there$/]" | } . $script);
use IPC::Open2 "open2";
$pid = open2($out, $in, $script);
$|=1;
print $in qq[hi$/there$/];
@rwstauner
rwstauner / accessor_maker.pm
Created November 29, 2011 17:52
Devel::Cover 0% branch coverage for externally defined methods
package accessor_maker;
sub import {
no strict 'refs';
*{ caller() . '::' . 'foo' } = sub { $_[0]->{ 'foo' } };
}
1;
@rwstauner
rwstauner / weirdness.pl
Created June 26, 2011 22:12
Perl bug? Weird combination of do, local, and something else? (http://bit.ly/mhaQ4x)
# original weirdness: same result changing local to my and if(){} to bare {}
sub weird {
my ($c) = @_;
if( ref $c ){
return (ref $c eq 'SCALAR' ? 't' : do { local $/; warn "# doing\n"; 'do'; });
}
return 'r';
}
# fix: no local, no my