Skip to content

Instantly share code, notes, and snippets.

View dlundy's full-sized avatar

David Lundy dlundy

  • Lettuce Box
  • San Diego
View GitHub Profile
@dlundy
dlundy / wkhtmltopdf.java
Last active December 4, 2018 07:48
Quickie Java pipe out to wkhtmltopdf to create a pdf from a string with html
public byte[] getPdf(String html) {
byte[] results = null;
try {
// For piping in and out, we need separate args for this for some reason
String[] command = {"/usr/local/bin/wkhtmltopdf", "-", "-"};
ProcessBuilder builder = new ProcessBuilder(command);
// this eats up stderr but prevents us from having to handle it ourselves
builder.redirectErrorStream(false);
Process process = builder.start();
@dlundy
dlundy / StringRenderableController.java
Last active August 29, 2015 14:08
A Spring controller that can render views to a string (useful for PDF generation, for instance)
public abstract class StringRenderableController
{
@Autowired
ViewResolver viewResolver;
protected String renderViewToString(Model model, HttpServletRequest request, HttpServletResponse httpServletResponse, final String viewName)
{
final StringWriter html = new StringWriter();
View renderView = new View()
{
@dlundy
dlundy / postgres_table_sizes.sql
Created September 30, 2014 22:53
get table sizes in postgres
SELECT
relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size"
FROM pg_catalog.pg_statio_user_tables
where relname like {{table_name}}
ORDER BY pg_total_relation_size(relid) DESC;
@dlundy
dlundy / gist:b8900f660646707e3d27
Last active August 29, 2015 14:02
modify windows timestamp in powershell
# get file as object
$a = Get-Item .\export.xlsx
# and then you can just set properties. wow
$a.LastWriteTime="5/1/2012 13:02"
$a.CreationTime="4/1/2012 12:22"
$a.LastAccessTime="5/13/2014 15:24:22"
@dlundy
dlundy / gist:8682463
Created January 29, 2014 05:41
sample alternate
<html>
<head>
<!-- load your javascript libs here with script tags -->
</head>
<body>
<!-- html goes here -->
<script type="text/javascript">
// timer code goes inside here, it should work because your DOM elements exist when this code is evaluated.
</script>
</body>
@dlundy
dlundy / gist:8682395
Last active January 4, 2016 21:39
sample
<html>
<head>
<!-- load your javascript libs here with script tags -->
<script type="text/javascript">
$(document).ready(function() {
// timer code goes inside here, it will be called when the page loads fully
});
</script>
</head>
<body>
@dlundy
dlundy / parse.rb
Last active December 30, 2015 02:09
Quick hack to parse Folkets Lexikon xml dump into word pairs to import into Anki
# http://folkets-lexikon.csc.kth.se/folkets/om.en.html
# http://folkets-lexikon.csc.kth.se/folkets/folkets_en_sv_public.xml
# http://folkets-lexikon.csc.kth.se/folkets/folkets_sv_en_public.xml
require "rexml/document"
require 'cgi'
file = File.new("folkets_en_sv_public.xml")
doc = REXML::Document.new file
@dlundy
dlundy / pom.xml
Created October 19, 2012 05:40
Sample Maven pom.xml using per-environment configuration and local repo
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycorp.project</groupId>
<artifactId>project</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Sample Maven Webapp</name>
<url>http://www.example.com</url>
<build>