Skip to content

Instantly share code, notes, and snippets.

View yakovsh's full-sized avatar

Yakov Shafranovich yakovsh

View GitHub Profile
@yakovsh
yakovsh / 2009_02_11-xml2json.pl
Last active March 14, 2024 10:20
Converting JSON to XML with Perl
# 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);
@yakovsh
yakovsh / 2007_01_16-postgres.vb
Last active September 13, 2023 08:31
Using PostgreSQL on Windows with ADO and VB
' 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.
@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/
*/
@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 / 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_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