Skip to content

Instantly share code, notes, and snippets.

@idavis
idavis / Jagged
Last active January 9, 2018 16:04
Matrix Multiplication Benchmarks
namespace MatrixMultiplication
{
public static class Jagged
{
public static double[][] Multiply( int N )
{
var C = new double[N][];
var A = new double[N][];
var B = new double[N][];
Util.Initialize( N, A, B, C );
@idavis
idavis / gist:ca8f67b1c1ab2f5d6fe7ab6f889a314a
Created July 30, 2016 02:51
Crypto Errors with .NET Command Line Tools for OS X
idavis$ brew link openssl --force
Warning: Refusing to link: openssl
Linking keg-only OpenSSL means you may end up linking against the insecure,
deprecated system version while using the headers from the Homebrew version.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
=============================================================================
=============================================================================
@idavis
idavis / ReShape.ps1
Last active May 21, 2016 22:17
Implementing APL shape/rank (⍴/⍴⍴) functions in PowerShell. This is a rough first cut.
# APL Rank
filter ⍴⍴ {
param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$false)] $ω
)
process {
if($ω -is [system.array]){
$ω.rank
} else{
"⍬"
@idavis
idavis / gist:c16f117c0f99eb20c49f
Created June 12, 2015 16:46
PowerShell Module Security

I was playing around with dynamic module creation and figured out how to monkey patch modules.

I then thought about how PowerShell is a Last-In-Wins language, and tried replacing private methods.

This led to the "what if" moment of pulling [secure data out of a loaded module][]. In this case, the username and password of a credential set.

This seems like a security issue to me, or am I being over sensitive?

@idavis
idavis / Monkey.psd1
Last active August 29, 2015 14:22
Stealing Private Data
@{
# Script module or binary module file associated with this manifest.
RootModule = 'Monkey.psm1'
# Version number of this module.
ModuleVersion = '1.0'
# ID used to uniquely identify this module
GUID = '4d4390dc-a8ad-4bce-8d69-f53ccf8e4163'
@idavis
idavis / gist:293022f2ebe30f726673
Created June 9, 2015 18:28
Replacing the private functionality of loaded module
$module = New-Module -Name "monkey" -ScriptBlock {
function Get-Stuff {
return GetStuffPrivate
}
function GetStuffPrivate {
5
}
Export-ModuleMember Get-Stuff
}
Import-Module $module # you can also just use $module = Get-Module "someName"
function Split-Number {
param([string]$value)
$index = 0
while($index -lt $value.Length - 12) {
$value.Substring($index++, 13)
}
}
filter Evaluate-String {
$_.ToCharArray() | % { [int]::Parse($_) } | % {$total = 1} {$total *= $_} {$total}
function Enable-FusionLog {
param($logPath = "C:\Temp\Fusion")
if(!(Test-Path $logPath)) {
New-Item -ItemType Directory -Path $logPath
}
$fusionRoot = "HKLM:Software\Microsoft\Fusion"
function Set-FusionKey($name, $value, $type) {
if(!(Test-Path (Join-Path $fusionRoot $name))) {
(New-ItemProperty $fusionRoot -name $name -propertyType $type -ErrorAction Stop) | Out-Null
@idavis
idavis / gist:4192723
Created December 3, 2012 04:36
Fresh clone of FubuMvc, trying to build
> git clone [email protected]:idavis/fubumvc.git
Cloning into 'fubumvc'...
remote: Counting objects: 57191, done.
remote: Compressing objects: 100% (11208/11208), done.
remote: Total 57191 (delta 45719), reused 56278 (delta 44979)
Receiving objects: 100% (57191/57191), 61.02 MiB | 327 KiB/s, done.
Resolving deltas: 100% (45719/45719), done.
> cd .\fubumvc
[master]> ls
@idavis
idavis / Fizz-Buzz.ps1
Created November 21, 2012 23:15
FizzBuzz with PowerShell
filter Fizz-Buzz {
process {
$output = switch($_) {
{$_ % 3 -eq 0} {"Fizz"}
{$_ % 5 -eq 0} {"Buzz"}
default {$_}
}
$output -join ""
}
}