Skip to content

Instantly share code, notes, and snippets.

L4rry Larry57

Block or report user

Report or block Larry57

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Larry57
Larry57 / LiangBarskyClippingHomogeneous.cs
Created Jan 12, 2020
Liang Barsky 3D clipping algorithm in homogeneous coordinates
View LiangBarskyClippingHomogeneous.cs
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 Nov 7, 2018
Awsh : undo manager
View awsh.cs
using System;
using System.Collections.Generic;
using System.Linq;
namespace OneFileTools {
/// <summary>
/// Awsh Undo helper
/// </summary>
@Larry57
Larry57 / MJPEGStream.cs
Last active Jun 1, 2018
*** Credits goes to andrew.kirillov@gmail.com *** MJPEG stream decoder, adapted from AForge.NET so the NewFrame event gives an byte[] back instead of a Bitmap.
View MJPEGStream.cs
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 Dec 21, 2016
My ludicrous and naive attempt to implement another Event hub for .NET : The Most Simple Possible Event Aggregator
View MSPEventAggregator
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 Sep 29, 2016
Create a ZedGraph PointList that use a object collection as a DataSource
View GenericPointList.cs
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 Feb 2, 2018
Simple, fast and stupid MJPEG decoder that works for real. Give this viewer a try : https://github.com/Larry57/SimpleMJPEGStreamViewer
View SimpleMJPEGDecoder.cs
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 / DoEvery.cs
Created Feb 17, 2016
Increment a counter for a lambda to run every n times
View DoEvery.cs
static class Do {
static ConcurrentDictionary<object, int> counters = new ConcurrentDictionary<object, int>();
public static void Every(int every, Action<int> action) {
var v = counters.AddOrUpdate(action, 0, (o, a) => a == int.MaxValue - int.MaxValue % every ? 0 : a + 1);
if(v % every == 0) {
action(v);
}
}
}
@Larry57
Larry57 / NameOf.cs
Last active Nov 19, 2015
Return the full path of a property name
View NameOf.cs
// 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 Oct 21, 2015
Get and Set properties values using a path with dots ("user.address.street"...)
View ObjectExtensions.cs
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 Sep 15, 2015
Calculate a zoom
View Zoom.cs
// 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));
You can’t perform that action at this time.