Skip to content

Instantly share code, notes, and snippets.

View klumsy's full-sized avatar

Karl Prosser klumsy

  • Pushpay Inc
  • Seattle , WA
View GitHub Profile
@klumsy
klumsy / capitalgainsslate.ps1
Created September 30, 2018 00:32
screwing around with capital gain optomization (only works with input data CSVs in specific format
Enum GainTerm {
Short
Long
}
Enum GainLoss {
Gain
Loss
}
@klumsy
klumsy / out-numbers.ps1
Last active September 16, 2018 06:01
Use Numbers on MacOS to display Powershell Data similar to Out-GridView
function Out-Numbers {
<#
.SYNOPSIS
Converts PowerShell Objects in CSV and opens in Numbers on macOS
.DESCRIPTION
Converts PowerShell Objects in CSV and opens in Numbers on macOS
TODO, maybe allow passing through a filename, an only using temp if not.
then allow certian parameters for export-csv like type, or no clobber or append..
.PARAMETER InputObject
Object to output
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class FirstdataE4Gateway < Gateway
# TransArmor support requires v11 or lower
self.test_url = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/v11'
self.live_url = 'https://api.globalgatewaye4.firstdata.com/transaction/v11'
TRANSACTIONS = {
sale: '00',
authorization: '01',
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class FirstdataE4V27Gateway < Gateway
self.test_url = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/v27'
self.live_url = 'https://api.globalgatewaye4.firstdata.com/transaction/v27'
TRANSACTIONS = {
sale: '00',
authorization: '01',
verify: '05',
@klumsy
klumsy / trycatch.cs
Last active December 21, 2015 09:48
try/catch while retraining strongly typed reference to an anonymous object.
public static class TryCatch
{
public static T Expression<T>(Func<T> lamda, Action<Exception> onException)
{
try
{
return lamda();
}
catch(Exception e)
{
@klumsy
klumsy / mustreturnsomething.cs
Last active December 21, 2015 04:48
Example of situations where the compiler is telling you that all code paths need a return value, however by the logic of your code, they all do.. so you end up having to write a return statement (or throw an exception) somewhere that will never go, just for it to compile
public static class Retry
{
public static IEnumerable<T1> Expression<T1>(
int retries,
Func<IEnumerable<T1>> action)
{
if (retries < 1) throw new Exception("must have 1 or more retries");
var iterations = 1;
while (iterations <= retries)
@klumsy
klumsy / Batch2.cs
Created August 5, 2013 20:00
my previous batch function wasn't always in parallel. This one seems to work properly and foces the parallelism plus gives you an option on the parallelism settings.
public static IEnumerable<T1> Batch2<T, T1>(
this IEnumerable<T> list,
int batchSize,
int maxParallelism,
Func<IEnumerable<T>, IEnumerable<T1>> action)
{
int i = 0;
return (
from item in list
group item by (int)i++ / batchSize
@klumsy
klumsy / batchextmethod.cs
Created June 19, 2013 00:12
C# extension method that can take an action that takes in a list.. so f(x) where x is a list, and break it up into batches of a certain size and do that action against each batch, either in serial or parallel.
public static IEnumerable<T1> Batch<T,T1>(
this IEnumerable<T> list,
int batchSize,
Func<IEnumerable<T>, IEnumerable<T1>> action,
bool processInParallel = false)
{
int i = 0;
var grpqry = from item in list
group item by (int)i++ / batchSize
into part
@klumsy
klumsy / booksofbible.rb
Created June 11, 2013 02:44
Code i wrote to that the dramatized audio bible (word of promise) i bought and downloaded as MP3 and rename the title to something that can be displayed as a whole on the Iphone , and also generate a CSV file of chapters and minutes for my curiousity.
require "rubygems"
require "mp3info"
require "csv"
chapterarray = []
#Dir.glob("/Users/klumsy/Downloads/bible/01_Genesis/*.mp3") do |f|
Dir.glob("/Users/klumsy/Downloads/bible/**/*.mp3") do |f|
Mp3Info.open(f) do |mp3info|
title = mp3info.tag.title
puts title
@klumsy
klumsy / PurgeRabbitQueues.ps1
Created December 5, 2014 22:16
Purge all messages in all RabbitMQ message queues.
$rabbitserver = 'localhost:15672'
$cred = Get-Credential
iwr -ContentType 'application/json' -Method Get -Credential $cred "http://${rabbitserver}/api/queues" | % {
ConvertFrom-Json $_.Content } | % { $_ } | ? { $_.messages -gt 0} | % {
iwr -method DELETE -Credential $cred -uri $("http://${rabbitserver}/api/queues/{0}/{1}" -f [System.Web.HttpUtility]::UrlEncode($_.vhost), $_.name)
}
iwr -Cr $cred "http://${rabbitserver}/api/queues" | % { ConvertFrom-Json $_.Content } | % { $_ } | % {iwr -me DELETE -Cr $cred $("http://${rabbitserver}/api/queues/{0}/{1}" -f [System.Web.HttpUtility]::UrlEncode($_.vhost), $_.name)}