Skip to content

Instantly share code, notes, and snippets.

@leoleozhu
leoleozhu / DownloadUtils.java
Last active January 11, 2022 10:57
Download file with HTTP resumable
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.apache.commons.io.IOUtils;
import java.io.*;
import java.net.URL;
@leoleozhu
leoleozhu / setjdk.bat
Created December 9, 2021 07:36 — forked from torutk/setjdk.bat
Setting oracle jdk path using registory for Windows command prompt
@echo off
:: ==========================================================
:: Windows(64bit) batch file tor set environment variables
:: JAVA_HOME and PATH for Oracle JDK or OpenJDK.
::
:: For Oracle JDK, search JDK installed path from Windows registory.
:: For OpenJDK, search JDK installed path from directory name under
:: OPENJDK_BASE directory specified in this batch file. (needs to
:: customize your configuration)
@leoleozhu
leoleozhu / ReusePage.java
Created August 5, 2021 10:49
Reuse page in PDF
@Test
public void testReusePage() throws Exception {
String original = resourceFile("PdfWithImage.pdf");
String destination = targetFile("image-reuse-ReusePage.pdf");
try (
PdfDocument input = new PdfDocument(new PdfReader(original));
PdfDocument output = new PdfDocument(new PdfWriter(destination))
) {
PdfPage page = input.getPage(1);
@leoleozhu
leoleozhu / GuessContentTypeTest.java
Created October 30, 2019 02:38
guess image content type from URL
public class GuessContentTypeTest extends TestCase {
@Test
public void testGuessFileTypeFromUrl() throws Exception {
String[] urls = {
// your image urls here
};
for(String s : urls) {
int pushbackLimit = 100;
@leoleozhu
leoleozhu / taopix-payment-icon.css
Created September 6, 2019 05:47
add payment icons for taopix checkout
div.paymentmethodlist>input[value="PAYPAL"] ~ label:after {
background-repeat: no-repeat;
background-image: url(/images/payments/paypal-640x188.png);
background-size: 48px 14px;
display: inline-block;
width: 48px;
height: 14px;
content: "";
margin-left: 20px;
@leoleozhu
leoleozhu / PdfGenerator.java
Created August 19, 2019 03:38
Draw transparent text with iText 7
class TextBox {
private UUID uuid;
private float x;
private float y;
private float width;
private float height;
@leoleozhu
leoleozhu / fonttools_fontinfo.py
Created August 16, 2019 14:41
Get FontFamily, Styles from a TTFont object (python fonttools lib)
class TTFontInfo(object):
bold_names = ("bold", "demibold", "demi-bold", "demi bold", "negreta", "demi",)
italic_names = ("italic", "cursiva", "oblique", "inclined",)
bold_italic_names = ("bolditalic", "bold-italic", "bold italic", "boldoblique", "bold-oblique",
"bold oblique", "demibold italic", "negreta cursiva", "demi oblique",)
@leoleozhu
leoleozhu / AffineTransformTests.java
Last active August 17, 2019 06:24
Affine Transform Example
package document.transform;
import com.itextpdf.kernel.geom.AffineTransform;
import com.itextpdf.kernel.geom.Point;
import junit.framework.TestCase;
import org.junit.Test;
public class AffineTransformTests extends TestCase {
VM=`docker-machine ls 2>/dev/null | sed -n 2p | awk '{print $1}'`
[ -z "$VM" ] && VM=default
@leoleozhu
leoleozhu / python-server.py
Created March 5, 2014 09:20
Python Simple HTTP Server
import os
import posixpath
import urllib
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
# modify this to add additional routes
ROUTES = (
# [url_prefix , directory_path],
['', 'E:\Dropbox\Other\python-server'], # empty string for the 'default' match