Skip to content

Instantly share code, notes, and snippets.

@peaeater
peaeater / Global.asax.cs
Created May 8, 2020
Castle Windsor and Web API 2 with ASP.NET MVC
View Global.asax.cs
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using Andi.MVC.Core;
using Andi.MVC.Core.Infrastructure.Globalization;
namespace Andi.MVC.Web
{
public class MvcApplication : System.Web.HttpApplication
{
@peaeater
peaeater / MediaApiController.cs
Created May 8, 2020
Web API 2 media controller that handles partial content requests
View MediaApiController.cs
public class MediaApiController : ApiController
{
public HttpResponseMessage Get(string filepath)
{
var path = HostingEnvironment.MapPath($"~/media/{filepath}") ?? string.Empty;
var mediaType = MediaTypeHeaderValue.Parse(MimeMapping.GetMimeMapping(filepath));
FileStream stream;
try
@peaeater
peaeater / helper.logging.ps1
Last active Apr 24, 2020
Log Helper writes to Event Log, console host or file depending on log source.
View helper.logging.ps1
<#
Logging functions.
#>
function logError([string]$logsrc, [string]$msg) {
if ([String]::IsNullOrWhiteSpace($logsrc)) {
write-log -msg $msg -level "ERROR"
}
elseif (@(".txt", ".log").Contains([System.IO.Path]::GetExtension($logsrc)) -eq $true) {
write-log -msg $msg -level "ERROR" -file $logsrc
@peaeater
peaeater / zipline.ps1
Last active Jun 22, 2020
Zip textbases with System.IO.Compression
View zipline.ps1
<#
Zip up textbase files in preparation for FTP sync to Andornot.
Peter Tyrrell, ptyrrell@andornot.com
-textbases c:\path\to\accessions.tba, c:\path\to\descriptions.tba
-out c:\path\to\destination
#>
param (
[string[]] $textbases,
@peaeater
peaeater / archive-project.ps1
Created Oct 31, 2019
Archive an Andi project
View archive-project.ps1
param (
[Parameter(Mandatory = $true)]
[string]$in,
[string]$out = "d:\dev-archive"
)
$extract_output_dir = "$in\extract\extracted\output\*"
remove-item $extract_output_dir -Recurse
Write-Host "Removed $extract_output_dir"
@peaeater
peaeater / sitemap.ps1
Created May 30, 2018
Creates sitemap index with attendant sitemaps from a Solr query.
View sitemap.ps1
<#
Create sitemap index with attendant sitemaps from a Solr query.
A new sitemap is created every 50,000 rows.
#>
param (
[string]$ChangeFrequency = "weekly",
[string]$IndexBaseUrl = "http://andi.andornot.com/",
[string]$Logsrc = "Andi Solr Update",
[string]$OutDir = ".\",
@peaeater
peaeater / optimize-pdf.ps1
Created May 25, 2018
Downsamples PDFs with ghostscript.
View optimize-pdf.ps1
<#
Downsample PDF and convert to gray if necessary.
Requires Ghostscript (gswin64c).
#>
param (
[string]$indir,
[string]$outdir = $indir,
[string]$gs = "gswin64c",
[string]$dpi = "150"
@peaeater
peaeater / logger.ps1
Created Mar 26, 2018 — forked from barsv/logger.ps1
Logging in powershell with log rotation
View logger.ps1
# all logging settins are here on top
$logFile = "log-$(gc env:computername).log"
$logLevel = "DEBUG" # ("DEBUG","INFO","WARN","ERROR","FATAL")
$logSize = 1mb # 30kb
$logCount = 10
# end of settings
function Write-Log-Line ($line) {
Add-Content $logFile -Value $Line
Write-Host $Line
@peaeater
peaeater / cd2mp3.ps1
Last active Mar 7, 2018
Powershell script that uses VLC to rip a CD audio track.
View cd2mp3.ps1
<#
Rip Audio CD to mp3 files with VLC.
#>
param (
[string]$vlc = "c:\program files\videolan\vlc\vlc.exe",
[string]$cddrive = "E:",
[int]$track = 0
)
@peaeater
peaeater / rip-cd.bat
Created Mar 7, 2018
Windows batch file that uses VLC to rip an audio CD
View rip-cd.bat
@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
SET /a x=0
FOR /R E:\ %%G IN (*.cda) DO (CALL :SUB_VLC "%%G")
GOTO :eof
:SUB_VLC
You can’t perform that action at this time.