Skip to content

Instantly share code, notes, and snippets.

View csirac2's full-sized avatar

Paul Harvey csirac2

View GitHub Profile
#!/usr/bin/perl -wT
use warnings;
use strict;
sub _stashText {
my ($fragment, $map, $key) = @_;
my $id = $map->{index};
ASSERT(ref($map) eq 'HASH') if DEBUG;
@csirac2
csirac2 / ensureIndexOnDBs.js
Created April 26, 2011 06:25
MongoDB ensureIndex on all databases
var databases = db.adminCommand('listDatabases')['databases'];
for (var item in databases) {
db = db.getMongo().getDB(item['name']);
db.current.ensureIndex({_web: 1});
db.current.ensureIndex({_topic: 1});
db.current.ensureIndex({'TOPICINFO.author': 1});
db.current.ensureIndex({'TOPICINFO.date': 1});
db.current.ensureIndex({'CREATEINFO.author': 1});
db.current.ensureIndex({'CREATEINFO.date': 1});
@csirac2
csirac2 / mongodb_count_all_dbs.js
Created May 8, 2011 09:30
MongoDB count all documents in a collection across all databases
var databases = db.adminCommand('listDatabases')['databases'];
var count = 0;
for (var item in databases) {
print(databases[item]['name']);
count = count + db.getMongo().getDB(databases[item]['name']).current.count();
}
@csirac2
csirac2 / CharacterTests.pm
Created June 1, 2011 14:14
CharacterTests - beginning utf8 stress tests for foswiki
package CharacterTests;
use strict;
use warnings;
# Using utf8, so we can have interesting chars in the source code.
use utf8;
use FoswikiFnTestCase;
our @ISA = qw( FoswikiFnTestCase );
@csirac2
csirac2 / Addressable.pm
Created August 20, 2011 07:25
Foswiki::Addressable ?
# See bottom of attachment for default license and copyright information
package Foswiki::Contrib::MigrationScriptsContrib::Roles::FoswikiAddressable;
use Moose::Role;
use Assert;
use Foswiki::Func();
use Foswiki::Meta();
use Foswiki::Address();
@csirac2
csirac2 / UTF8Tests.pm
Created September 30, 2011 09:28
some test madness
package UTF8Tests;
use strict;
use warnings;
# TODO: Exercise
# $Foswiki::cfg{Site}{CharSet}
# $Foswiki::cfg{UseLocale}
# $Foswiki::cfg{Site}{Locale}
# $Foswiki::cfg{Site}{Lang}
# $Foswiki::cfg{Site}{FullLang}
@csirac2
csirac2 / test.pl
Created October 20, 2011 23:42
perl unisanity
#!/usr/bin/perl -CSAD
# You probably want to run as perl -CSAD /tmp/test.pl
# This is a little exploration of http://perldoc.perl.org/perlunicode.html#The-"Unicode-Bug"
# See also http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default
use utf8;
use warnings;
use strict;
my $u = 'ü';
@csirac2
csirac2 / CSVDemo.pm
Created October 29, 2011 12:31
Re-save scripts in Sandbox
#!/usr/bin/perl -wT
# See bottom of file for default license and copyright information
package CSVDemo;
use strict;
use warnings;
# Adjust these variables to suit your own data/requirements
my $formname = 'System.MigrationScriptsCSVDemo.CSVDemoForm';
my ( $csvtopic, $csvfile ) =
@csirac2
csirac2 / drop.js
Created November 8, 2011 05:32
drop matching databases
use webs
db.map.find({_id : /^ParentWeb/i}).forEach(function (thing) { db = db.getMongo().getDB(thing.hash); db.dropDatabase(); });
@csirac2
csirac2 / perlitdy.pl
Created April 13, 2012 01:07
perltidy filter for Method::Signatures & friends
#!/usr/bin/perl
package main;
use strict;
use warnings;
use Perl::Tidy();
my $secret = '# __PERLTIDY_IGNORING ###';
my $secret_sub = '# __PERLTIDY_KEYWORD: ';
sub perltidy {