Skip to content

Instantly share code, notes, and snippets.

View chrcar01's full-sized avatar

Chris Carter chrcar01

View GitHub Profile
@RupertAvery
RupertAvery / Job.cs
Last active February 26, 2024 08:32
A wrapper class using Channels to asynchonously process a queue that can be added to at any time
public class Job
{
private static int lastId;
public int Id { get; private set; }
public int Duration { get; private set; }
public Job(int value)
{
Id = lastId + 1;
@sanme98
sanme98 / LINQPad-MinAPI.linq
Created November 28, 2021 10:43
LINQPad 7 Minimum APIs
<Query Kind="Program">
<NuGetReference>Microsoft.EntityFrameworkCore.InMemory</NuGetReference>
<NuGetReference>Swashbuckle.AspNetCore</NuGetReference>
<Namespace>Microsoft.AspNetCore.Builder</Namespace>
<Namespace>Microsoft.EntityFrameworkCore</Namespace>
<Namespace>Microsoft.Extensions.DependencyInjection</Namespace>
<Namespace>Microsoft.OpenApi.Models</Namespace>
<Namespace>Microsoft.AspNetCore.Http</Namespace>
<IncludeAspNet>true</IncludeAspNet>
<RuntimeVersion>6.0</RuntimeVersion>
@hyrmn
hyrmn / DapperExtensions.cs
Last active December 18, 2023 09:16
Extension methods for calling Dapper asynchronously with a Polly retry
public static class DapperExtensions
{
private static readonly IEnumerable<TimeSpan> RetryTimes = new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(2),
TimeSpan.FromSeconds(3)
};
private static readonly AsyncRetryPolicy RetryPolicy = Policy
@andriybuday
andriybuday / 0 - ServiceHost.cs
Last active April 16, 2024 15:58
Microsoft.Extensions.DependencyInjection with OWIN Self-Hosted WebAPI
// ...
using Microsoft.Owin.Hosting;
// ...
public class ServiceHost
{
private IDisposable server = null;
const string baseAddress = "https://*:443";
public void Start()
@cauerego
cauerego / IndexedDB101.js
Last active January 13, 2023 22:00 — forked from JamesMessinger/IndexedDB101.js
Very Simple IndexedDB Example
// quite untested, adapted from BigstickCarpet's gist, attempt to make it simpler to use
function openIndexedDB (fileindex) {
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
var openDB = indexedDB.open("MyDatabase", 1);
openDB.onupgradeneeded = function() {
var db = {}
@nozzlegear
nozzlegear / ValidateHeaderAntiForgeryToken.cs
Last active March 15, 2024 00:11
Validate an ASP.NET AntiForgeryToken sent in the request header
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
namespace MyNamespace.Controllers
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
@willurd
willurd / web-servers.md
Last active June 26, 2024 11:15
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@michiakig
michiakig / ants.clj
Created July 19, 2011 22:37
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world