Skip to content

Instantly share code, notes, and snippets.

View Larry57's full-sized avatar

L4rry Larry57

View GitHub Profile
@Larry57
Larry57 / LiangBarskyClippingHomogeneous.cs
Created January 12, 2020 21:14
Liang Barsky 3D clipping algorithm in homogeneous coordinates
using System;
using System.Numerics;
namespace Clipping {
// https://fr.mathworks.com/matlabcentral/fileexchange/51550-3d-and-2d-homogeneous-space-line-clipping-using-liang-barsky-algorithm
public class LiangBarskyClippingHomogeneous {
float _t0;
float _t1;
@Larry57
Larry57 / awsh.cs
Created November 7, 2018 10:45
Awsh : undo manager
using System;
using System.Collections.Generic;
using System.Linq;
namespace OneFileTools {
/// <summary>
/// Awsh Undo helper
/// </summary>
@Larry57
Larry57 / MJPEGStream.cs
Last active June 1, 2018 19:06
*** Credits goes to [email protected] *** MJPEG stream decoder, adapted from AForge.NET so the NewFrame event gives an byte[] back instead of a Bitmap.
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
// AForge Video Library
// AForge.NET framework
//
// Copyright © Andrew Kirillov, 2007-2008
@Larry57
Larry57 / MSPEventAggregator
Last active December 21, 2016 11:21
My ludicrous and naive attempt to implement another Event hub for .NET : The Most Simple Possible Event Aggregator
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
namespace MSPEventAggregator {
void sample_usage() {
var hub = new MessageHub();
@Larry57
Larry57 / GenericPointList.cs
Created September 29, 2016 08:49
Create a ZedGraph PointList that use a object collection as a DataSource
public class GenericPointList<T> : IPointList {
List<T> innerList;
Func<T, double> ySelector;
Func<T, double> xSelector;
public GenericPointList(List<T> list, Func<T, double> xSelector, Func<T, double> ySelector) {
innerList = list;
this.xSelector = xSelector;
this.ySelector = ySelector;
}
@Larry57
Larry57 / SimpleMJPEGDecoder.cs
Last active September 19, 2024 19:38
Simple, fast and stupid MJPEG decoder that works for real. Give this viewer a try : https://github.com/Larry57/SimpleMJPEGStreamViewer
using System;
using System.Drawing;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SimpleMJPEGStreamViewer {
static class SimpleMJPEGDecoder {
@Larry57
Larry57 / NameOf.cs
Last active November 19, 2015 09:57
Return the full path of a property name
// Inspired by http://stackoverflow.com/q/301809/24472
public static string Property<TProp>(Expression<Func<T, TProp>> expression)
{
var s = expression.Body.ToString();
var p = s.Remove(0, s.IndexOf('.') + 1);
return p;
}
// Example:
@Larry57
Larry57 / ObjectExtensions.cs
Last active October 21, 2015 06:03
Get and Set properties values using a path with dots ("user.address.street"...)
using System.Reflection;
namespace System
{
internal static class ObjectExtensions
{
public static PropertyInfo GetPropertyInfo(this Type type, string name)
{
string[] bits = name.Split('.');
for (int i = 0; i < bits.Length - 1; i++)
@Larry57
Larry57 / Zoom.cs
Created September 15, 2015 10:26
Calculate a zoom
// sourceSize = source control size
// targetSize = target control size
// center of the zoom
// zoom radius
static Rectangle Zoom(Size sourceSize, Size targetSize, Point center, int radius)
{
var f = Math.Min((double)targetSize.Width / ((double)radius * 2d), (double)targetSize.Height / ((double)radius * 2d));
var loc = new Point((int)((-center.X + radius) * f), (int)((-center.Y + radius) * f));
@Larry57
Larry57 / AssemblyResolver.cs
Created January 21, 2015 15:45
Hook an AppDomain to a generic assembly resolver that accepts to several folders
using System.IO;
using System.Linq;
using System.Reflection;
namespace System
{
public static class AssemblyResolver
{
internal static void Hook(params string[] folders)
{