Skip to content

Instantly share code, notes, and snippets.

@bdenckla
bdenckla / escape_database_for_grant.php
Created February 4, 2012 01:16
Escape SQL (MySQL?) database name for grant
<?php
function escape_database_for_grant( $d )
{
$search = array( '_', '%' );
$replace = array ( '\_', '\%' );
return str_replace( $search, $replace, $d );
}
?>
@bdenckla
bdenckla / wab.pl
Created November 4, 2011 21:27
underscore, while, and angle brackets in Perl
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
sub f { while ( <> ) {} }
my $a = 1;
@bdenckla
bdenckla / bash-script-illustrating-pipefail.sh
Created November 4, 2011 21:23
bash script illustrating pipefail
#!/bin/bash
false; echo "false alone: $?"
false | head; echo "false piped to head: $?"
set -o pipefail
false | head; echo "false 'pipefailed' to head: $?"
@bdenckla
bdenckla / Perl-partial-application.pl
Created October 20, 2011 00:00
Perl function implementing partial function application
sub Pa # Partially Apply
{
my ( $f, @a ) = @_;
sub { $f->( @a, @_ ) }
}
@bdenckla
bdenckla / PHP-partial-application.php
Created October 19, 2011 23:59
PHP function implementing partial function application
<?php
function Pa() // Partially Apply
{
$origArgs = func_get_args();
return function() use ( $origArgs )
{
$allArgs = array_merge( $origArgs, func_get_args() );
return call_user_func_array( 'call_user_func', $allArgs );
};
}