Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Dimech AdamDimech

View GitHub Profile
@AdamDimech
AdamDimech / ImageJ_Loop_Through_Files_Headless.ijm
Created Oct 23, 2018
This generic script can be used in ImageJ "headless" mode to loop through files in a selected directory and do something to them.
View ImageJ_Loop_Through_Files_Headless.ijm
// Blank ImageJ Macro Script that loops through files in a directory
// Written by Adam Dimech
// https://code.adonline.id.au/imagej-batch-process-headless/
// Specify global variables
#@String input
#@String suffix
// Add trailing slashes
@AdamDimech
AdamDimech / database_tables_to_csv.sql
Created Dec 15, 2017
Convert tables in a SQL database to individual CSVs
View database_tables_to_csv.sql
/*
1. Log in to psql as a superuser
2. CHMOD target directory to 777
3. Execute via SELECT db_to_csv('/path/to/output');
4. Use complete file path.
*/
CREATE OR REPLACE FUNCTION db_to_csv(path TEXT) RETURNS void AS $$
declare
tables RECORD;
@AdamDimech
AdamDimech / ImageJ_Loop_Through_Files.ijm
Last active Mar 14, 2017
This generic script can be used in ImageJ to loop through files in a selected directory and do something to them.
View ImageJ_Loop_Through_Files.ijm
// Blank ImageJ Macro Script that loops through files in a directory
// Written by Adam Dimech
// Also available at https://gist.github.com/AdamDimech/cd3999f6fe9eddfa55c19d6fd3997bbc
// Specify global variables
input = getDirectory("Input Directory");
output = input; // Output images to the same directory as input (prevents second dialogue box, otherwise getDirectory("Output Directory"))
Dialog.create("File Type");
Dialog.addString("File Suffix: ", ".png", 5);
@AdamDimech
AdamDimech / Date_Time_Output.ijm
Created Mar 14, 2017
ImageJ Date and Time Output
View Date_Time_Output.ijm
// ImageJ Macro Code
// Output timestamp in format EEE dd MMM yyyy, hh:mm:ss
MonthNames = newArray("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
DayNames = newArray("Sun", "Mon","Tue","Wed","Thu","Fri","Sat");
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
print (DayNames[dayOfWeek], dayOfMonth, MonthNames[month], year + "," + hour + ":" + minute + ":" + second);
@AdamDimech
AdamDimech / UNC-from-file-path.ps1
Last active Mar 7, 2017
Select a file to determine its UNC path
View UNC-from-file-path.ps1
# UNC File Path Finder
# Written by Adam Dimech
# Based on https://code.adonline.id.au/unc-path-from-local-path-in-powershell/
# 1 March 2017
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
Multiselect = $false # Only one file can be chosen
InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"; #Opens in My Computer
Filter = 'All File Types|*.*' # Specified file types
@AdamDimech
AdamDimech / Local-Path-to-UNC-Path.ps1
Created Feb 22, 2017
Determine an UNC path from a local path (if applicable)
View Local-Path-to-UNC-Path.ps1
$Drive = $(get-location).Path
$x = new-object system.io.driveinfo($Drive)
$x.drivetype | Out-Null
If ($x.drivetype -eq "Fixed") {
Write-Host "`r`n`r`nSorry," $Drive "is not a networked drive."
}
Else {
$currentDirectory = Get-Location
$currentDrive = Split-Path -qualifier $currentDirectory.Path
@AdamDimech
AdamDimech / Local-to-UNC.ps1
Created Feb 22, 2017
Determine an UNC path from a local path
View Local-to-UNC.ps1
$currentDirectory = Get-Location
$currentDrive = Split-Path -qualifier $currentDirectory.Path
$logicalDisk = Gwmi Win32_LogicalDisk -filter "DriveType = 4 AND DeviceID = '$currentDrive'"
$unc = $currentDirectory.Path.Replace($currentDrive, $logicalDisk.ProviderName)
$output = "`r`n`r`nThe UNC Path for " + $currentDirectory + " is " + $unc
$output
@AdamDimech
AdamDimech / PDF_Grabber.ps1
Last active Aug 3, 2020
Download all PDF's from a web page via PowerShell
View PDF_Grabber.ps1
# More information at https://code.adonline.id.au/download-all-pdfs-from-a-web-page/
function Grab-PDFs {
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[System.Windows.Forms.Application]::EnableVisualStyles()
$browse = New-Object System.Windows.Forms.FolderBrowserDialog
$browse.SelectedPath = "C:\"
$browse.ShowNewFolderButton = $false
$browse.Description = "Select a directory"
@AdamDimech
AdamDimech / SFTP-Upload.ps1
Last active Aug 1, 2020
Upload files to an SFTP server via PowerShell
View SFTP-Upload.ps1
#Upload files to an SFTP server via PowerShell
#Requires WinSCP to be installed on local machine
# Load WinSCP .NET assembly
Add-Type -Path "C:\path\to\WinSCPnet.dll"
# Password prompt (not obscured)
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'Credentials'
@AdamDimech
AdamDimech / TidyUnzipper.pl
Created Nov 9, 2016
Perl Unzipping Utility
View TidyUnzipper.pl
#!/usr/bin/perl
use strict;
use warnings;
package TidyUnzipper;
use strict;
use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
use Exporter 'import';
You can’t perform that action at this time.