Skip to content

Instantly share code, notes, and snippets.

View gordysc's full-sized avatar

Luke Gordon gordysc

View GitHub Profile
@gordysc
gordysc / ValidationFilter.cs
Last active September 25, 2024 01:30
C# Minimal API ValidationFilter w/ FluentValidations
using FluentValidation;
public sealed class ValidationFilter<T> : IEndpointFilter
where T : class
{
public async ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next)
{
if (context.Arguments.FirstOrDefault(x => x?.GetType() == typeof(T)) is not { } argument)
return Results.Problem($"Missing argument type. Expected to validate {typeof(T).Name}.");
@gordysc
gordysc / signedId.js
Last active November 26, 2022 10:36
Rails signed_id reimplemented in NodeJS
/*
* This was just a thought experiment of reimplementing the Rails signed_id's concept
* in NodeJS. All values below are examples and do not represent any real world data.
*
* This script might be useful for folks who need to support signed IDs that were
* generated by a Ruby on Rails application that is being ported to NodeJS.
*/
const { createHmac, pbkdf2Sync } = require("node:crypto");
@gordysc
gordysc / within_circle.rb
Last active November 12, 2020 04:32
Find first 10 points within a given radius of a lon/lat ordered by closest to furthest (Elasticsearch v7+)
def within_circle(lon:, lat:, distance:, unit:, direction: "asc")
{
query: {
bool: {
must: {
match_all: {}
},
filter: [
{
geo_distance: {
[
{
"name": "Approved 👍",
"description": "Looks Good To Me!",
"color": "88e87f"
},
{
"name": "Blocked ⛔️",
"description": "This Is Blocked By Something!",
"color": "fc2929"
class SlackWebhook
attr_accessor :webhook
def initialize(webhook)
@webhook = webhook
end
def send_message(text)
uri = URI(webhook)
@gordysc
gordysc / gist:cc158f33ca41329a720e7777aefa5604
Last active November 19, 2016 17:07
Verifying signed URL's w/ Hapi
// URL signature has following format:
// http://<uri>?timestamp=<timestamp>&signature=<signature>
const Boom = require('boom')
const crypto = require('crypto')
const algorithm = process.env.SIGNATURE_ALGORITHM || 'sha1'
const TIMESTAMP_RANGE = parseInt(process.env.TIMESTAMP_RANGE) || 5 * 60 * 1000
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i