Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View yakovsh's full-sized avatar

Yakov Shafranovich yakovsh

View GitHub Profile
@yakovsh
yakovsh / 2004_10_12-ie_cookies.html
Created January 17, 2016 17:15
Making Cookies Work in IE
<!--
Recently I had a weird problem while using Tomcat - sessions would get lost when using Microsoft's Internet Explorer.
Since Tomcat stores the session id as JSESSIONID cookie, the session would get lost when the cookie is not stored.
Same behavior occurs with other web servers including IIS and Resin.
After further research, it seems that IE does not store cookies at default privacy settings unless a P3P policy is
provided for the site. In order to bypass this problem, a basic P3P policy needs to defined and included in the site.
I used IBM's P3P editor to generate a basic P3P XML policy file and the following snippet of HTML code to enable it.
This is still true as of 2011: [http://blog.toppingdesign.com/2011/11/18/ie-iframe-p3p-cookies-oh-my/]
@yakovsh
yakovsh / 2006_01_03-js_highlight.js
Last active January 17, 2016 17:13
Inobstrusive Form Field Highlighting in JavaScript
/*
* One of the recent problem that I ran across at work is an easy way to do highlighting for form fields.
* Of course the best way would be CSS 2
* (as shown here [http://www.cssdrive.com/index.php/examples/exampleitem/focus_pseudo_class/]) but alas,
* IE does not support that.
*
* The alternative is JavaScript onFocus and onBlur method. However, one thing which I also wanted to avoid
* is changing over 200 different pages in our system to add those in. So instead, I wrote a simple piece of
* Javascript which attaches the event handlers on the fly. The best part about this is that the actual form
* does not need to be changed - just include the Javascript on the bottom of your webpage. The code is as follows
<!--
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
@yakovsh
yakovsh / 2005_01_13-visited-links.css
Last active January 17, 2016 16:01
Making Visited Links Look the Same as Unvisited Links
@yakovsh
yakovsh / 2004_08_30-xml_in_html.xsl
Last active January 17, 2016 16:00
Display XML in HTML files (XSLT)
<!--
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="*">
@yakovsh
yakovsh / 2008_12_28-unicode_in_s3.pl
Last active January 17, 2016 16:00
Handling Unicode Data in Amazon S3 Headers
# 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):
@yakovsh
yakovsh / 2009_05_06-delete_s3_bucket.pl
Last active January 17, 2016 15:59
Deleting Amazon S3 Bucket with A Lot of Files
#!/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',
@yakovsh
yakovsh / 2008_10_24-cleanup.pl
Last active January 17, 2016 15:59
Cleaning Up Bad HTML in Perl
#
# 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();
@yakovsh
yakovsh / 2009_02_09-cleanup2.pl
Last active January 17, 2016 15:59
Cleaning Up Bad HTML in Perl, Take 2
# 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 = '';
@yakovsh
yakovsh / 2008_10_26-fix_utf8_input.pl
Last active January 17, 2016 15:58
Fixing "Input is not proper UTF-8, indicate encoding" Error
# 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);