Skip to content

Instantly share code, notes, and snippets.

View atruskie's full-sized avatar
🤨

Anthony Truskinger atruskie

🤨
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / Contract.cs
Last active May 14, 2017 12:24
A dummy implementation of CodeContracts designed to be a signature-wise drop in replacement for common use cases
/// MIT License
/// Copyright (c) 2017 Anthony Truskinger
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
@atruskie
atruskie / README.md
Created April 10, 2019 07:06
Purposely corrupt a file for testing reasons (on Unix)

I'm testing file transfer methods (particularly to a SFTP remote).

In particular FileZilla does not detect corrupted files.

Use the above script to corrupt a remote file as a test.

If you are transferring files with rclone (https://rclone.org/) using the --checksums argument it will detect the fault and re-transfer the corrupt file.

@atruskie
atruskie / gist:91c299114038254cb88eb52f19e49352
Created April 11, 2019 11:43
Chocolatey Packages Statuses (Test)
empty
@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 $$