Skip to content

Instantly share code, notes, and snippets.

View yakovsh's full-sized avatar

Yakov Shafranovich yakovsh

View GitHub Profile
@yakovsh
yakovsh / 2016_01_31-remove_interpolation.java
Created February 1, 2016 01:57
Remove interpolation flag from images in a pdf file
import com.itextpdf.text.pdf.*;
import com.itextpdf.text.pdf.parser.PdfImageObject;
import java.io.FileOutputStream;
/**
* This remove the interpolation flag in images in a given PDF file using iText 5.
* Requires: iText 5
*
* For more info, see:
@yakovsh
yakovsh / 2007_07_25-djvu2pdf.sh
Created January 24, 2016 05:05
Converting from DJVU to PDF
#!/bin/sh
#
# Here is the software that is needed for the conversion to take place:
# 1. DjVuLibre .
# 2. LibTiff .
#
# NOTE: The ddjvu utility has an option to convert specific layers. One common mistake is to convert only the mask layer
# or the foreground layer . Technically speaking, the mask layer is the one that should have the actual text but in
# practice I have seen that the the DjVu encoder occasionally puts portions of the text in the background layer. Thus,
# if you only take the foreground or mask layers, you will lose those bits in the background. If your specific files
@yakovsh
yakovsh / 2007_11_09-flatten_pdf.sh
Created January 18, 2016 01:43
Flattening Transparencies in PDF with Free Tools
#!/bin/bash
#
# This script flattens transparencies in PDF files. To use, run the following:
# 2007_11_09-flatten_pdf.sh [input.pdf] [output.pdf]
#
# You will need xpdf-tools and ps2pdf to be installed
#
pdftops -origpagesizes -level3 $1 temp.ps
ps2pdf -dPDFX temp.ps $2
@yakovsh
yakovsh / 2005_01_03-ups_tracking.js
Created January 18, 2016 01:18
Tracking UPS Packages via JavaScript
/**
* A post at TechDigits [https://web.archive.org/web/20050311025802/http://techdigits.blogspot.com/2004/12/ups-package-tracking-with-rss.html]
* about tracking UPS packages via RSS and web services got me thinking if the same is possible via Javascript and
* the XmlHttpRequest object (in IE and Mozilla). Since Google's Gmail and Google Suggest started using that object,
* it has become more popular. So after some thinking, I put together the following quick and dirty code snippet
*
* I don't know how useful this can be since the security information is exposed, but it is a nice hack.
*/
req = new XMLHttpRequest();
var strXML = '<?xml version='1.0'?>' +
@yakovsh
yakovsh / 2008_02_23-pdf_multiplier.java
Created January 17, 2016 17:37
Multiplies pages inside a PDF file, requires iText 2.0.8
/*
* To compile and run:
*
* javac -classpath MultiplyPDF.java
* java -classpath iText-2.0.8.jar MultiplyPDF
*
*/
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
@yakovsh
yakovsh / 2004_09_22-cardexport.sh
Created January 17, 2016 17:31
This script is used to load and unload external SD cards in Palm Pilot devices that are made available to the OS as a USB drive by CardExport II # program,
#!/bin/sh
#
# This script is used to load and unload external SD cards in Palm Pilot
# devices that are made available to the OS as a USB drive by CardExport II
# program, made by www.softick.com.
#
# Please make sure that /mnt/usbdrive directory exists and that you have
# the usb-storage support in your kernel. You must be root to run this.
#
# Usage: cardexport {start|stop}
@yakovsh
yakovsh / 2000_12_14-ie_title_changer.vbs
Created January 17, 2016 17:18
IE Titlebar Changer
'
' Based on column by Walter Mossberg <mossberg@wsj.com>. Check out his
' page at http://pctech.wsj.com
'
Dim strName
Dim WshShell
Dim strOldTitle
Dim strNewTitle
Dim intTemp
@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
@yakovsh
yakovsh / 2005_06_03-remove_vowels_from_hebrew.js
Last active May 23, 2022 19:43
Removing Vowels from Hebrew Unicode Text
/*
* One of the questions that recently came up is how to remove vowels from Hebrew characters in Unicode
* (or any other similar language). A quick look at Hebrew Unicode chart shows that the vowels are all
* located between 0x0591 (1425) and 0x05C7 (1479). With this and Javascript's charCodeAt function, it
* is trivial to strip them out with Javascript as follows
*
* Live demo is available here:
* https://jsfiddle.net/js0ge7gn/
*/