Skip to content

Instantly share code, notes, and snippets.

@IanMercer
IanMercer / SampleUDPReceiver.cs
Created November 19, 2020 20:40
Sample UDP Receiver to listen for decoded Bluetooth messages from PI-SNIFFER
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace UDPSample
{
@IanMercer
IanMercer / rc.local
Last active November 18, 2022 04:31
Automatic hostnames for Raspberry Pi instead of all 'raspberrypi'
# If you have many Raspberry Pis that you want to setup from a common image,
# add this to `/etc/rc.local` before you create the image, but do not run it.
# On first-run it will change the name from `raspberrypi` to `crowd-XXXXXX` where XXXXXX
# is the serial number of the Raspberry Pi. (Change 'crowd' in the line below.)
MAC="crowd-""$(grep 'Serial' /proc/cpuinfo | sed 's/^Serial.*000\([1-9a-f][0-9a-f]*\)$/\1/')"
CURRENT_HOSTNAME=$(cat /proc/sys/kernel/hostname)
if [ $CURRENT_HOSTNAME != $MAC ]
@IanMercer
IanMercer / SyslogService.cs
Created April 26, 2020 21:36
Syslog service for dotnet to monitor WIFI and Switch connections and DHCP Requests
/*
This example Syslog service receives Syslog messages over UDP and publishes them internally using Rx
to an observable stream `Messages`.
If you point all your Ubiquity (TPLink or other) SysLog messages to a device running this code listening on
port 514 you can parse the messages and:
1) Determine which access point each cell phone is connected to.
2) Generate an alert every time a new device connects to your network.
3) Track guests by creating a 'honeypot' SSID like "Google Starbucks" that catches most visitors with Wifi on.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Dynamic;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using ImpromptuInterface;
using log4net;
using System.Collections.Concurrent;
using System.Diagnostics;
using System;
using System.Collections;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.IdGenerators;
@IanMercer
IanMercer / JsonPatches.cs
Created July 5, 2016 21:17
JSONPatch - a simple, crude implementation of calculating and applying patches to Json objects
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Abodit
{
public class JPatch
{
public string op { get; set; } // add, remove, replace
@IanMercer
IanMercer / Edge.cs
Last active April 12, 2018 06:43
A simple in-memory graph
using System.Diagnostics;
namespace AboditUnits.Graph
{
public partial class Graph<TNode, TRelation>
{
/// <summary>
/// A relationship between two objects
/// </summary>
[DebuggerDisplay("{Start} -- {Predicate} --> {End}")]
@IanMercer
IanMercer / ConstraintSolverSample,cs
Last active November 18, 2015 03:55
Sample using Constraint Solver to solve a student to workshop allocation problem. I made this to explore csp.net. Each student picks workshops they want to attend, each workshop has a limited size, each workshop runs four times in different time slots.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Csp;
using Csp.Constraints;
using NUnit.Framework;
namespace TestConstraintSolver
{
@IanMercer
IanMercer / SlackbotResponder.cs
Created October 2, 2015 17:36
A sample Slackbot responder using Margiebot and AboditNLP
using System;
using System.Collections.Concurrent;
using AboditNLP;
using log4net;
using MargieBot.Models;
using MargieBot.Responders;
using Services;
namespace NLPService
{