Skip to content

Instantly share code, notes, and snippets.

@tombatron
tombatron / example.cs
Created April 21, 2023 19:58
Example Code
var vectorBytes = new byte[item.Features.Length * sizeof(float)];
Buffer.BlockCopy(item.Features, 0, vectorBytes, 0, vectorBytes.Length);
db.HashSet($"Order:{item.OrderNumber}", new []
{
new HashEntry("order_number", item.OrderNumber),
new HashEntry("quote", item.Quote),
new HashEntry("vectorized_order", vectorBytes)
});
@tombatron
tombatron / JSONPathExample.cs
Created April 30, 2022 17:57
Demonstration settings and getting JSON values within an array using JSONPath syntax with NReJSON.
// Make sure that the version of the RedisJson module that you're
// using is equal to or greater than version 20007. I'm using the
// following: redis/redis-stack-server:latest
using System.Text.Json;
using NReJSON;
using StackExchange.Redis;
// Let's define an example model instance to persist to Redis...
var example = new TestModel
@tombatron
tombatron / example.cs
Created September 1, 2021 22:43
Example of writing a JSON object and then updating a property via its JSONPath with a filter...
using System;
using System.Text.Json;
using System.Threading.Tasks;
using NReJSON;
using StackExchange.Redis;
namespace RedisJsonTest
{
class Program
{
@tombatron
tombatron / testing.cxx
Last active December 20, 2019 13:03
V8 Context Dispose Question
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include "include/libplatform/libplatform.h"
#include "include/v8.h"
#include "v8eval.h"
# File generated at : 14:25:02, Fri 22 Nov
# Converted Project : V8.Net-Proxy-x64.vcxproj
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
add_definitions(-D_MSC_PLATFORM_TOOLSET=200)
# TODO: Make a variable for holding the path to the V8 source.
# installed clang and set it as the default compiler
# installed sudo apt-get install libc++-dev
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.IO.Pipelines;
using System.Linq;
using System.Text;
namespace HtmlRemover
{
@tombatron
tombatron / MulticastExperiment.cs
Last active February 5, 2019 03:34
Just messing around with multicast sockets.
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Collections.ObjectModel;
using System.Threading;
namespace Prototype
{
public static class Program
# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf
# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
docker run -p 6379:6379 -v /Users/tombatron/docker/redis:/data -v /Users/tombatron/docker/redis/redis.conf:/usr/local/etc/redis/redis.conf --name redis redislabs/redismod /usr/local/etc/redis/redis.conf --dir /data
@tombatron
tombatron / GroupedDictionary.cs
Created July 15, 2017 13:36
GroupedDictionary
public class GroupedDictionary<TKey, TValue> : Dictionary<TKey, ICollection<TValue>>
{
private readonly Func<TValue, TKey> _groupingKeyExtractor;
public GroupedDictionary(IEnumerable<TValue> values, Expression<Func<TValue, TKey>> groupingKey)
{
_groupingKeyExtractor = groupingKey.Compile();
PopulateDictionary(values);
}