Skip to content

Instantly share code, notes, and snippets.

View naepalm's full-sized avatar

Janae Cram naepalm

View GitHub Profile
@naepalm
naepalm / DictionaryController.cs
Created February 8, 2017 18:08
Get all dictionary items for a language on a site and spit them out in an API Controller.
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Web;
using Umbraco.Web.WebApi;
namespace Olympic.Web.Controllers.Api
{
public class DictionaryController : UmbracoApiController
{
@naepalm
naepalm / TextOverImagePartial.cshtml
Created January 12, 2017 22:10
Files to easily render the Text Over Image Editor on the front.
@model TextOverImage.Models.ImageWithText
@{
// Use this code to render this partial in your template. Replace "banner" with whatever your property name is
// Make sure to include @using TextOverImage.Models at the top of your template
//@if(Model.Content.HasProperty("banner") && Model.Content.HasValue("banner"))
//{
// @Html.Partial("TextOverImagePartial", Model.Content.GetPropertyValue<ImageWithText>("banner")
//}
@naepalm
naepalm / RazorServerDirectoryListingHelper.cshtml
Created August 17, 2016 16:45
Displays a list of directories and files on a server, for those nasty moments when you don't have access and are looking for something.
@helper RenderFolders(string dirPath, bool displaySubDirs = false)
{
try
{
List<string> dirs = new List<string>(Directory.EnumerateDirectories(dirPath));
<h4>@string.Format("Directory: {0}", dirPath.Substring(dirPath.LastIndexOf("\\") + 1))</h4>
<p>@(string.Format("{0} directories found.", dirs.Count))</p>
<ul>
@foreach (var dir in dirs)
@naepalm
naepalm / TastyCookies.js
Last active August 23, 2016 21:06
Kyle's handy-dandy cookie scripts.
/**
* @class Cookie
* @description Helper functions for adding and deleting cookies.
*/
var Cookie = {
/**
* @method delete
* @param {string} cookieName - The name of the cookie to delete.
* @description Deletes the indicated cookie.
*/
@naepalm
naepalm / Helpers.js
Last active August 3, 2017 22:46
Helper functions for react, such as price currency formatting.
var Helpers = {
/**
* @function formatMoney
* @param {number} n - The number to be formatted
* @param {string} d - The character to be used for the decimal. Defaults to ".".
* @param {string} t - the character to be used for the thousands separator. Defaults to ",".
* @param {int} c - the number of decimal places. Defaults to 2.
* @returns {string}
* @description Formats a number to a price
*/
public class CacheService : ICacheService
{
private readonly MemoryCache _memoryCache = new MemoryCache("Cache.Key");
public void Add<T>(T cacheObject, string key)
{
var cacheItemPolicy = new CacheItemPolicy
{
AbsoluteExpiration = DateTimeOffset.Now.AddHours(24)
};
@naepalm
naepalm / ContentExtensions.cs
Last active January 10, 2019 01:32
A set of useful extension methods for Umbraco properties.
namespace Client.Web
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Models;
using Newtonsoft.Json;
using Umbraco.Core.Models;
@naepalm
naepalm / ContactForm.cs
Created December 3, 2015 19:49
Contact Form for Umbraco with a Departments dropdown list. Assumes the dropdown list is NestedContent on the selected Email Template.
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Umbraco.Core.Models;
using Umbraco.Web;
namespace Forms.Web.Models
{
public class ContactForm
{
@naepalm
naepalm / MediaSave.cshtml
Last active December 3, 2015 19:38
A little razor template snippet that re-saves/republishes all media in Umbraco
@using Umbraco.Core.Models;
@{
var mediaService = ApplicationContext.Current.Services.MediaService;
SaveMedias(mediaService.GetRootMedia().ToList());
}
@functions
{
namespace Client.Web.Models
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Buzz.Hybrid;
using Buzz.Hybrid.Models;