Skip to content

Instantly share code, notes, and snippets.

@DanDiplo
DanDiplo / BlockListCreatorService.cs
Last active July 26, 2024 05:58
Create Blocklist JSON programmatically in Umbraco
/// <summary>
/// Helper service for creating JSON necessary for creating block list items programatically using Umbraco <see cref="ContentService"/>
/// </summary>
/// <remarks>
/// Based of this: https://github.com/umbraco/UmbracoDocs/blob/e64ec0e5b28b4e5a37b7865691621e45dd82701f/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Block-List-Editor/index.md
/// It's intended for simple content
/// </remarks>
public class BlockListCreatorService
{
/// <summary>
@getify
getify / 1.html
Last active May 10, 2023 03:25
Ever noticed how vw/vh units in CSS seem to be a bit unreliable on various devices (especially mobile)? Here's my solution.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>Test Page</title>
<script>
// early compute the vw/vh units more reliably than CSS does itself
computeViewportDimensions();
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using System.Web;
using System.Web.Hosting;
using ImageProcessor.Web.Services;
namespace UmbrellaInc.Web.Services
{
@jhauge
jhauge / MediaApi.cs
Last active December 23, 2015 22:31
private readonly IMediaService _mediaSvc = ApplicationContext.Current.Services.MediaService;
// Updating profile pic
internal void UpdateProfilePic(int profileId, string picPath)
{
if (profileId == 0) throw new ArgumentException("Error updating profile, no profile id in request");
var contentItem = _contentSvc.GetById(profileId);
// Set mediaitem
var mediaFilename = contentItem.Name + Path.GetExtension(picPath);
@joeriks
joeriks / structure_and_content_creation_script.cshtml
Created March 27, 2015 10:59
Poor mans "Code First" implementation for Umbraco - or rather a sample of a Structure and Content creation script
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = null;
}
@functions{
/*
* Poor mans "Code First" implementation for Umbraco
$('input[type=submit]').not('.cancel').click(function (evt) {
evt.preventDefault();
var self = $(this);
var frm = self.closest('form');
frm.validate();
if (frm.valid()) {
$.ajax({
cache: false,
async: true,
@kipusoep
kipusoep / gist:9fa2dc1160d21afaabc4
Created December 16, 2014 13:37
ImageProcessor auto-resize
MediaFileSystem mediaFileSystem = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
IContentSection contentSection = UmbracoConfig.For.UmbracoSettings().Content;
IEnumerable<string> supportedTypes = contentSection.ImageFileTypes.ToList();
foreach (IMedia media in e.SavedEntities)
{
if (media.HasProperty("umbracoFile"))
{
// Make sure it's an image.
string path = media.GetValue<string>("umbracoFile");
@leekelleher
leekelleher / umbraco.io.user.js
Last active March 19, 2018 15:10
Umbraco Cloud UserScript - to assist with common tasks
// ==UserScript==
// @name Umbraco Cloud - UI Fixes
// @namespace http://leekelleher.com/
// @version 0.6.1
// @description Hacking around on umbraco.io
// @author Lee Kelleher
// @match https://www.umbraco.io/project/*
// @match https://www.s1.umbraco.io/project/*
// @grant none
// ==/UserScript==
@pburtchaell
pburtchaell / styles.css
Last active February 25, 2024 12:24
VH and VW units can cause issues on iOS devices. To overcome this, create media queries that target the width, height, and orientation of iOS devices.
/**
* VH and VW units can cause issues on iOS devices: http://caniuse.com/#feat=viewport-units
*
* To overcome this, create media queries that target the width, height, and orientation of iOS devices.
* It isn't optimal, but there is really no other way to solve the problem. In this example, I am fixing
* the height of element `.foo` —which is a full width and height cover image.
*
* iOS Resolution Quick Reference: http://www.iosres.com/
*/
@Jeavon
Jeavon / AppIcons.cshtml
Last active November 8, 2016 12:31
AppIcons - Partial View for Umbraco
@using Umbraco.Web.Models
@inherits UmbracoViewPage<IPublishedContent>
@{
var internalMediaFolder = Umbraco.TypedMediaAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "InternalMediaFolder");
if (internalMediaFolder != null)
{
var appleTouchIcon = internalMediaFolder.Descendants().FirstOrDefault(x => x.DocumentTypeAlias == "AppleTouchIcon");