Skip to content

Instantly share code, notes, and snippets.

View rudiv's full-sized avatar

Rudi Visser rudiv

View GitHub Profile
@rudiv
rudiv / generate_date.sql
Created December 13, 2011 12:06
Generate Date Table SQL Server
-- This will insert X years worth of data into a Date table. All fields are INT apart from DayName and DateTime (NVARCHAR(10) and DATE respectively)
-- Update 19/12 now uses ISO Week Number
-- Define start (base) and end dates
DECLARE @basedate DATETIME = '20111101', @enddate DATETIME = '20150101';
DECLARE @days INT = 0, @date DATETIME = '20110101', @maxdays INT = DATEDIFF(dd, @basedate, @enddate);
WHILE @days <= @maxdays
BEGIN
SET @date = DATEADD(dd, @days, @basedate);
@rudiv
rudiv / ValuesFromExtension.cs
Last active November 25, 2015 11:40
Copy values from one object to another with inclusion/exclusion list
using System.Linq;
namespace Cedita
{
public static class ModelExtensions
{
/// <summary>
/// Type-safe value copy from one object instance to another.
/// </summary>
/// <example>
@rudiv
rudiv / Program.cs
Created April 21, 2017 09:16
EF Core .Include being ignored (no logged warning as expected if EF Core detects it)
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace EFIncludeQueryable
{
public class TestEntityA
{
public int Id { get; set; }
public int TestEntityBId { get; set; }
public TestEntityB TestEntityB { get; set; }
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.sendgrid.net" userName="u@d" password="p" />
</smtp>
</mailSettings>
</system.net>
@rudiv
rudiv / sctest.console.cs
Last active May 10, 2018 09:11
string comparison tests
/*
Faster (probably due to no debugging attached by roslyn/linqpad), but same results overall
ICIC - 2.0579534
ToLower - 3.2817216
ToUpper - 3.2320578
ToLowerInvariant - 2.7057271
ToUpperInvariant - 2.7467674
*/
using System;
@rudiv
rudiv / RichTextEditor.svelte
Created November 17, 2024 20:48
shadcn-svelte tiptap Svelte 5 Rich Text Editor
<script lang="ts">
import { onMount, onDestroy } from "svelte";
import { Editor, type Extensions } from "@tiptap/core";
import StarterKit from "@tiptap/starter-kit";
import Underline from "@tiptap/extension-underline";
import CharacterCount from "@tiptap/extension-character-count";
import { debounce } from "$lib/utils";
import { Toggle } from "$lib/components/ui/toggle";
import IconBold from "@tabler/icons-svelte/icons/bold";
import IconItalic from "@tabler/icons-svelte/icons/italic";
@rudiv
rudiv / +page.server.ts
Last active November 24, 2024 21:06
.NET Aspire & SvelteKit OpenTelemetry (OTEL) / Traces
// /src/routes/**/+[page|layout].server.ts
import { skTracer } from "$lib/server/telemetry";
export async function load(event) {
const span = skTracer.startSpan("some-trace");
// Do something here, if you call fetch() it will be traced automatically so not needed
span.end();
return ...
@rudiv
rudiv / Program.cs
Created November 28, 2024 19:26
LightEndpoints
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKeyedSingleton<Counter>("sng");
builder.Services.AddKeyedScoped<Counter>("scp");
builder.Services.AddScoped<EndpointAsAClass>();
builder.Services.AddScoped<EndpointWithARequest>();
var app = builder.Build();
app.MapEndpoint<EndpointAsAClass>("/");
@rudiv
rudiv / BlueSkyComments.svelte
Last active December 2, 2024 10:22 — forked from emilyliu7321/bluesky-comments.tsx
Integrate Bluesky replies as your blog's comment section in Svelte
<script lang="ts" module>
import { AppBskyFeedDefs, AppBskyFeedPost, type AppBskyFeedGetPostThread } from "@atproto/api";
import type { ThreadViewPost } from "@atproto/api/dist/client/types/app/bsky/feed/defs";
export type CommentsProps = {
did: string;
threadId: string;
};
export type Reply = {
post: {