Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / backup.ps1
Last active November 2, 2018 07:46
Backs up Inmagic textbases, both SQL Server db and textbase files. Logs most recent backup to a file.
<#
Backs up Inmagic textbases, both SQL Server db and relevant textbase files.
Peter Tyrrell, Andornot, www.andornot.com
sqlps dependency
If module sqlps does not exist, install from:
Microsoft SQL Server 2016 Feature Pack (https://www.microsoft.com/en-us/download/details.aspx?id=52676)
- SQLSysClrTypes.msi
- SharedManagementObjects.msi
- PowershellTools.msi
@peaeater
peaeater / unzip.ps1
Created October 24, 2016 21:40
Picks up zip files in a given folder and extracts the contents to a destination folder.
<#
Picks up zip files in a given folder and extracts the contents to a destination folder.
Peter Tyrrell, Andornot
#>
param(
[Parameter(Mandatory=$true,Position=0)]
[string]$in,
[Parameter(Mandatory=$false,Position=1)]
[string]$out = ".",
@peaeater
peaeater / clean-xml.ps1
Created October 26, 2016 18:12
Purges all illegal characters from XML files in provided folder. Recursive.
<#
Purges illegal XML characters from XML files in provided folder (and its subfolders).
Encodes out file as UTF8 without BOM.
Peter Tyrrell, Andornot
#>
param (
[string]$indir
)
@peaeater
peaeater / script-table.ps1
Last active October 31, 2016 22:39
Generates schema and data for a given SQL Server table to file.
<#
Generates a CREATE/INSERT script for a given SQL Server db table (e.g. Localizations)
Peter Tyrrell, Andornot, www.andornot.com
sqlps dependency
If module sqlps does not exist, install from:
Microsoft SQL Server 2016 Feature Pack (https://www.microsoft.com/en-us/download/details.aspx?id=52676)
- SQLSysClrTypes.msi
- SharedManagementObjects.msi
- PowershellTools.msi