Skip to content

Instantly share code, notes, and snippets.

@davidfowl
davidfowl / AUsage.cs
Last active May 8, 2024 17:57
Header propagation HttpClientFactory middleware
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient("myclient");
// Global header propagation for any HttpClient that comes from HttpClientFactory
services.AddHeaderPropagation(options =>
{
options.HeaderNames.Add("Correlation-Id");
});
}
@cssquirrel
cssquirrel / FileUploadApiController.cs
Last active January 25, 2019 11:49
Using AngularJS API service and Umbraco API controller to permit users to upload files to the server
// Use whatever namespacing works for your project.
namespace YourSite.Web.Controllers.Api
{
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
@taivo
taivo / x-editable-radiolist
Last active March 2, 2019 09:23
radiolist support for x-editable
/**
List of radio buttons. Unlike checklist, value is stored internally as
scalar variable instead of array. Extends Checklist to reuse some code.
@class radiolist
@extends checklist
@final
@example
<a href="#" id="options" data-type="radiolist" data-pk="1" data-url="/post" data-title="Select options"></a>
<script>
@sitereactor
sitereactor / MediaEventHandler.cs
Last active July 12, 2023 02:33
Renaming an image when its uploaded to a property with Alias "umbracoFile", but before its saved. The name of the image will be changed to the name of the folder it resides in. This is using the Saving event in the MediaService in Umbraco.
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.IO;
using Umbraco.Core.Services;
namespace Startup
{
public class MediaEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
@neilkennedy
neilkennedy / buffer.js
Created January 10, 2014 10:21
Use JSTS buffer function with Leaflet.js by exporting / importing GeoJSON
function buffer(leafletGeometry, distance){
var reader, input, buffer, bufferGeoJSON;
reader = new jsts.io.GeoJSONReader();
input = reader.read(leafletGeometry.toGeoJSON());
buffer = input.geometry.buffer(distance);
bufferGeoJSON = new jsts.io.GeoJSONWriter().write(buffer);
return L.geoJson(bufferGeoJSON);