Skip to content

Instantly share code, notes, and snippets.

@SurinderBhomra
SurinderBhomra / hubspot-upload-file.js
Last active January 21, 2022 15:12
Hubspot Serverless Function - Upload A New File
const axios = require('axios');
const FormData = require('form-data');
/**********************************************************************/
/* Convert a Base64 file to a buffer.
/**********************************************************************/
const base64ToBuffer = (base64String, fileName) => {
if (base64String !== "") {
let buffer;
@SurinderBhomra
SurinderBhomra / MyWebpart.ascx.cs
Created June 16, 2020 10:05
Cache Busting Kentico - StaticFileCacheBuster Usage Example
if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "MyWebpart"))
{
string jsScripts = $@"$LAB
.script(""{CacheEngine.StaticFileCacheBuster("/resources/js/plugins/slick.min.js")}"")
.script(""{CacheEngine.StaticFileCacheBuster("/resources/js/carousel.min.js")}"").wait(function() {{
BECarousel.Init();
FECarousel.Init();
}});";
ScriptManager.RegisterStartupScript(this, typeof(string), "MyWebpart", jsScripts, true);
@SurinderBhomra
SurinderBhomra / Default.aspx
Created June 16, 2020 10:02
Cache Busting Kentico - CSS Usage Example
<!-- Cache Bust CSS/Images -->
<link rel="stylesheet" type="text/css" href="{%"/resources/css/site.min.css".CacheBuster() #%}" />
<link rel="apple-touch-icon" href="{%"/resources/images/icons/apple-touch-icon.png".CacheBuster()#%}" />
<!-- Outcome -->
<link rel="stylesheet" type="text/css" href="/resources/css/v636619761520000000/site.min.css" />
<link rel="apple-touch-icon" href="/resources/images/icons/v636528193180000000/apple-touch-icon.png" />
@SurinderBhomra
SurinderBhomra / StringMacroMethods.cs
Created June 16, 2020 09:40
Cache Busting Kentico - Kentico Macro
using CMS;
using CMS.DocumentEngine;
using CMS.Helpers;
using CMS.MacroEngine;
using CMS.SiteProvider;
using System;
using System.Text;
using System.Web;[assembly: RegisterExtension(typeof(StringMacroMethods), typeof(string))]
public class StringMacroMethods : MacroMethodContainer
{
@SurinderBhomra
SurinderBhomra / Web.config
Created June 16, 2020 09:37
Cache Busting Kentico - Rewrite Rules - Web.config
<system.webServer>
<rewrite>
<rules>
<rule name="Cache Buster">
<match url="([\S]+)(/v[0-9]+/)([\S]+)" />
<action type="Rewrite" url="{R:1}/{R:3}" />
</rule>
</rules>
</rewrite>
<staticContent>
@SurinderBhomra
SurinderBhomra / CacheEngine.cs
Created June 16, 2020 09:35
Cache Busting Kentico - CacheEngine Class
public class CacheEngine
{
/// <summary>
/// Caches static resources, such as CSS and JavaScript.
/// </summary>
/// <param name="rootRelativePath"></param>
/// <returns></returns>
public static string StaticFileCacheBuster(string rootRelativePath)
{
if (!HttpContext.Current.IsDebuggingEnabled)
@SurinderBhomra
SurinderBhomra / Web.config
Last active June 16, 2020 09:30
Cache Busting Kentico - Cache-Control Custom Header - Web.config
<!-- Cache resources directory BEGIN -->
<location path="resources">
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="public, max-age=604800" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
@SurinderBhomra
SurinderBhomra / Program.cs
Last active December 19, 2019 13:43
Console App - Export Kentico Blog Posts To Markdown Files
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.Helpers;
using CMS.MediaLibrary;
using Export.BlogPosts.Models;
using ReverseMarkdown;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
@SurinderBhomra
SurinderBhomra / WebMarkupMinConfig.cs
Created December 2, 2019 17:42
WebMinMarkup Configuration
public class WebMarkupMinConfig
{
public static void Configure(WebMarkupMinConfiguration configuration)
{
configuration.AllowMinificationInDebugMode = false;
configuration.AllowCompressionInDebugMode = false;
configuration.DisablePoweredByHttpHeaders = true;
DefaultLogger.Current = new ThrowExceptionLogger();
@SurinderBhomra
SurinderBhomra / ContentManipulatorExtensions
Last active April 20, 2019 20:43
Responsive Images: Convert Image To Picture Tag
using HtmlAgilityPack;
using Site.Common.Kentico;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Web;
namespace SurinderBhomra.Common.Extensions