Skip to content

Instantly share code, notes, and snippets.

@peaeater
peaeater / dbt4sql-query.sql
Created August 22, 2016 20:42
Query to flatten records in an Inmagic DBTEXT for SQL internal database.
USE [name-of-db]
go
declare @cols AS NVARCHAR(MAX)
, @query AS NVARCHAR(MAX)
, @dechunkedRecords AS NVARCHAR(MAX)
, @where AS NVARCHAR(MAX);
set @where = ''
/*set @where = 'where _RecordID in (
@peaeater
peaeater / resurrector-schedule-task.xml
Created August 18, 2016 23:51
App Pool Resurrector scheduled task
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2015-08-05T09:01:28.0362962</Date>
<Author>ANDORNOT\peter-admin</Author>
<Description>Run if Application Event Id 1000, or Event Id 1309 (Unhandled exception). Wait 30-60s. Do not run if task already running.</Description>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
@peaeater
peaeater / andi.highlight.js
Created April 6, 2016 13:54
Extracts keywords and quoted phrases from a Solr query string, ignoring field phrases, ranges and query syntax characters. Surrounds terms found with a <b> tag. Native javascript, no dependencies.
andi.highlightTerms = [];
andi.highlight = function (el, terms) {
if (terms === null || terms.length === 0) return;
var term = terms.join('|');
var regex = new RegExp('\\b('+term+')\\b', 'gi');
if (el.innerHTML.match(regex) !== null) {
el.innerHTML = el.innerHTML.replace(regex, '<b>$1</b>');
el.classList === true ? el.classList.add('highlighted') : el.className += ' ' + 'highlighted';
}
@peaeater
peaeater / create-jetty-service.ps1
Last active October 10, 2016 06:23
Creates a Windows Service for Solr 5.3.1 with nssm.exe. Writes stdout and stderr to log. Put this Powershell script in the Solr bin folder with solr.cmd
<#
create-jetty-service.ps1
This script needs to be run once, to create the service.
Service name is mandatory.
Requires nssm.exe (Non-Sucking Service Manager https://nssm.cc).
The script assumes it is located in the Solr 5.x \bin folder with solr.cmd.
N.B. This operation requires elevated permissions. Either run script from Admin version of PS console, or allow to run when it asks.
-- Peter Tyrrell
@peaeater
peaeater / parsetsv.ps1
Created November 25, 2015 16:22
Takes a tab-delimited csv input file (tsv) produced by ner.ps1, and outputs a text file for each category found. A single category may be named, in which case a single output text file is created. If no output file is provided, results are written to the console instead.
<#
parse tsv
Categories: person, location, organization, misc, money, percent, date, time (depending on classifier used to produce the tsv)
Outfile: Results written to console if outfile not provided. If all categories, outfile is used as a filename template.
#>
param(
[Parameter(Mandatory=$true,Position=0)]
@peaeater
peaeater / ner.ps1
Last active November 25, 2015 16:17
Takes a text input file and by default, produces a tab-delimited csv output file. Output columns do not have a header row, but are always arranged the same way in three columns.
<#
Requires Stanford NER, Java 1.8+
formats = slashTags, inlineXML, xml, tsv, tabbedEntities
#>
param(
[Parameter(Mandatory=$true,Position=0)]
[string]$file,
[Parameter(Mandatory=$true,Position=1)]
@peaeater
peaeater / AppPoolResurrector.ps1
Last active July 30, 2018 00:28
Restarts named application pool if stopped, writes restart event to the Windows Application Event Log.
# restarts named app pool if stopped, writes restart event to the Application Event Log
# Peter Tyrrell, May 13 2013
param(
[string[]]$names = (,"ISAPI Webpublisher")
)
# If OS < Server 2008 R2, install Powershell snap-in for IIS and uncomment:
#Add-PSSnapin WebAdministration
@peaeater
peaeater / harvest2qbooks.ps1
Last active August 29, 2015 14:18
Convert Harvest timer CSV export to Quickbooks import format
<#
Peter Tyrrell, 2015
Convert Harvest time report to Quickbooks import format in Windows-1252.
#>
param (
[string]$indir = ".",
[string]$outdir = $indir
)
@peaeater
peaeater / solr-dih-transform-order-sample.xml
Created November 12, 2014 19:58
Sample Solr DIH entity demonstrating the order in which transformers act.
<entity
name="sample"
transformer="RegexTransformer,TemplateTransformer">
<field column="test_ignored" template="BLAH" />
<field column="test_ignored" sourceColName="id" regex="(.+)" />
<!--
test_ignored will equal 'BLAH' because TemplateTransformer acts last,
even though it is written first.
@peaeater
peaeater / raw-ocr.ps1
Created November 11, 2014 00:01
Converts PDFs to JPGs and OCRed text with imagemagick and tesseract.
<#
Processes raw source pdfs, producing per page: 1 txt, 1 hocr, 1 jpg.
Requires imagemagick w/ ghostscript, tesseract.
Subscripts: pdf2png.ps1, ocr.ps1, hocr.ps1, png2jpg.ps1
#>
param(
[string]$indir = ".",
[string]$outbase = $indir