This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Recently I had to work with Google AJAX API data which returns in JSON. For my purposes, the data needed to be in XML. | |
# While there is a CPAN module called XML2JSON which is designed to do that, for some reason it chokes on my input. | |
# Instead, I adopted a much more simple technique from the Google::Data::JSON module as follows. | |
use JSON::Any; | |
use XML::Simple; | |
my $convertor = JSON::Any->new(); | |
my $data = $convertor->decode($json); | |
my $xml = XMLout($data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# Here is a short script that can mass delete files in an Amazon S3 bucket. It is limited to a 1,000 keys at a time | |
# | |
use Net::Amazon::S3; | |
my $s3 = Net::Amazon::S3->new({ | |
aws_access_key_id => 'ACCESS_ID', | |
aws_secret_access_key => 'ACCESS_KEY', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Here is a short way to cleanup bad HTML input and convert to XML with Perl: | |
# | |
use HTML::TreeBuilder; | |
use XML::LibXML; | |
$html_code = ''; | |
my $builder = HTML::TreeBuilder->new(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# During a recent project, I ran into an issue when handling Unicode data in metadata headers in Amazon S3. | |
# Apparently, Amazon adds on "?UTF-8?B?" in front of any Unicode data and "?=" in end of the data. | |
# I could not find any existing standard that describes this or why it is done, but I surmise this probably | |
# has to do with Base-64 encoding and how it handles Unicode. | |
# | |
# As per @rawnsley: | |
# apparently this is because HTTP headers must only be encoded in ASCII: http://stackoverflow.com/a/4410331/671393 | |
# | |
# An easy Perl hack to get around this is as following (assuming you are using MIME::Base64 module): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
While working with XSLT templates, I came across an interesting problem. I am using an XSLT template | |
to transform an XML file into HTML. However, for debugging purposes I need to see the original XML | |
and since the generation process is done on a web server (like Resin does), it is not easy to get it. | |
The solution: display the original XML file inside the output HTML itself. As it turns out, this was | |
not easy since it requires to change all "<" and ">" to use entities like "<" and ">". In XSLT, | |
the solution looks as follows (another solution would be to use JavaScript to escape this client-side) | |
--> | |
<xsl:template match="*"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
One of our customers had recently requested a feature to make all links look the same, visited or unvisited. | |
While debates and complaints have been raised about whether they should look the same, in our case this was | |
necessary. A web application such as ours usually dynamically generated all the content. That means that | |
links may stay static but their content changes. Therefore, visited links make no sense in a dynamic system. | |
In any case, the way I made them look the same is via the following piece of CSS | |
*/ | |
A:link {color: blue} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Here is how I am wrapping text via XSLT as opposed to CSS and JavaScript. The reason why I am prefering to do this | |
server side via XSLT as opposed to JavaScript client-side is because if I will be doing client-side JavaScripts, | |
I would have to escape the stuff during the HTML generation anyway in XSLT server-side. So in the same processing | |
power I might as well wrap it instead. Of course you can also do it via some fancy JavaScript client side by going | |
through the entire table and chopping up the text in each row, but that would make things look rather interesting | |
to the user (tables automatically re-arranging themselves). | |
Anyway, here is a simple recursive template based on the code posted by Andrew Welch: | |
https://web.archive.org/web/20070116081723/http://www.xslt.com/html/xsl-list/2002-03/msg00334.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here is another way to cleanup bad HTML with Perl, and convert to XML: | |
# This approach relies on the HTML::DOMbo module to do the actual conversion | |
# between HTML and XML, and HTML::TreeBuilder for parsing. | |
use HTML::DOMbo; | |
use HTML::TreeBuilder; | |
use XML::LibXML; | |
$html_code = ''; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' The problem with PostgreSQL is lack of documentation for Windows interfaces. Visual Basic uses | |
' the ADO library to connect to the PostgreSQL ODBC driver, which in turns connects to the server. | |
' | |
' This example covers a unique requirement - the network has over 300 individual desktop machines, | |
' all of which must be able to access the planned PostgreSQL server via Access, VBA or VB6. | |
' However, they do not want to go and setup a data source name (DSN) on each machine separately | |
' (installing ODBC is easier via the Windows deployment tools). Unfortunately, the ODBC driver has | |
' absolutely zero documentation as to how to setup an ADO connection WITHOUT a DSN. After some prolonged | |
' tries and failures, we both were finally able to come up with a solution which I am posting here for | |
' others to benefit from. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quick way to fix the following error in Perl: | |
# | |
# :1: parser error : Input is not proper UTF-8, indicate encoding ! | |
# Bytes: 0xA0 0x20 0xA0 0x3C | |
# | |
# Use this command: | |
# | |
use Encode: | |
$string1 = decode("UTF-8", $input); |
OlderNewer