Skip to content

Instantly share code, notes, and snippets.

@JPaulDuncan
JPaulDuncan / InteractiveStars.tsx
Created September 1, 2025 14:14
Express+Typescript: Accessible, reusable 1–5 interactive star rating component
import React, { useMemo, useRef, useState } from "react";
import { Star } from "lucide-react";
export type InteractiveStarsProps = {
/** Current rating (0–max). Controlled. */
value: number;
/** Called when the user selects a rating. */
onChange: (val: number) => void | Promise<void>;
/** Number of stars to render (default 5). */
max?: number;
@JPaulDuncan
JPaulDuncan / broadcast.service.ts
Created October 21, 2021 16:06
Using BroadcastChannel - Typescript
import {EventEmitter, Injectable, OnDestroy} from "@angular/core";
/**
* Interface to ensure broadcast message uniformity.
*/
export interface IBroadcastMessage {
source: string;
target: string;
action: string;
payload: any;
@JPaulDuncan
JPaulDuncan / digitOnly.directive.ts
Created September 8, 2021 17:16
Angular Directive: Digits Only
import { Directive, ElementRef, HostListener, Input } from "@angular/core";
/**
* Ensures the associated element only allows digits to be entered.
* Allows for editing and in-element navigation.
*
* Usage: digitOnly allowSpaces="false"
*/
@Directive({
selector: "[digitOnly]"
@JPaulDuncan
JPaulDuncan / MailImportService.cs
Created December 12, 2017 17:48
Microsoft Exchange Web Services (EWS) Connecting, filtering, attachment downloading, and archiving.
using log4net;
using Microsoft.Exchange.WebServices.Data;
using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.ServiceProcess;
using System.Timers;
@JPaulDuncan
JPaulDuncan / jquery.ajax.working.js
Last active February 8, 2017 21:04
Notify a user that an ajax action is happening and prevent clicks. JQuery
/*
* Throws up a notification to tell the end-user a
* server call (ajax) is happening and prevents them
* from clicking elsewhere on the screen while it's
* working.
* USAGE: $.ajaxWorking();
*/
; (function ($) {
$.extend({
@JPaulDuncan
JPaulDuncan / validation-vin.js
Last active March 2, 2023 21:37
VIN Validation (Vehicle Identification Number)
function validateVin(vin) {
if (vin == "11111111111111111") { return false; }
if (!vin.match("^([0-9a-hj-npr-zA-HJ-NPR-Z]{10,17})+$")) { return false;}
var letters = [{ k: "A", v: 1 }, { k: "B", v: 2 }, { k: "C", v: 3 },
{ k: "D", v: 4 }, { k: "E", v: 5 }, { k: "F", v: 6 }, { k: "G", v: 7 },
{ k: "H", v: 8 }, { k: "J", v: 1 }, { k: "K", v: 2 }, { k: "L", v: 3 },
{ k: "M", v: 4 }, { k: "N", v: 5 }, { k: "P", v: 7 }, { k: "R", v: 9 },
{ k: "S", v: 2 }, { k: "T", v: 3 }, { k: "U", v: 4 }, { k: "V", v: 5 },
{ k: "W", v: 6 }, { k: "X", v: 7 }, { k: "Y", v: 8 }, { k: "Z", v: 9 }];
var weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2];
@JPaulDuncan
JPaulDuncan / infobox.js
Created February 3, 2016 14:56 — forked from wbotelhos/infobox.js
InfoBox
/**
* @name InfoBox
* @version 1.1.11 [January 9, 2012]
* @author Gary Little (inspired by proof-of-concept code from Pamela Fox of Google)
* @copyright Copyright 2010 Gary Little [gary at luxcentral.com]
* @fileoverview InfoBox extends the Google Maps JavaScript API V3 <tt>OverlayView</tt> class.
* <p>
* An InfoBox behaves like a <tt>google.maps.InfoWindow</tt>, but it supports several
* additional properties for advanced styling. An InfoBox can also be used as a map label.
* <p>
@JPaulDuncan
JPaulDuncan / EmptyGUIDConstraint
Last active August 29, 2015 14:21
Create a SQL Server Constraint to check for Empty UniqueIdentifier (GUID)
ALTER TABLE MyTable WITH CHECK ADD CONSTRAINT [CK_MyTable_MyId_NotEmpty] CHECK (MyId<>CAST(0x0 AS UNIQUEIDENTIFIER))
GO
@JPaulDuncan
JPaulDuncan / PrettyRelativeDateString
Last active December 14, 2015 16:39
Generates a date description relative the current date.
public static string ToRelativeDateString(this DateTime date)
{
return DateTimeExtensions.GetRelativeDateValue(date, DateTime.Now);
}
public static string ToRelativeDateStringUtc(this DateTime date)
{
return DateTimeExtensions.GetRelativeDateValue(date, DateTime.UtcNow);
}
private static string GetRelativeDateValue(DateTime date, DateTime comparedTo)
{