Skip to content

Instantly share code, notes, and snippets.

@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));
}
/* 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;
--- a 2013-02-19 20:50:11.000000000 -0500
+++ b 2013-02-19 20:50:04.000000000 -0500
@@ -1 +1 @@
-Angela teaches a FOB the pinky-swear.
+Samples teaches a FOB the pinky-swear.
@eirikbakke
eirikbakke / gist:1074542
Created July 10, 2011 13:40
The DatabaseConnector class.
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public final class DatabaseConnector {
private static DatabaseConnector instance;
private static String useMySQL = null;
// Deployment note: Replace with a real server name.
@eirikbakke
eirikbakke / gist:1069036
Created July 7, 2011 07:19
The VideoDatabase Class
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
public class VideoDatabase {
public static List<Video> loadVideos() throws SQLException {
throw new UnsupportedOperationException("TODO: Implement when instructed.");
}
public static void insertVideo(Video v) throws SQLException {
@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;
@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: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:1059266
Created July 1, 2011 19:49
Example CSS file
/* Applies to the entire body of the HTML document (except where overridden by more specific
selectors). */
body {
margin: 25px;
background-color: rgb(240,240,240);
font-family: arial, sans-serif;
font-size: 14px;
}
/* Applies to all <h1>...</h1> elements. */
@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>