Skip to content

Instantly share code, notes, and snippets.

View DevJohnC's full-sized avatar

John Carruthers DevJohnC

View GitHub Profile
@DevJohnC
DevJohnC / MemoryRef.cs
Created March 2, 2024 03:24
DotProduct operation using SIMD
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace VectorSearch.Memory;
public readonly ref struct MemoryRef<T>
{
private readonly ref T _value;
public MemoryRef(ref T value)
// a webservice
public class MyWebService : Service
{
private IMyService _myService;
public MyWebService(IMyService myService)
{
_myService = myService;
}
public ref struct ParsedString
{
private readonly ReadOnlySpan<byte> _valueSpan;
private readonly Encoding _encoding;
private readonly string _value;
public bool IsDeferred { get; }
/// <summary>
/// Deferred reading ctor.
public class ObservableCollectionView<T> : IReadOnlyCollection<T>, INotifyCollectionChanged, IDisposable
{
private readonly ObservableCollection<T> _sourceCollection;
private List<T> _localCollection = new List<T>();
public int Count => _localCollection.Count;
public event NotifyCollectionChangedEventHandler CollectionChanged;
public bool IsOrdered => OrderComparer != null;
public static IEntitySelectQueryBuilder<TEntity> AndWhere<TEntity>(this IEntitySelectQueryBuilder<TEntity> builder, ISchemaField<TEntity> schemaField, ComparisonOperator @operator, TEntity entity)
where TEntity : class => builder.AndWhere<IEntitySelectQueryBuilder<TEntity>, TEntity>(schemaField, @operator, entity);
public static IEntitySelectQueryBuilder<TEntity> AndWhere<TEntity, TValue>(this IEntitySelectQueryBuilder<TEntity> builder, ISchemaField<TEntity> schemaField, ComparisonOperator @operator, TValue value)
where TEntity : class => builder.AndWhere<IEntitySelectQueryBuilder<TEntity>, TEntity, TValue>(schemaField, @operator, value);
public static class BigEndianBitConverter
{
public static UInt16 ToUInt16(byte[] value, int startIndex)
{
return (ushort)(
value[startIndex + 1] |
value[startIndex] << 8
);
}
public static UInt16 ToUInt16(byte[] value, int startIndex)
{
return (ushort)(
value[startIndex + 1] +
(value[startIndex] * 256)
);
}
//
// Author: John Carruthers (johnc@frag-labs.com)
//
// Copyright (C) 2014 John Carruthers
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
@DevJohnC
DevJohnC / Test.cs
Created November 13, 2014 06:55
IKVM Reflection test
/// <summary>
/// Tests that the ManifestReader isn't loading assemblies.
/// </summary>
[TestMethod]
public void ManifestReaderDoesntLoadAssemblies()
{
var didFail = false;
AppDomain.CurrentDomain.AssemblyLoad += (sender, args) =>
{
if (args.LoadedAssembly.FullName.IndexOf("SimplePlugin") != -1)
@DevJohnC
DevJohnC / ManifestReader.cs
Created November 13, 2014 06:49
Reading a custom attribute from an assembly without loading it for execution.
//
// Author: John Carruthers (johnc@frag-labs.com)
//
// Copyright (C) 2014 John Carruthers
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to