Skip to content

Instantly share code, notes, and snippets.

View dg1an3's full-sized avatar
🧩
putting together the pieces

Derek dg1an3

🧩
putting together the pieces
View GitHub Profile
@dg1an3
dg1an3 / histo.cs
Created February 24, 2018 23:35
C# Image Histogram
// for a 2D array of pixels with some pixel type
var pixels = new TPixel[100,100];
// turn into a sequence
var pixelSequence = pixels.Cast<TPixelType>();
// group the sequence and turn to a dictionary, with pixel values as key and bin count as value
var histo = pixelSequence.GroupBy(px => px).ToDictionary(grp => grp.Key, grp => grp.Count());
@dg1an3
dg1an3 / AsciiPixels.fsx
Last active December 20, 2018 20:48
this is a lofi representation of images for experimenting in F#
#load "FsSampleImage.fsx"
open System.Collections.Generic
open FsSampleImage
let rows<'T> (samples: Map<Index,'T>) =
samples // extracts rows of samples from the "image" Map
|> Seq.sortBy (fun samp -> samp.Key.x)
|> Seq.groupBy (fun samp -> samp.Key.y)
|> Seq.map snd
@dg1an3
dg1an3 / MprGenerator.cs
Created July 3, 2018 19:29
Quick and dirty MPR generation from a 3D volume array
public enum Orientation
{
Transverse,
Sagittal,
Coronal
}
public static class MprGenerator<TPixel>
{
// generates an MPR from a volume given an orientation
@dg1an3
dg1an3 / ComplexGeometry.cs
Last active July 3, 2018 19:35
Isocurve Generation via simple marching squares
/// <summary>
///
/// </summary>
public class ComplexGeometry : List<LineSegments>
{
// stores the dictionary
Dictionary<Point, LineSegments> _segments =
new Dictionary<Point, LineSegments>();
/// <summary>
@dg1an3
dg1an3 / Image.csx
Created October 26, 2018 16:12
csx-based image helpers
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
// width/height helpers
static int Width<TPixel>(this TPixel[,] pixels) => pixels.GetLength(0);
static int Height<TPixel>(this TPixel[,] pixels) => pixels.GetLength(1);
// range helper
@dg1an3
dg1an3 / allgit.bat
Created February 23, 2019 20:54
findstr for git repo urls
findstr /S "version" config
@dg1an3
dg1an3 / findinterfaces.bat
Created February 23, 2019 20:57
find public interfaces
findstr /S/R "public.interface" *.cs
@dg1an3
dg1an3 / CreateTypeForSvcInterface.cs
Last active April 8, 2019 20:52
generate a dynamic empty wcf interface, given a name and namespace
string source = string.Format(@"
using System.ServiceModel;
namespace CreateTypeForSvcNamespace
{{
[ServiceContract(Namespace=""{0}"",Name=""{1}"")]
public interface {1} {{ }}
}}", ns, name);
var asmName = Path.GetRandomFileName();
var compilation = CSharpCompilation.Create(asmName,
@dg1an3
dg1an3 / ballot.sol
Created October 24, 2019 21:41
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.17+commit.bdeb9e52.js&optimize=false&gist=
pragma solidity ^0.4.17;
contract Contract {
string ipfsHash;
function setHash(string x) public {
ipfsHash = x;
}
function getHash() public view returns (string x) {
return ipfsHash;
}
}
@dg1an3
dg1an3 / ballot.sol
Created October 25, 2019 14:56
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.12+commit.7709ece9.js&optimize=false&gist=
pragma solidity ^0.5.12;
contract PhotoContestContract {
bytes32 _name;
address _owner;
bytes32[] _ipfsPhotoHashes;
address payable[] _submissionAddresses;
constructor(bytes32 name) public {
_owner = msg.sender;
_name = name;