A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.
Jump to
How to use PHP snippets in Drupal
Enable the core 'PHP filter' module, then select the PHP filter from the 'input formats' list when creating a page.
Using Java classes from XSLT under Coocon / JBoss
Possible MD5 methods:
<xsl:value-of select="md5:encode('$term')" xmlns:md5="java:org.jboss.security.Base64Encoder" />
<xsl:value-of select="md5:encodeString($term,'ISO-8859-1')" xmlns:md5="java:org.hsqldb.lib.MD5" />
Search through built-in classes in JBoss:
find /path/to/jboss-4.2.2.GA/server/default/ -name "*.jar" -exec jar tf {} \; | grep MD5 -H
<xsl:value-of select="md5:encode('$term')" xmlns:md5="java:org.jboss.security.Base64Encoder" />
<xsl:value-of select="md5:encodeString($term,'ISO-8859-1')" xmlns:md5="java:org.hsqldb.lib.MD5" />
Search through built-in classes in JBoss:
find /path/to/jboss-4.2.2.GA/server/default/ -name "*.jar" -exec jar tf {} \; | grep MD5 -H
Parents node's position in XSL
1. Count parents using <xsl:number>
Number can be extracted:
($n)=$c=~/(\d+)\.\d+\.\d+\.\d+$/;
and adjusted:
$n=((($n/2)-5)+1)
<xsl:number count="." level="multiple" from="/page" format="1"/>
Or with format="a", interpret like j=1, l=2, n=3, p=4, etc.
2. Count parents using position()
Simpler -- but apparently this is a weird way to do it. Probably inefficient too.
<xsl:value-of select="count(parent::*/parent::*/parent::*/preceding-sibling::*) - 3"/>
Number can be extracted:
($n)=$c=~/(\d+)\.\d+\.\d+\.\d+$/;
and adjusted:
$n=((($n/2)-5)+1)
<xsl:number count="." level="multiple" from="/page" format="1"/>
Or with format="a", interpret like j=1, l=2, n=3, p=4, etc.
2. Count parents using position()
Simpler -- but apparently this is a weird way to do it. Probably inefficient too.
<xsl:value-of select="count(parent::*/parent::*/parent::*/preceding-sibling::*) - 3"/>
Read an internal Apache variable
...such as %{MY_MOD_OUTPUT_NOTE}n -- that would be available for logging, but not visible by mod_include.
RewriteEngine On
RewriteRule ^(.*)$ $1 [E=MY_MOD_ENV_VAR:%{ENV:MY_MOD_OUTPUT_NOTE}]
RewriteEngine On
RewriteRule ^(.*)$ $1 [E=MY_MOD_ENV_VAR:%{ENV:MY_MOD_OUTPUT_NOTE}]
Labels:
apache,
mod_include,
mod_rewrite,
module,
variables,
webserver
Apache error "premature EOF in parsed file"
When Apache 1.3 says "premature EOF in parsed file".
What it means is "You've messed up the attribute syntax in a mod_include command".
Examples:
<!--#config timefmt=%s --> (no quotes)
<!--#set var='title' value='This title would've screwed things up' --> (apostrophe not escaped)
What it means is "You've messed up the attribute syntax in a mod_include command".
Examples:
<!--#config timefmt=%s --> (no quotes)
<!--#set var='title' value='This title would've screwed things up' --> (apostrophe not escaped)
JSP/XSP generator in Cocoon
Warning: Untested.
In the sitemap.xmap:
<map:match pattern="^(\d+)$" type="regexp">
<map:generate type="serverpages" src="sfapi.xsp">
<map:parameter name="feedid" value="{1}"/>
</map:generate>
The source of sfapi.xsp
<?xml version="1.0" encoding="UTF-8"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp" xmlns:soap="http://apache.org/xsp/soap/3.0">
<results>
<xsp:logic>
int feedid=0;
try {
feedid = Integer.parseInt(parameters.getParameter("feedid"));
} catch (Exception e) {
feedid = -999;
}
</xsp:logic>
<soapcall
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
url="/FeedManager"
>
<m:getFeedData xmlns:m="http://else.something.co.uk/ns/feeds">
<int_1 xsi:type="xsd:int"><xsp:expr>feedid</xsp:expr></int_1>
</m:getFeedData>
</soapcall>
</results>
</xsp:page>
In the sitemap.xmap:
<map:match pattern="^(\d+)$" type="regexp">
<map:generate type="serverpages" src="sfapi.xsp">
<map:parameter name="feedid" value="{1}"/>
</map:generate>
The source of sfapi.xsp
<?xml version="1.0" encoding="UTF-8"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp" xmlns:soap="http://apache.org/xsp/soap/3.0">
<results>
<xsp:logic>
int feedid=0;
try {
feedid = Integer.parseInt(parameters.getParameter("feedid"));
} catch (Exception e) {
feedid = -999;
}
</xsp:logic>
<soapcall
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
url="/FeedManager"
>
<m:getFeedData xmlns:m="http://else.something.co.uk/ns/feeds">
<int_1 xsi:type="xsd:int"><xsp:expr>feedid</xsp:expr></int_1>
</m:getFeedData>
</soapcall>
</results>
</xsp:page>
XSL to copy XML
Andy's way:
<xsl:stylesheet version="1.0" xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node()">
</xsl:apply-templates>
</xsl:copy>
</xsl:template></xsl:output></xsl:stylesheet>
Another way:
<!-- copy the whole document -->
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|text()|comment()|processing-instruction">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:stylesheet version="1.0" xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node()">
</xsl:apply-templates>
</xsl:copy>
</xsl:template></xsl:output></xsl:stylesheet>
Another way:
<!-- copy the whole document -->
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|text()|comment()|processing-instruction">
<xsl:copy-of select="."/>
</xsl:template>
Case sensitive MySQL column
Make a case sensitive varchar column:
CREATE TABLE `page_dm` (
`url` varchar(500) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
http://dev.mysql.com/doc/refman/5.0/en/create-table.html
CREATE TABLE `page_dm` (
`url` varchar(500) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
http://dev.mysql.com/doc/refman/5.0/en/create-table.html
Labels:
case,
characters,
comparisons,
mysql
Different files for log4perl levels
log4perl.rootLogger=DEBUG,CONSOLE,ViewableLog,DebugLog,ErrorLog
###################################################################################
# console - what to watch
log4perl.appender.CONSOLE=Log::Log4perl::Appender::Screen
log4perl.appender.CONSOLE.layout=PatternLayout
log4perl.appender.CONSOLE.layout.ConversionPattern=[%d] [%p %c] - %m%n
log4perl.appender.CONSOLE.Filter = ViewableFilter
log4perl.filter.ViewableFilter = sub { \
my %p = @_; \
$p{log4p_level} eq "FATAL" or \
$p{log4p_level} eq "ERROR" or \
$p{log4p_level} eq "INFO" or \
$p{log4p_level} eq "WARN" \
}
###################################################################################
# Viewable log - record of CONSOLE
log4perl.appender.ViewableLog=Log::Log4perl::Appender::File
log4perl.appender.ViewableLog.layout=PatternLayout
log4perl.appender.ViewableLog.layout.ConversionPattern=[%d] [%p %c] - %m%n
log4perl.appender.ViewableLog.filename = logs/output.log
log4perl.appender.ViewableLog.Filter = ViewableFilter
###################################################################################
# Error log - warnings and errors
log4perl.appender.ErrorLog=Log::Log4perl::Appender::File
log4perl.appender.ErrorLog.layout=PatternLayout
log4perl.appender.ErrorLog.layout.ConversionPattern=[%d] [%p %c] - %m%n
log4perl.appender.ErrorLog.filename = logs/error.log
log4perl.appender.ErrorLog.Filter = ErrorFilter
log4perl.filter.ErrorFilter = sub { \
my %p = @_; \
$p{log4p_level} eq "FATAL" or \
$p{log4p_level} eq "ERROR" or \
$p{log4p_level} eq "WARN" \
}
###################################################################################
# Debug Log - everything
log4perl.appender.DebugLog = Log::Log4perl::Appender::File
log4perl.appender.DebugLog.layout=PatternLayout
log4perl.appender.DebugLog.layout.ConversionPattern=[%d] [%p %c] - %m%n
log4perl.appender.DebugLog.filename = logs/debug.log
log4perl.appender.DebugLog.Filter = AllFilter
log4perl.filter.AllFilter = sub { \
my %p = @_; \
$p{log4p_level} eq "FATAL" or \
$p{log4p_level} eq "ERROR" or \
$p{log4p_level} eq "WARN" or \
$p{log4p_level} eq "INFO" or \
$p{log4p_level} eq "DEBUG" or \
$p{log4p_level} eq "TRACE" \
}
###################################################################################
# To enable DEBUG-level logging for a particular module (and any modules that subclass it),
# un-comment the following and change e.g. 'TempTopicsAdminTools.ModuleManager' to the your own module.
##log4perl.logger.TempTopicsAdminTools.ModuleManager=DEBUG
#log4perl.logger.TempTopicsAdminTools.PageManager=WARN
#log4perl.logger.TempTopicsAdminTools.CategoryManager=WARN
Remove MySQL user password
root@dsdsdsdsd:~# mysql -p
Enter password:
mysql> use mysql;
mysql> update user set Password='' where User='yourusername';
mysql> commit;
mysql> flush privileges;
mysql> quit;
Phone twiddles
Any phone:
Blackberry only:
- *#06# - show IMEI number
Blackberry only:
- from home screen: Hold Alt and type E, A, C, E - displays OS version
Labels:
blackberry,
mobile
Subscribe to:
Posts (Atom)