Skip to content

Instantly share code, notes, and snippets.

@aembleton
aembleton / rename.bat
Created October 15, 2013 14:38
Renames files that have a name ending in 20131015-140115.csv to the current date in the format yyyyMMdd then a -, then the number already in the file name, incremented by 1. File ending in 20131015-140115.csv ran through this script on 1 January 2014 will have their ending renamed as 20130101-140116.csv
@echo off
setlocal enabledelayedexpansion
set FOLDER_PATH=.
set year=%date:~-4%
set month=%date:~3,2%
set day=%date:~0,2%
pushd %FOLDER_PATH%
for %%f in (*csv) do if %%f neq %~nx0 (
set "filename=%%~nf"
set "postfix=!filename:~-6!"
@aembleton
aembleton / build.info
Last active December 25, 2015 00:29
Builds a jar
#Sat, 12 Oct 2013 23:12:10 +0100
major=0
minor=1
build=3
@aembleton
aembleton / listFiles.scala
Created September 19, 2013 09:31
Gets a list of files in a given directory and all child directories
/**
* Gets a list of files in a given directory and all child directories
* @param f This is the File representing the root directory
* @return A list of File objects, each one representing a File inside f, either directly or in a sub-directory
*/
def listFiles(f: File): List[File] = f match{
case f if f.isDirectory => f.listFiles.toList.flatMap(listFiles(_))
case f if f.isFile => List(f)
case _ => Nil
}
@aembleton
aembleton / diskspace.sql
Created May 8, 2013 14:45
Calculates used disk space on Oracle
SELECT df.tablespace_name "Tablespace",
totalusedspace "Used MB",
(df.totalspace - tu.totalusedspace) "Free MB",
df.totalspace "Total MB",
ROUND(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) "Pct. Free"
FROM
(SELECT tablespace_name,
ROUND(SUM(bytes) / 1048576) TotalSpace
FROM dba_data_files
GROUP BY tablespace_name
@aembleton
aembleton / itext.java
Created May 8, 2013 11:28
Example of iText that repeats an image all over a page and draws a semi-transparent yellow line on top.
import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
package com.jandrewthompson;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
/**
@aembleton
aembleton / Frequency of email address domains
Created March 22, 2013 14:00
Find the frequency of email address domains from your email table.
select substring_index(value, '@',-1) as email, count(*) as frequency FROM emailTable where name="EmailAddress" group by email order by frequency desc;
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
package net.blerg.oracleToMysql.util;
import java.util.LinkedList;
import java.util.List;
public class PatternReplace {
public static String replace (String string, String pattern, String replacement, char wildcard, char escapeChar, boolean ignoreCase) {
//tokenise against the pattern
@aembleton
aembleton / InformationBox.java
Created August 29, 2012 14:30
Provides a way to produce an information box surrounded by a char such as *.
import java.util.LinkedList;
import java.util.List;
/**
* Provides a way to produce an information box surrounded by a char such as *. To use, add lines by calling {@link #add(String)} and then call {@link #getStringsInBox(char)} to get a String that can
* be put into a System.out.println call or used elsewhere that is formatted.
*
* @author Arthur Embleton
*
*/