Skip to content

Instantly share code, notes, and snippets.

/* This file is based in part on:
* org.netbeans.editor.Utilities (with listed author Miloslav Metelka)
* The complete license headers for the original file can be found in the ExternalLicenses.txt
* file.
*
* This version by Eirik Bakke (ebakke@mit.edu).
*/
package com.sieuferd.upstream.localeditor;
import com.google.common.base.Preconditions;
@eirikbakke
eirikbakke / JackcessNegDate.java
Created June 10, 2015 18:22
Example Jackcess patch to handle negative dates
private double adjustNegativeDatesFromAccess(double value) {
double fractionalPart = value % 1.0; // Negative if value is negative.
double wholePart = value - fractionalPart;
return wholePart + Math.abs(fractionalPart);
}
// Simplified equivalent implementation (avoids touching positive dates).
private double adjustNegativeDatesFromAccess2(double value) {
return value >= 0.0 ? value : (value - 2.0 * (value % 1.0));
}
private static final ZoneId UTC_ZONEID = ZoneId.of("UTC");
public double toDateDouble(Object value) {
long time = toDateLong(value);
time += getToLocalTimeZoneOffset(time);
final LocalDateTime ldt =
LocalDateTime.ofInstant(Instant.ofEpochMilli(time), UTC_ZONEID);
final long datePart = ldt.toLocalDate().toEpochDay() * (long) MILLISECONDS_PER_DAY +
MILLIS_BETWEEN_EPOCH_AND_1900;
final long timePart = ldt.toLocalTime().toNanoOfDay() / 1000000L;
package com.sieuferd.harness;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.SystemFlavorMap;
import java.awt.datatransfer.Transferable;
import java.io.InputStream;
public final class FlavorMapBugExhibit {
@eirikbakke
eirikbakke / gist:1056064
Created June 30, 2011 11:40
Basic structure of an HTML file.
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<!-- Include a stylesheet called stylesheet.css . -->
<link href="stylesheet.css" rel="stylesheet" title="Normal" />
<title>The title of the page.</title>
</head>
<body>
<!-- The page's content goes here. -->
@eirikbakke
eirikbakke / gist:1056066
Created June 30, 2011 11:42
Basic structure of a Servlet.
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/* The relative URL that this servlet will be handling. For instance, if we are running
Tomcat locally with an Eclipse project called "SomeProject", then by specifying "/Main"
@eirikbakke
eirikbakke / gist:1056079
Created June 30, 2011 11:50
Basic structure of a JSP file that generates a HTML file.
<!-- Boilerplate. -->
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
version="2.0">
<jsp:directive.page
language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
<jsp:text><![CDATA[<!doctype html>]]></jsp:text>
<html>
<head>
@eirikbakke
eirikbakke / gist:1059502
Created July 1, 2011 22:05
Example of an HTML form
<!-- To submit form data back to the same page (and thus the same Servlet), use "#" for the
action. Otherwise specify a relative URL to a different page for the action. -->
<form action="#">
<label for="ageField" >Your age: </label>
<input type="text" name="ageParam" id="ageField" /><br/>
<label for="colorField">Favorite color:</label>
<input type="text" name="colorParam" id="colorField"/><br/>
<input type="submit" value="Click me to submit!"/>
</form>
@eirikbakke
eirikbakke / gist:1059621
Created July 2, 2011 00:18
Generating an empty iframe tag from JSP
<!-- Not like this: -->
<iframe width="560" height="349" src="http://www.youtube.com/embed/FaMTedT6P0I" />
<!-- Nor like this (JSP will just convert it to use a self-closing tag as above): -->
<iframe width="560" height="349" src="http://www.youtube.com/embed/FaMTedT6P0I"></iframe>
<!-- But like this (tell JSP to output the elements exactly like we wrote them): -->
<![CDATA[
<iframe width="560" height="349" src="http://www.youtube.com/embed/FaMTedT6P0I"></iframe>
]]>
@eirikbakke
eirikbakke / gist:1066999
Created July 6, 2011 10:53
Boilerplate for the DBManager class.
package org.meetproj.model;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;