Skip to content

Instantly share code, notes, and snippets.

View atruskie's full-sized avatar
🤨

Anthony Truskinger atruskie

🤨
View GitHub Profile
@atruskie
atruskie / strip-prefix-bytes.ps1
Last active November 2, 2016 07:18
Dodgy ass (but pretty fast) powershell to strip a prefix of bytes from the front of the file, if the prefix is in the file
$pattern = "<html>`n"
ls *.wav | %{
echo ("Fixing" + $_.FullName)
if ([System.Text.Encoding]::ASCII.GetString((gc $_.FullName -Encoding Byte -TotalCount ($pattern.Length * 2))).StartsWith($pattern)) {
echo ("Reading" + $_.FullName)
$stream = $_.OpenRead()
$stream.Seek($pattern.Length, [System.IO.SeekOrigin]::Begin)
$destStream = [System.IO.File]::OpenWrite($_.FullName + ".trimmed.wav")
echo ("Writing" + $_.FullName)
$stream.CopyTo($destStream)
@atruskie
atruskie / find_folders_that_are_different.ps1
Created October 5, 2016 22:51
A one-liner I used to search through several hundred folders to find which ones did not have the same number of files/directories inside them.
ls . -Directory | % { $count = (ls $_ -Recurse).Count; $_ | Select *,@{Name="count"; Expression={$count} } } | Group-Object Count
@atruskie
atruskie / excpetions_test.rb
Created September 8, 2016 05:28
ruby exceptions
# This is a thought exercise.
# Write down the output for the following two invocations
# - `> me false`
# - `> me true`
def me(ensure_fail = false)
begin
puts "inside"
fail "inside error"
rescue => error
puts "rescue"
@atruskie
atruskie / simulate_script.sh
Created February 18, 2016 05:51
Simulate a long running script without the annoyance of setting up dependencies
#!/bin/bash
ANALYSIS_LENGTH=$(shuf -i 10-1000 -n 1)
echo -e "`date -u`: Analysis will take $ANALYSIS_LENGTH seconds"
sleep $ANALYSIS_LENGTH
echo "`date -u`: timeout completed"
ANALYSIS_SUCCESS=$[$RANDOM % 2]
echo -e "`date -u`: Analysis exit code: $ANALYSIS_SUCCESS"
exit $ANALYSIS_SUCCESS
@atruskie
atruskie / complex_postres_query_template.sql
Created February 15, 2016 01:17
A template/pattern (that I commonly use) for creating complex PostgreSQL queries
/*
* This is a template for creating very complex PostgreSQL queries.
* Large queries quickly become very unreadable because variables and
* other snippets of code cannot be refactored out. This template demos
* using variables within an anonymous PL/pgSQL block and returning the
* table result, WITHOUT requiring write permission to the database!
* The use of variables are trivial within this example.
*/
DO $$
@atruskie
atruskie / mock-bash.ps1
Last active February 28, 2017 06:03
Mock the bash export function in powershell
function Set-EnvironmentVariable($key, $value) {
Set-Content -Value $value -Path ("env:" + $key)
New-Variable -Scope Global -Name $key -Value $value -Force
}
function export($envVar) {
$split = $envVar.Trim().Split("=");
Set-EnvironmentVariable $split[0] $split[1]
}
@atruskie
atruskie / gist:db437b7afed669f8be87
Created December 4, 2014 22:20
Prof. Jemal Abawajy's definition of BigData
"A distributed framework for managing and processing massive volumes
of diverse and complex datasets possibly generated at different rates
from different sources to solve complex problems an discover new knowledge
in a scalable, efficient, and reliable manner" - Jemal Abawajy, BDCloud2014, 05/12/14
@atruskie
atruskie / VisualStudioAttacher.cs
Last active November 20, 2023 14:55
A class for programmatically attaching Visual Studio to debug a process. It can be used to automatically attach Visual Studio to your process. It can dynamically attach any solution to any process.
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AutoAttachVs.cs" company="QutEcoacoustics">
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group).
// </copyright>
// <summary>
// Example taken from this gist.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
#if DEBUG