Skip to content

Instantly share code, notes, and snippets.

View rudfoss's full-sized avatar

Thomas Haugland Rudfoss rudfoss

View GitHub Profile
@rudfoss
rudfoss / SanitySchema.ts
Last active August 28, 2021 14:14
A starter file of typescript types for Sanity CMS schema definitions. It is by no means complete, but covers most of the basic use cases I've run into.
import React from "react"
import { SanityDocument as SanityQueryDocument, SanityDocumentStub } from "@sanity/client"
/**
* A Sanity name string. Can only a-z A-Z 0-9 and underscore.
*/
export type SanityName = string
export interface SanitySelectorSet {
[key: string]: string
@rudfoss
rudfoss / ExtendedPropsComponent.tsx
Last active May 28, 2022 11:37
React functional component with extended props
import React from "react";
// This can be defined in some other file as well.
interface SharedProps {
active: boolean
title?: string
}
type MyProps = Omit<SharedProps, "title"> & {
specialTitle: string
@rudfoss
rudfoss / typescript.code-snippets
Created January 2, 2023 10:33
TypeScript code snippets
{
"React Component": {
"prefix": "react-component",
"description": "Creates a react function component without props",
"body": [
"import React from \"react\"",
"",
"export interface ${1:name}Props {",
"\t${0}",
"}",
@rudfoss
rudfoss / cross-stage-variables-azure-devops-yaml-pipeline.yml
Last active December 18, 2025 20:10
Cheat-sheet for setting and retrieving variables in Azure DevOps yaml pipelines across different steps, jobs and stages.
# Cheat-sheet for using dynamically defined variables between steps, jobs and stages in Azure DevOps Yaml Pipelines
# Documentation: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch
trigger: none
pr: none
stages:
- stage: DefineVarStage
jobs:
- job: DefineVarJob
@rudfoss
rudfoss / convertDataToCsvRows.ts
Created March 26, 2024 10:40
A small set of helper functions that convert raw data to CSV which in turn can be downloaded. Uses no libraries and escapes necessary characters.
const sanitizeCellValue = (value: unknown, cellSeparator: string): string => {
let valueString = String(value ?? "")
if (
valueString.includes(cellSeparator) ||
valueString.includes(" ") ||
valueString.includes('"') ||
valueString.includes("\n")
) {
valueString = valueString.replaceAll('"', '""')
valueString = `"${valueString}"`
@rudfoss
rudfoss / DotEnv.cs
Last active August 12, 2024 11:50
A very simple parser for loading .env files in a c# application. Has no external dependencies and supports basic references.
namespace DotEnv
{
public class DotEnv(ILogger<DotEnv> logger)
{
/// <summary>
/// Holds a set of all environment variables set from .env files. Listed if logLevel set do debug.
/// </summary>
private readonly IDictionary<string, string> _finalEnvironmentVariables = new Dictionary<string, string>();
private void LoadAndParse()